annotate utils/themwi-dump-numdb.c @ 15:a24f0794ab4d default tip

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