FreeCalypso > hg > themwi-system-sw
annotate libnumdb/check_short.c @ 175:623c64ae6102
doc/Codec-library-depend: libgsmefr is here and actively used
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 10 Jan 2023 18:05:55 -0800 |
parents | 1d590563e64b |
children |
rev | line source |
---|---|
11
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The library function implemented in this module looks up 4-digit short |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * dialing numbers in ThemWi number db to determine their disposition. |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "../include/number_db_file.h" |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern struct numdb_file_hdr numdb_hdr; |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern struct short_number_map *numdb_short_numbers; |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static int |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 compare_short_num(p1, p2) |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 struct short_number_map *p1, *p2; |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 if (p1->short_code < p2->short_code) |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 return(-1); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 else if (p1->short_code > p2->short_code) |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 return(1); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 else |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return(0); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 } |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 lookup_short_dial_number(numstr, nanp_buf) |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 char *numstr, *nanp_buf; |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 { |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 struct short_number_map key, *res; |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (!numdb_short_numbers || !numdb_hdr.short_number_count) |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(0); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 key.short_code = strtoul(numstr, 0, 10); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 res = bsearch(&key, numdb_short_numbers, numdb_hdr.short_number_count, |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 sizeof(struct short_number_map), compare_short_num); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (!res) |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(0); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (res->prefix < 200000 || res->prefix > 999999) { |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 /* either ITN or an invalid record, also treated as an ITN */ |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 nanp_buf[0] = '\0'; |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(1); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 sprintf(nanp_buf, "%06u%04u", res->prefix, res->short_code); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return(1); |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |