annotate libnumdb2/check_nanp.c @ 247:c6a3fb913c53

top Makefile: mtctest changed to use libnumdb2
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 22:39:28 -0800
parents bd493b21f215
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The library function implemented in this module consults ThemWi number db
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * to see if a given NANP number is owned by us or not.
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
9 #include "../include/number_db_v2.h"
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern struct numdb_file_hdr numdb_hdr;
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
12 extern struct owned_number_rec *numdb_owned_numbers;
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static int
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 compare_owned_num(p1, p2)
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
16 uint16_t *p1, *p2;
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
18 if (p1[0] < p2[0])
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
19 return(-1);
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
20 if (p1[0] > p2[0])
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
21 return(1);
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
22 if (p1[1] < p2[1])
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(-1);
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
24 if (p1[1] > p2[1])
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return(1);
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
26 if (p1[2] < p2[2])
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
27 return(-1);
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
28 if (p1[2] > p2[2])
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
29 return(1);
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
30 return(0);
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
33 struct owned_number_rec *
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
34 numdb_lookup_nanp(numstr)
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 char *numstr;
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
37 uint16_t key[3];
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (!numdb_owned_numbers || !numdb_hdr.owned_number_count)
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(0);
235
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
41 key[0] = digits3_to_uint16(numstr);
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
42 key[1] = digits3_to_uint16(numstr + 3);
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
43 key[2] = digits4_to_uint16(numstr + 6);
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
44 return bsearch(key, numdb_owned_numbers, numdb_hdr.owned_number_count,
bd493b21f215 libnumdb2: port check_nanp.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
45 sizeof(struct owned_number_rec), compare_owned_num);
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }