comparison libnumdb/check_short.c @ 1:6534965175dd

libnumdb ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 13 Dec 2023 00:53:04 +0000
parents
children
comparison
equal deleted inserted replaced
0:159dd90eeafe 1:6534965175dd
1 /*
2 * The library function implemented in this module looks up 4-digit short
3 * dialing numbers in ThemWi number db to determine their disposition.
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9
10 #include <themwi/nanp/number_db_v2.h>
11 #include <themwi/nanp/number_lookup.h>
12 #include <themwi/nanp/number_utils.h>
13
14 extern struct numdb_file_hdr numdb_hdr;
15 extern struct short_number_rec *numdb_short_numbers;
16
17 static int compare_short_num(const void *p1v, const void *p2v)
18 {
19 const uint16_t *p1 = p1v, *p2 = p2v;
20
21 if (*p1 < *p2)
22 return(-1);
23 if (*p1 > *p2)
24 return(1);
25 return(0);
26 }
27
28 const struct short_number_rec *numdb_lookup_short(const char *numstr)
29 {
30 uint16_t key;
31
32 if (!numdb_short_numbers || !numdb_hdr.short_number_count)
33 return(0);
34 key = digits4_to_uint16(numstr);
35 return bsearch(&key, numdb_short_numbers, numdb_hdr.short_number_count,
36 sizeof(struct short_number_rec), compare_short_num);
37 }