FreeCalypso > hg > themwi-system-sw
annotate libnumdb2/check_short.c @ 262:f1c024b2b835
smpp-trx-sa/log.c: additional cleanup
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 11 Oct 2023 21:21:34 -0800 |
parents | 38cac1cbe010 |
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> |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
9 #include "../include/number_db_v2.h" |
11
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; |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
12 extern struct short_number_rec *numdb_short_numbers; |
11
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) |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
16 uint16_t *p1, *p2; |
11
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
18 if (*p1 < *p2) |
11
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 return(-1); |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
20 if (*p1 > *p2) |
11
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 return(1); |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
22 return(0); |
11
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
25 struct short_number_rec * |
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
26 numdb_lookup_short(numstr) |
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
27 char *numstr; |
11
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 { |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
29 uint16_t key; |
11
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); |
236
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
33 key = digits4_to_uint16(numstr); |
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
34 return bsearch(&key, numdb_short_numbers, numdb_hdr.short_number_count, |
38cac1cbe010
libnumdb2: port check_short.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
35 sizeof(struct short_number_rec), compare_short_num); |
11
1d590563e64b
libnumdb: implement short number lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |