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