comparison libnumdb2/check_nanp.c @ 235:bd493b21f215

libnumdb2: port check_nanp.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 13:57:10 -0800
parents libnumdb/check_nanp.c@960ffce6c542
children
comparison
equal deleted inserted replaced
234:44f178901a46 235:bd493b21f215
1 /*
2 * The library function implemented in this module consults ThemWi number db
3 * to see if a given NANP number is owned by us or not.
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include "../include/number_db_v2.h"
10
11 extern struct numdb_file_hdr numdb_hdr;
12 extern struct owned_number_rec *numdb_owned_numbers;
13
14 static int
15 compare_owned_num(p1, p2)
16 uint16_t *p1, *p2;
17 {
18 if (p1[0] < p2[0])
19 return(-1);
20 if (p1[0] > p2[0])
21 return(1);
22 if (p1[1] < p2[1])
23 return(-1);
24 if (p1[1] > p2[1])
25 return(1);
26 if (p1[2] < p2[2])
27 return(-1);
28 if (p1[2] > p2[2])
29 return(1);
30 return(0);
31 }
32
33 struct owned_number_rec *
34 numdb_lookup_nanp(numstr)
35 char *numstr;
36 {
37 uint16_t key[3];
38
39 if (!numdb_owned_numbers || !numdb_hdr.owned_number_count)
40 return(0);
41 key[0] = digits3_to_uint16(numstr);
42 key[1] = digits3_to_uint16(numstr + 3);
43 key[2] = digits4_to_uint16(numstr + 6);
44 return bsearch(key, numdb_owned_numbers, numdb_hdr.owned_number_count,
45 sizeof(struct owned_number_rec), compare_owned_num);
46 }