annotate libnumdb/check_short.c @ 14:78319ed870dc

convert to new ThemWi configure and build system
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 21 May 2024 00:15:24 +0000
parents 6534965175dd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 looks up 4-digit short
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * dialing numbers in ThemWi number db to determine their disposition.
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 short_number_rec *numdb_short_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_short_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 < *p2)
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 > *p2)
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 return(0);
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 const struct short_number_rec *numdb_lookup_short(const char *numstr)
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 uint16_t key;
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (!numdb_short_numbers || !numdb_hdr.short_number_count)
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 key = digits4_to_uint16(numstr);
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return bsearch(&key, numdb_short_numbers, numdb_hdr.short_number_count,
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 sizeof(struct short_number_rec), compare_short_num);
6534965175dd libnumdb ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }