FreeCalypso > hg > themwi-system-sw
annotate utils/themwi-short-dial.c @ 255:b0bf167bb846
themwi-update-outrt: add route-to-e911 option
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 15 Aug 2023 00:23:03 -0800 |
parents | c7a3ba56c636 |
children |
rev | line source |
---|---|
14
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This command line utility looks up a 4-digit short dialing code |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * in ThemWi number database and reports its status: not defined, |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * ITN or mapping to NANP. |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
239
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
8 #include <stdint.h> |
14
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <syslog.h> |
239
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
11 #include "../include/number_db_v2.h" |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
12 #include "../libnumdb2/lookup_func.h" |
14
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 main(argc, argv) |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char **argv; |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
239
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
17 struct short_number_rec *rec; |
14
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (argc != 2) { |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 usage: fprintf(stderr, "usage: %s 4-digit-number\n", argv[0]); |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 exit(1); |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 } |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (grok_number_string(argv[1], 0) != 4) |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 goto usage; |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 openlog("themwi-short-dial", 0, LOG_LOCAL5); |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (read_number_db() < 0) { |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fprintf(stderr, "error reading number database\n"); |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 exit(1); |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
239
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
30 rec = numdb_lookup_short(argv[1]); |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
31 if (!rec) { |
14
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 printf("Short number %s is not defined\n", argv[1]); |
239
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
33 exit(0); |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
34 } |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
35 switch (rec->short_num_type) { |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
36 case SHORT_NUM_TYPE_ABBREV: |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
37 printf("Short number %s is abbrev for +1-%03u-%03u-%04u\n", |
240
c7a3ba56c636
themwi-short-dial: fix bug in printf arguments
Mychaela Falconia <falcon@freecalypso.org>
parents:
239
diff
changeset
|
38 argv[1], rec->fullnum_prefix[0], rec->fullnum_prefix[1], |
239
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
39 rec->short_num); |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
40 break; |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
41 case SHORT_NUM_TYPE_ITN: |
14
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 printf("Short number %s is an ITN\n", argv[1]); |
239
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
43 break; |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
44 case SHORT_NUM_TYPE_TEST_SINK: |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
45 printf("Short number %s is a test sink\n", argv[1]); |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
46 break; |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
47 default: |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
48 printf("Short number %s has unknown type 0x%02X\n", argv[1], |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
49 rec->short_num_type); |
19d1c39ae4e7
themwi-short-dial: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
50 } |
14
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(0); |
aea422af79dd
themwi-short-dial utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |