annotate utils/themwi-short-dial.c @ 8:db3c657efafa

themwi-short-dial: old source as starting point
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 13 Dec 2023 03:39:48 +0000
parents
children 0b4d54289ef3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include "../include/number_db_v2.h"
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../libnumdb2/lookup_func.h"
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 main(argc, argv)
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char **argv;
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 struct short_number_rec *rec;
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (argc != 2) {
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 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
21 exit(1);
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 }
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 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
24 goto usage;
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 openlog("themwi-short-dial", 0, LOG_LOCAL5);
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (read_number_db() < 0) {
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 fprintf(stderr, "error reading number database\n");
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 exit(1);
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 rec = numdb_lookup_short(argv[1]);
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (!rec) {
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 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
33 exit(0);
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 switch (rec->short_num_type) {
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case SHORT_NUM_TYPE_ABBREV:
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 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
38 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
39 rec->short_num);
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 break;
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 case SHORT_NUM_TYPE_ITN:
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 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
43 break;
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case SHORT_NUM_TYPE_TEST_SINK:
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 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
46 break;
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 default:
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 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
49 rec->short_num_type);
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(0);
db3c657efafa themwi-short-dial: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }