FreeCalypso > hg > themwi-nanp
annotate libnumdb/check_nanp.c @ 13:c0bfd300b6e5
add INSTALL
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 13 Dec 2023 06:07:40 +0000 |
parents | 6534965175dd |
children |
rev | line source |
---|---|
1
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The library function implemented in this module consults ThemWi number db |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * to see if a given NANP number is owned by us or not. |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <themwi/nanp/number_db_v2.h> |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <themwi/nanp/number_lookup.h> |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <themwi/nanp/number_utils.h> |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern struct numdb_file_hdr numdb_hdr; |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern struct owned_number_rec *numdb_owned_numbers; |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static int compare_owned_num(const void *p1v, const void *p2v) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 const uint16_t *p1 = p1v, *p2 = p2v; |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (p1[0] < p2[0]) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(-1); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (p1[0] > p2[0]) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return(1); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (p1[1] < p2[1]) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(-1); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (p1[1] > p2[1]) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(1); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (p1[2] < p2[2]) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(-1); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (p1[2] > p2[2]) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(1); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return(0); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 const struct owned_number_rec *numdb_lookup_nanp(const char *numstr) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 uint16_t key[3]; |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (!numdb_owned_numbers || !numdb_hdr.owned_number_count) |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(0); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 key[0] = digits3_to_uint16(numstr); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 key[1] = digits3_to_uint16(numstr + 3); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 key[2] = digits4_to_uint16(numstr + 6); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return bsearch(key, numdb_owned_numbers, numdb_hdr.owned_number_count, |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 sizeof(struct owned_number_rec), compare_owned_num); |
6534965175dd
libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |