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

themwi-update-numdb2: logic fix in abbrev number creation
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 10:29:22 -0800
parents 28441920fb35
children 626824449ddf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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);
228
7ea6acdb8364 themwi-update-numdb2: logic fix in abbrev number creation
Mychaela Falconia <falcon@freecalypso.org>
parents: 226
diff changeset
243 if (!prefix_allows_abbrev)
7ea6acdb8364 themwi-update-numdb2: logic fix in abbrev number creation
Mychaela Falconia <falcon@freecalypso.org>
parents: 226
diff changeset
244 return;
7ea6acdb8364 themwi-update-numdb2: logic fix in abbrev number creation
Mychaela Falconia <falcon@freecalypso.org>
parents: 226
diff changeset
245 if ((own_rec.usage & NUMBER_USAGE_MASK) != NUMBER_USAGE_TYPE_GSM_SUB)
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 return;
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
247 bzero(&short_rec, sizeof short_rec);
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
248 short_rec.short_num = suffix;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
249 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
250 short_rec.fullnum_flags = own_rec.number_flags;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
251 short_rec.fullnum_prefix[0] = prefix_buf[0];
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
252 short_rec.fullnum_prefix[1] = prefix_buf[1];
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
253 enter_short_number(&short_rec);
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 static void
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 handle_full10_line(cp)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 char *cp;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 char *np, full10[11];
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
261 struct owned_number_rec own_rec;
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
263 prefix_set = 0; /* cancel any previous prefix line */
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 for (np = cp; *cp && !isspace(*cp); cp++)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 ;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 if (*cp)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 *cp++ = '\0';
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 if (grok_number_string(np, 1) != 10) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 fprintf(stderr,
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
270 "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
271 lineno);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 dehyphen_number_string(np, full10);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 if (!is_nanp_valid_prefix(full10)) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 fprintf(stderr,
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
277 "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
278 lineno);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 }
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
281 bzero(&own_rec, sizeof own_rec);
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
282 own_rec.number[0] = digits3_to_uint16(full10);
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
283 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
284 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
285 handle_number_attr(&own_rec, cp);
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
286 enter_owned_number(&own_rec);
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 static void
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 handle_itn_line(cp)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 char *cp;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 char *np;
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
294 struct short_number_rec short_rec;
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
296 prefix_set = 0; /* cancel any previous prefix line */
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 for (np = cp; *cp && !isspace(*cp); cp++)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 ;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 if (*cp)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 *cp++ = '\0';
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 if (grok_number_string(np, 0) != 4) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 fprintf(stderr,
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
303 "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
304 lineno);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 }
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
307 bzero(&short_rec, sizeof short_rec);
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
308 short_rec.short_num = digits4_to_uint16(np);
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
309 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
310 enter_short_number(&short_rec);
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 static void
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 process_line()
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 char *cp, *np;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 void (*handler)();
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 if (!index(linebuf, '\n')) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 fprintf(stderr,
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
321 "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
322 lineno);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 exit(1);
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 for (cp = linebuf; isspace(*cp); cp++)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 ;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 if (*cp == '\0' || *cp == '#')
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 return;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 for (np = cp; *cp && !isspace(*cp); cp++)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 ;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 if (*cp)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 *cp++ = '\0';
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 if (!strcmp(np, "prefix"))
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 handler = handle_prefix_line;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 else if (!strcmp(np, "suffix"))
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 handler = handle_suffix_line;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 else if (!strcmp(np, "full10"))
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 handler = handle_full10_line;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 else if (!strcmp(np, "itn"))
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 handler = handle_itn_line;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 else {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 fprintf(stderr,
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
343 "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
344 lineno, np);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 while (isspace(*cp))
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 cp++;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 if (*cp == '\0' || *cp == '#') {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 fprintf(stderr,
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
351 "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
352 lineno, np);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 exit(1);
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 handler(cp);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358 static int
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 compare_owned_num(p1, p2)
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
360 struct owned_number_rec *p1, *p2;
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 {
226
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[0] > p2->number[0])
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
365 return(1);
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[1] > p2->number[1])
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 return(1);
226
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 if (p1->number[2] > p2->number[2])
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
373 return(1);
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
374 return(0);
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 static int
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 compare_short_num(p1, p2)
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
379 struct short_number_rec *p1, *p2;
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 {
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 if (p1->short_num > p2->short_num)
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 return(1);
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
385 return(0);
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388 static void
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389 owned_num_check_dup()
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390 {
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
391 struct owned_number_rec *p, *endp;
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 endp = owned_number_buf + owned_number_count - 1;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 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
395 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
396 p[0].number[1] == p[1].number[1] &&
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
397 p[0].number[2] == p[1].number[2]) {
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 fprintf(stderr,
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
399 "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
400 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
401 exit(1);
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 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 static void
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
407 short_num_check_dup()
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
408 {
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
409 struct short_number_rec *p, *endp;
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
410
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
411 endp = short_number_buf + short_number_count - 1;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
412 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
413 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
414 fprintf(stderr,
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
415 "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
416 (unsigned) p->short_num);
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
417 exit(1);
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 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
421
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
422 static void
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
423 emit_output()
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
424 {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
425 FILE *outf;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
426 struct numdb_file_hdr hdr;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
427
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
428 outf = fopen("number-db2.newbin", "w");
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
429 if (!outf) {
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
430 perror("creating number-db2.newbin");
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
431 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
432 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
433 hdr.owned_number_count = owned_number_count;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
434 hdr.short_number_count = short_number_count;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
435 if (fwrite(&hdr, sizeof hdr, 1, outf) != 1) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
436 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
437 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
438 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
439 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
440 owned_number_count, outf) != owned_number_count)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
441 goto write_err;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
442 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
443 short_number_count, outf) != short_number_count)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
444 goto write_err;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
445 fclose(outf);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
446 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
447
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
448 main(argc, argv)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
449 char **argv;
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
450 {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
451 if (argc > 2) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
452 fprintf(stderr, "usage: %s [directory]\n", argv[0]);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
453 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
454 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
455 if (argv[1])
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
456 system_dir = argv[1];
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
457 else
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
458 system_dir = "/var/gsm";
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
459 if (chdir(system_dir) < 0) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
460 perror(system_dir);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
461 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
462 }
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
463 inf = fopen("number-db2", "r");
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
464 if (!inf) {
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
465 perror("opening number-db2");
4
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
466 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
467 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
468 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++)
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
469 process_line();
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
470 fclose(inf);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
471 if (owned_number_count >= 2) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
472 qsort(owned_number_buf, owned_number_count,
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
473 sizeof(owned_number_buf[0]), compare_owned_num);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
474 owned_num_check_dup();
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
475 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
476 if (short_number_count >= 2) {
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
477 qsort(short_number_buf, short_number_count,
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
478 sizeof(short_number_buf[0]), compare_short_num);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
479 short_num_check_dup();
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
480 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
481 emit_output();
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
482 /* make it live */
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
483 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
484 perror("rename");
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
485 exit(1);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
486 }
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
487 exit(0);
4ad5deafaa87 themwi-update-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
488 }