view utils/themwi-short-dial.c @ 267:81958b35f74d

NANP validation: allow made-up area codes of N9X form
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 13 Nov 2023 15:28:09 -0800
parents c7a3ba56c636
children
line wrap: on
line source

/*
 * 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);
}