annotate utils/themwi-update-numdb.c @ 2:1773886ef54e

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