FreeCalypso > hg > themwi-nanp
annotate utils/themwi-short-dial.c @ 14:78319ed870dc
convert to new ThemWi configure and build system
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 21 May 2024 00:15:24 +0000 |
parents | 0b4d54289ef3 |
children |
rev | line source |
---|---|
8
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This command line utility looks up a 4-digit short dialing code |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * in ThemWi number database and reports its status: not defined, |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * ITN or mapping to NANP. |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <syslog.h> |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
9
0b4d54289ef3
themwi-short-dial compiles in the new model
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
12 #include <themwi/nanp/number_db_v2.h> |
0b4d54289ef3
themwi-short-dial compiles in the new model
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
13 #include <themwi/nanp/number_lookup.h> |
0b4d54289ef3
themwi-short-dial compiles in the new model
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
14 #include <themwi/nanp/number_utils.h> |
0b4d54289ef3
themwi-short-dial compiles in the new model
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
15 |
0b4d54289ef3
themwi-short-dial compiles in the new model
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
16 int main(int argc, char **argv) |
8
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
9
0b4d54289ef3
themwi-short-dial compiles in the new model
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
18 const struct short_number_rec *rec; |
8
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (argc != 2) { |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 usage: fprintf(stderr, "usage: %s 4-digit-number\n", argv[0]); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 exit(1); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (grok_number_string(argv[1], 0) != 4) |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 goto usage; |
9
0b4d54289ef3
themwi-short-dial compiles in the new model
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
26 openlog("themwi-short-dial", LOG_PERROR, LOG_USER); |
8
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (read_number_db() < 0) { |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "error reading number database\n"); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 rec = numdb_lookup_short(argv[1]); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (!rec) { |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 printf("Short number %s is not defined\n", argv[1]); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(0); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 switch (rec->short_num_type) { |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 case SHORT_NUM_TYPE_ABBREV: |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 printf("Short number %s is abbrev for +1-%03u-%03u-%04u\n", |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 argv[1], rec->fullnum_prefix[0], rec->fullnum_prefix[1], |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 rec->short_num); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 break; |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 case SHORT_NUM_TYPE_ITN: |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 printf("Short number %s is an ITN\n", argv[1]); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 break; |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 case SHORT_NUM_TYPE_TEST_SINK: |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 printf("Short number %s is a test sink\n", argv[1]); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 break; |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 default: |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 printf("Short number %s has unknown type 0x%02X\n", argv[1], |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 rec->short_num_type); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 exit(0); |
db3c657efafa
themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |