annotate utils/themwi-dump-numdb2.c @ 228:7ea6acdb8364

themwi-update-numdb2: logic fix in abbrev number creation
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 10:29:22 -0800
parents a349ae9d90fa
children 78c6e30f5234
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program is a debug utility: it reads and dumps the compiled
227
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
3 * binary form of ThemWi number database version 2.
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
227
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
9 #include "../include/number_db_v2.h"
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
227
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
11 static char binfile_default_pathname[] = "/var/gsm/number-db2.bin";
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static char *binfile_pathname;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static FILE *inf;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static struct numdb_file_hdr hdr;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static void
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 dump_owned_numbers()
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 unsigned count;
227
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
20 struct owned_number_rec rec;
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 for (count = 0; count < hdr.owned_number_count; count++) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (fread(&rec, sizeof rec, 1, inf) != 1) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "error reading record from %s\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 binfile_pathname);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
227
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
28 printf("Owned NANP number: %03u-%03u-%04u\n",
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
29 rec.number[0], rec.number[1], rec.number[2]);
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
30 printf(" Number flags 0x%02X, usage byte 0x%02X\n",
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
31 rec.number_flags, rec.usage);
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
32 if ((rec.usage & NUMBER_USAGE_MASK) == NUMBER_USAGE_TYPE_ALIAS)
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
33 printf(" Alias maps to: %03u-%03u-%04u\n",
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
34 rec.remap[0], rec.remap[1], rec.remap[2]);
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
35 if (rec.usage & NUMBER_USAGE_FLAG_E911_VIA)
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
36 printf(" E911 route via: %03u-%03u-%04u\n",
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
37 rec.remap[0], rec.remap[1], rec.remap[2]);
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 static void
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 dump_short_numbers()
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 unsigned count;
227
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
45 struct short_number_rec rec;
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 for (count = 0; count < hdr.short_number_count; count++) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (fread(&rec, sizeof rec, 1, inf) != 1) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr, "error reading record from %s\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 binfile_pathname);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
227
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
53 printf("Short number %04u is of type 0x%02X\n", rec.short_num,
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
54 rec.short_num_type);
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
55 if (rec.short_num_type == SHORT_NUM_TYPE_ABBREV) {
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
56 printf(" Abbrev maps to: %03u-%03u-%04u\n",
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
57 rec.fullnum_prefix[0], rec.fullnum_prefix[1],
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
58 rec.short_num);
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
59 printf(" Full number flags: 0x%02X\n",
a349ae9d90fa number db v2: implement themwi-dump-numdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
60 rec.fullnum_flags);
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 main(argc, argv)
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 char **argv;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (argc > 2) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 fprintf(stderr, "usage: %s [binfile]\n", argv[0]);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (argv[1])
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 binfile_pathname = argv[1];
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 else
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 binfile_pathname = binfile_default_pathname;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 inf = fopen(binfile_pathname, "r");
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 if (!inf) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 perror(binfile_pathname);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (fread(&hdr, sizeof hdr, 1, inf) != 1) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 fprintf(stderr, "error reading header from %s\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 binfile_pathname);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 printf("Count of owned NANP numbers: %u\n", hdr.owned_number_count);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 printf("Count of defined short numbers: %u\n", hdr.short_number_count);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 dump_owned_numbers();
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 dump_short_numbers();
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 exit(0);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }