changeset 239:19d1c39ae4e7

themwi-short-dial: convert to libnumdb2
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 15:35:04 -0800
parents 697fe2c87fec
children c7a3ba56c636
files utils/Makefile utils/themwi-short-dial.c
diffstat 2 files changed, 25 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/utils/Makefile	Mon Aug 14 14:42:59 2023 -0800
+++ b/utils/Makefile	Mon Aug 14 15:35:04 2023 -0800
@@ -43,8 +43,8 @@
 themwi-dump-numdb2:	themwi-dump-numdb2.c
 	${CC} ${CFLAGS} -o $@ $@.c
 
-themwi-short-dial:	themwi-short-dial.o ${LIBNUMDB} ${LIBUTIL}
-	${CC} ${CFLAGS} -o $@ $@.o ${LIBNUMDB} ${LIBUTIL}
+themwi-short-dial:	themwi-short-dial.o ${LIBNUMDB2} ${LIBUTIL}
+	${CC} ${CFLAGS} -o $@ $@.o ${LIBNUMDB2} ${LIBUTIL}
 
 themwi-update-numdb:	themwi-update-numdb.o ${LIBUTIL}
 	${CC} ${CFLAGS} -o $@ $@.o ${LIBUTIL}
--- a/utils/themwi-short-dial.c	Mon Aug 14 14:42:59 2023 -0800
+++ b/utils/themwi-short-dial.c	Mon Aug 14 15:35:04 2023 -0800
@@ -5,14 +5,16 @@
  */
 
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <syslog.h>
+#include "../include/number_db_v2.h"
+#include "../libnumdb2/lookup_func.h"
 
 main(argc, argv)
 	char **argv;
 {
-	char nanp[11];
-	int res;
+	struct short_number_rec *rec;
 
 	if (argc != 2) {
 usage:		fprintf(stderr, "usage: %s 4-digit-number\n", argv[0]);
@@ -25,13 +27,26 @@
 		fprintf(stderr, "error reading number database\n");
 		exit(1);
 	}
-	res = lookup_short_dial_number(argv[1], nanp);
-	if (!res)
+	rec = numdb_lookup_short(argv[1]);
+	if (!rec) {
 		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
+		exit(0);
+	}
+	switch (rec->short_num_type) {
+	case SHORT_NUM_TYPE_ABBREV:
+		printf("Short number %s is abbrev for +1-%03u-%03u-%04u\n",
+			rec->fullnum_prefix[0], rec->fullnum_prefix[1],
+			rec->short_num);
+		break;
+	case SHORT_NUM_TYPE_ITN:
 		printf("Short number %s is an ITN\n", argv[1]);
+		break;
+	case SHORT_NUM_TYPE_TEST_SINK:
+		printf("Short number %s is a test sink\n", argv[1]);
+		break;
+	default:
+		printf("Short number %s has unknown type 0x%02X\n", argv[1],
+			rec->short_num_type);
+	}
 	exit(0);
 }