changeset 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 dc1554b7dfb8
children 0b4d54289ef3
files utils/themwi-short-dial.c
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/themwi-short-dial.c	Wed Dec 13 03:39:48 2023 +0000
@@ -0,0 +1,52 @@
+/*
+ * 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 <stdint.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include "../include/number_db_v2.h"
+#include "../libnumdb2/lookup_func.h"
+
+main(argc, argv)
+	char **argv;
+{
+	struct short_number_rec *rec;
+
+	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);
+	}
+	rec = numdb_lookup_short(argv[1]);
+	if (!rec) {
+		printf("Short number %s is not defined\n", argv[1]);
+		exit(0);
+	}
+	switch (rec->short_num_type) {
+	case SHORT_NUM_TYPE_ABBREV:
+		printf("Short number %s is abbrev for +1-%03u-%03u-%04u\n",
+			argv[1], 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);
+}