FreeCalypso > hg > themwi-system-sw
comparison libnumdb2/check_short.c @ 236:38cac1cbe010
libnumdb2: port check_short.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 14:16:07 -0800 |
parents | libnumdb/check_short.c@1d590563e64b |
children |
comparison
equal
deleted
inserted
replaced
235:bd493b21f215 | 236:38cac1cbe010 |
---|---|
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 #include "../include/number_db_v2.h" | |
10 | |
11 extern struct numdb_file_hdr numdb_hdr; | |
12 extern struct short_number_rec *numdb_short_numbers; | |
13 | |
14 static int | |
15 compare_short_num(p1, p2) | |
16 uint16_t *p1, *p2; | |
17 { | |
18 if (*p1 < *p2) | |
19 return(-1); | |
20 if (*p1 > *p2) | |
21 return(1); | |
22 return(0); | |
23 } | |
24 | |
25 struct short_number_rec * | |
26 numdb_lookup_short(numstr) | |
27 char *numstr; | |
28 { | |
29 uint16_t key; | |
30 | |
31 if (!numdb_short_numbers || !numdb_hdr.short_number_count) | |
32 return(0); | |
33 key = digits4_to_uint16(numstr); | |
34 return bsearch(&key, numdb_short_numbers, numdb_hdr.short_number_count, | |
35 sizeof(struct short_number_rec), compare_short_num); | |
36 } |