changeset 14:aea422af79dd

themwi-short-dial utility written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 26 Jun 2022 14:42:33 -0800
parents 26b98505684e
children ccc5ab6d8388
files .hgignore utils/Makefile utils/themwi-short-dial.c
diffstat 3 files changed, 42 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Jun 26 14:17:26 2022 -0800
+++ b/.hgignore	Sun Jun 26 14:42:33 2022 -0800
@@ -4,4 +4,5 @@
 
 ^utils/themwi-check-own$
 ^utils/themwi-dump-numdb$
+^utils/themwi-short-dial$
 ^utils/themwi-update-numdb$
--- a/utils/Makefile	Sun Jun 26 14:17:26 2022 -0800
+++ b/utils/Makefile	Sun Jun 26 14:42:33 2022 -0800
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	themwi-check-own themwi-dump-numdb themwi-update-numdb
+PROGS=	themwi-check-own themwi-dump-numdb themwi-short-dial themwi-update-numdb
 LIBNUMDB=../libnumdb/libnumdb.a
 LIBUTIL=../libutil/libutil.a
 INSTBIN=/usr/local/bin
@@ -13,6 +13,9 @@
 themwi-dump-numdb:	themwi-dump-numdb.c
 	${CC} ${CFLAGS} -o $@ $@.c
 
+themwi-short-dial:	themwi-short-dial.o ${LIBNUMDB} ${LIBUTIL}
+	${CC} ${CFLAGS} -o $@ $@.o ${LIBNUMDB} ${LIBUTIL}
+
 themwi-update-numdb:	themwi-update-numdb.o ${LIBUTIL}
 	${CC} ${CFLAGS} -o $@ $@.o ${LIBUTIL}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/themwi-short-dial.c	Sun Jun 26 14:42:33 2022 -0800
@@ -0,0 +1,37 @@
+/*
+ * This command line utility looks up a 4-digit short dialing code
+ * in ThemWi number database and reports its status: not defined,
+ * ITN or mapping to NANP.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <syslog.h>
+
+main(argc, argv)
+	char **argv;
+{
+	char nanp[11];
+	int res;
+
+	if (argc != 2) {
+usage:		fprintf(stderr, "usage: %s 4-digit-number\n", argv[0]);
+		exit(1);
+	}
+	if (grok_number_string(argv[1], 0) != 4)
+		goto usage;
+	openlog("themwi-short-dial", 0, LOG_LOCAL5);
+	if (read_number_db() < 0) {
+		fprintf(stderr, "error reading number database\n");
+		exit(1);
+	}
+	res = lookup_short_dial_number(argv[1], nanp);
+	if (!res)
+		printf("Short number %s is not defined\n", argv[1]);
+	else if (nanp[0])
+		printf("Short number %s maps to +1-%.3s-%.3s-%s\n", argv[1],
+			nanp, nanp+3, nanp+6);
+	else
+		printf("Short number %s is an ITN\n", argv[1]);
+	exit(0);
+}