FreeCalypso > hg > themwi-system-sw
annotate utils/themwi-update-numdb2.c @ 226:28441920fb35
beginning of number database version 2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 13 Aug 2023 22:01:25 -0800 |
parents | utils/themwi-update-numdb.c@4ad5deafaa87 |
children | 7ea6acdb8364 |
rev | line source |
---|---|
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
2 * This program reads (parses) ThemWi config file /var/gsm/number-db2, |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * generates the compiled binary form of this database, and then makes |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * it live via atomic rename. |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <unistd.h> |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
14 #include "../include/number_db_v2.h" |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #define MAX_OWNED_NUMBERS 1000 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #define MAX_SHORT_NUMBERS 1000 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
19 static struct owned_number_rec owned_number_buf[MAX_OWNED_NUMBERS]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
20 static struct short_number_rec short_number_buf[MAX_SHORT_NUMBERS]; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static unsigned owned_number_count, short_number_count; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 static char *system_dir; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 static FILE *inf; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 static int lineno; |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
26 static char linebuf[256]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
27 static int prefix_set, prefix_allows_abbrev; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
28 static uint16_t prefix_buf[2]; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 static void |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
31 enter_owned_number(rec) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
32 struct owned_number_rec *rec; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (owned_number_count >= MAX_OWNED_NUMBERS) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(stderr, "error: MAX_OWNED_NUMBERS exceeded\n"); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
38 bcopy(rec, owned_number_buf + owned_number_count, |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
39 sizeof(struct owned_number_rec)); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
40 owned_number_count++; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 static void |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
44 enter_short_number(rec) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
45 struct short_number_rec *rec; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (short_number_count >= MAX_SHORT_NUMBERS) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fprintf(stderr, "error: MAX_SHORT_NUMBERS exceeded\n"); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
51 bcopy(rec, short_number_buf + short_number_count, |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
52 sizeof(struct short_number_rec)); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 short_number_count++; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 static void |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 handle_prefix_line(cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 char *cp; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
60 char *np, prefix[7]; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 for (np = cp; *cp && !isspace(*cp); cp++) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 ; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (*cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 *cp++ = '\0'; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (grok_number_string(np, 1) != 6) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
68 "number-db2 line %d: prefix requires 6-digit argument\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 lineno); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 dehyphen_number_string(np, prefix); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (!is_nanp_valid_prefix(prefix)) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
75 "number-db2 line %d: prefix violates NANP rules\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 lineno); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
79 prefix_buf[0] = digits3_to_uint16(prefix); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
80 prefix_buf[1] = digits3_to_uint16(prefix + 3); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
81 prefix_set = 1; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 while (isspace(*cp)) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 cp++; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (*cp == '\0' || *cp == '#') { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 prefix_allows_abbrev = 0; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 return; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 for (np = cp; *cp && !isspace(*cp); cp++) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 ; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (*cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 *cp++ = '\0'; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (!strcmp(np, "allow-abbrev")) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 prefix_allows_abbrev = 1; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 return; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
97 "number-db2 line %d: non-understood notation \"%s\" after prefix\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 lineno, np); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
102 static int |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
103 parse_extra_number(rec, numstr) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
104 struct owned_number_rec *rec; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
105 char *numstr; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
106 { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
107 char buf[11]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
108 int rc; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
109 |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
110 rc = grok_number_string(numstr, 1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
111 switch (rc) { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
112 case 4: |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
113 if (!prefix_set) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
114 return(-1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
115 dehyphen_number_string(numstr, buf); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
116 rec->remap[0] = prefix_buf[0]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
117 rec->remap[1] = prefix_buf[1]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
118 rec->remap[2] = digits4_to_uint16(buf); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
119 return(0); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
120 case 10: |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
121 dehyphen_number_string(numstr, buf); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
122 rec->remap[0] = digits3_to_uint16(buf); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
123 rec->remap[1] = digits3_to_uint16(buf + 3); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
124 rec->remap[2] = digits4_to_uint16(buf + 6); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
125 return(0); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
126 default: |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
127 return(-1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
128 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
129 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
130 |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
131 static void |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
132 handle_number_attr(rec, tail) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
133 struct owned_number_rec *rec; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
134 char *tail; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
135 { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
136 char *cp, *np; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
137 int rc; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
138 |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
139 for (cp = tail; ; ) { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
140 while (isspace(*cp)) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
141 cp++; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
142 if (*cp == '\0' || *cp == '#') |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
143 return; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
144 for (np = cp; *cp && !isspace(*cp); cp++) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
145 ; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
146 if (*cp) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
147 *cp++ = '\0'; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
148 if (!strcmp(np, "sms")) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
149 rec->number_flags |= NUMBER_FLAG_SMSPROV; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
150 else if (!strcmp(np, "e911")) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
151 rec->number_flags |= NUMBER_FLAG_E911PROV; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
152 else if (!strcmp(np, "gsm-sub")) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
153 rec->usage = NUMBER_USAGE_TYPE_GSM_SUB; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
154 else if (!strcmp(np, "map-to")) { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
155 rec->usage = NUMBER_USAGE_TYPE_ALIAS; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
156 while (isspace(*cp)) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
157 cp++; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
158 if (*cp == '\0' || *cp == '#') { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
159 fprintf(stderr, |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
160 "number-db2 line %d: map-to requires an argument\n", |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
161 lineno); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
162 exit(1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
163 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
164 for (np = cp; *cp && !isspace(*cp); cp++) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
165 ; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
166 if (*cp) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
167 *cp++ = '\0'; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
168 rc = parse_extra_number(rec, np); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
169 if (rc < 0) { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
170 fprintf(stderr, |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
171 "number-db2 line %d: map-to argument is invalid\n", |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
172 lineno); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
173 exit(1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
174 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
175 } else if (!strcmp(np, "e911-via")) { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
176 if (rec->usage != NUMBER_USAGE_TYPE_GSM_SUB) { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
177 fprintf(stderr, |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
178 "number-db2 line %d: invalid usage of e911-via\n", |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
179 lineno); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
180 exit(1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
181 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
182 rec->usage |= NUMBER_USAGE_FLAG_E911_VIA; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
183 while (isspace(*cp)) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
184 cp++; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
185 if (*cp == '\0' || *cp == '#') { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
186 fprintf(stderr, |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
187 "number-db2 line %d: e911-via requires an argument\n", |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
188 lineno); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
189 exit(1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
190 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
191 for (np = cp; *cp && !isspace(*cp); cp++) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
192 ; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
193 if (*cp) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
194 *cp++ = '\0'; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
195 rc = parse_extra_number(rec, np); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
196 if (rc < 0) { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
197 fprintf(stderr, |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
198 "number-db2 line %d: e911-via argument is invalid\n", |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
199 lineno); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
200 exit(1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
201 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
202 } else { |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
203 fprintf(stderr, |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
204 "number-db2 line %d: invalid attribute \"%s\"\n", |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
205 lineno, np); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
206 exit(1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
207 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
208 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
209 } |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
210 |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 static void |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 handle_suffix_line(cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 char *cp; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
215 char *np; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
216 uint16_t suffix; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
217 struct owned_number_rec own_rec; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
218 struct short_number_rec short_rec; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
220 if (!prefix_set) { |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
222 "number-db2 line %d: suffix not valid without preceding prefix\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 lineno); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 for (np = cp; *cp && !isspace(*cp); cp++) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 ; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 if (*cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 *cp++ = '\0'; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 if (grok_number_string(np, 0) != 4) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
232 "number-db2 line %d: suffix requires 4-digit argument\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 lineno); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 } |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
236 suffix = digits4_to_uint16(np); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
237 bzero(&own_rec, sizeof own_rec); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
238 own_rec.number[0] = prefix_buf[0]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
239 own_rec.number[1] = prefix_buf[1]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
240 own_rec.number[2] = suffix; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
241 handle_number_attr(&own_rec, cp); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
242 enter_owned_number(&own_rec); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
243 if (!prefix_allows_abbrev || own_rec.usage != NUMBER_USAGE_TYPE_GSM_SUB) |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 return; |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
245 bzero(&short_rec, sizeof short_rec); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
246 short_rec.short_num = suffix; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
247 short_rec.short_num_type = SHORT_NUM_TYPE_ABBREV; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
248 short_rec.fullnum_flags = own_rec.number_flags; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
249 short_rec.fullnum_prefix[0] = prefix_buf[0]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
250 short_rec.fullnum_prefix[1] = prefix_buf[1]; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
251 enter_short_number(&short_rec); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 static void |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 handle_full10_line(cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 char *cp; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 char *np, full10[11]; |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
259 struct owned_number_rec own_rec; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
261 prefix_set = 0; /* cancel any previous prefix line */ |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 for (np = cp; *cp && !isspace(*cp); cp++) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 ; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 if (*cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 *cp++ = '\0'; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 if (grok_number_string(np, 1) != 10) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
268 "number-db2 line %d: full10 requires 10-digit argument\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 lineno); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 dehyphen_number_string(np, full10); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 if (!is_nanp_valid_prefix(full10)) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
275 "number-db2 line %d: number violates NANP rules\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 lineno); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 } |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
279 bzero(&own_rec, sizeof own_rec); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
280 own_rec.number[0] = digits3_to_uint16(full10); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
281 own_rec.number[1] = digits3_to_uint16(full10 + 3); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
282 own_rec.number[2] = digits4_to_uint16(full10 + 6); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
283 handle_number_attr(&own_rec, cp); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
284 enter_owned_number(&own_rec); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 static void |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 handle_itn_line(cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 char *cp; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 char *np; |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
292 struct short_number_rec short_rec; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
294 prefix_set = 0; /* cancel any previous prefix line */ |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 for (np = cp; *cp && !isspace(*cp); cp++) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 ; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 if (*cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 *cp++ = '\0'; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 if (grok_number_string(np, 0) != 4) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
301 "number-db2 line %d: itn requires 4-digit argument\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 lineno); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 } |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
305 bzero(&short_rec, sizeof short_rec); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
306 short_rec.short_num = digits4_to_uint16(np); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
307 short_rec.short_num_type = SHORT_NUM_TYPE_ITN; |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
308 enter_short_number(&short_rec); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 static void |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 process_line() |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 char *cp, *np; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 void (*handler)(); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 if (!index(linebuf, '\n')) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
319 "number-db2 line %d: too long or missing newline\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 lineno); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 for (cp = linebuf; isspace(*cp); cp++) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 ; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 if (*cp == '\0' || *cp == '#') |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 return; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 for (np = cp; *cp && !isspace(*cp); cp++) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 ; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 if (*cp) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 *cp++ = '\0'; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 if (!strcmp(np, "prefix")) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 handler = handle_prefix_line; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 else if (!strcmp(np, "suffix")) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 handler = handle_suffix_line; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 else if (!strcmp(np, "full10")) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 handler = handle_full10_line; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 else if (!strcmp(np, "itn")) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 handler = handle_itn_line; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 else { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
341 "number-db2 line %d: non-understood keyword \"%s\"\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 lineno, np); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 while (isspace(*cp)) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 cp++; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 if (*cp == '\0' || *cp == '#') { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
349 "number-db2 line %d: missing argument after \"%s\" keyword\n", |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 lineno, np); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 handler(cp); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 static int |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 compare_owned_num(p1, p2) |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
358 struct owned_number_rec *p1, *p2; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
360 if (p1->number[0] < p2->number[0]) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
361 return(-1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
362 if (p1->number[0] > p2->number[0]) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
363 return(1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
364 if (p1->number[1] < p2->number[1]) |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 return(-1); |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
366 if (p1->number[1] > p2->number[1]) |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 return(1); |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
368 if (p1->number[2] < p2->number[2]) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
369 return(-1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
370 if (p1->number[2] > p2->number[2]) |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
371 return(1); |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
372 return(0); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 static int |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 compare_short_num(p1, p2) |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
377 struct short_number_rec *p1, *p2; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
379 if (p1->short_num < p2->short_num) |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 return(-1); |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
381 if (p1->short_num > p2->short_num) |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 return(1); |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
383 return(0); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 static void |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 owned_num_check_dup() |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
389 struct owned_number_rec *p, *endp; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 endp = owned_number_buf + owned_number_count - 1; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 for (p = owned_number_buf; p < endp; p++) { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
393 if (p[0].number[0] == p[1].number[0] && |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
394 p[0].number[1] == p[1].number[1] && |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
395 p[0].number[2] == p[1].number[2]) { |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 fprintf(stderr, |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
397 "error: NANP number %03u-%03u-%04u appears more than once\n", |
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
398 p[0].number[0], p[0].number[1], p[0].number[2]); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 static void |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 short_num_check_dup() |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
407 struct short_number_rec *p, *endp; |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 endp = short_number_buf + short_number_count - 1; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 for (p = short_number_buf; p < endp; p++) { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
411 if (p[0].short_num == p[1].short_num) { |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
412 fprintf(stderr, |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 "error: short number %04u appears more than once\n", |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
414 (unsigned) p->short_num); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
418 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 static void |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 emit_output() |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 FILE *outf; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 struct numdb_file_hdr hdr; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
426 outf = fopen("number-db2.newbin", "w"); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 if (!outf) { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
428 perror("creating number-db2.newbin"); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 hdr.owned_number_count = owned_number_count; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 hdr.short_number_count = short_number_count; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
433 if (fwrite(&hdr, sizeof hdr, 1, outf) != 1) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
434 write_err: fprintf(stderr, "error writing to new binary file\n"); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 if (fwrite(owned_number_buf, sizeof(owned_number_buf[0]), |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 owned_number_count, outf) != owned_number_count) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 goto write_err; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
440 if (fwrite(short_number_buf, sizeof(short_number_buf[0]), |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 short_number_count, outf) != short_number_count) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
442 goto write_err; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
443 fclose(outf); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 main(argc, argv) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 char **argv; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
448 { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 if (argc > 2) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 fprintf(stderr, "usage: %s [directory]\n", argv[0]); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 if (argv[1]) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 system_dir = argv[1]; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 else |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 system_dir = "/var/gsm"; |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 if (chdir(system_dir) < 0) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 perror(system_dir); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 } |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
461 inf = fopen("number-db2", "r"); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 if (!inf) { |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
463 perror("opening number-db2"); |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
466 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
467 process_line(); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
468 fclose(inf); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
469 if (owned_number_count >= 2) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
470 qsort(owned_number_buf, owned_number_count, |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
471 sizeof(owned_number_buf[0]), compare_owned_num); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
472 owned_num_check_dup(); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
473 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 if (short_number_count >= 2) { |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 qsort(short_number_buf, short_number_count, |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
476 sizeof(short_number_buf[0]), compare_short_num); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 short_num_check_dup(); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
479 emit_output(); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 /* make it live */ |
226
28441920fb35
beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
481 if (rename("number-db2.newbin", "number-db2.bin") < 0) { |
4
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
482 perror("rename"); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
483 exit(1); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
484 } |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
485 exit(0); |
4ad5deafaa87
themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
486 } |