view utils/themwi-short-dial.c @ 10:05a94b08c8e1

add top Makefile
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 13 Dec 2023 03:56:16 +0000
parents 0b4d54289ef3
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 <themwi/nanp/number_db_v2.h>
#include <themwi/nanp/number_lookup.h>
#include <themwi/nanp/number_utils.h>

int main(int argc, char **argv)
{
	const 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", LOG_PERROR, LOG_USER);
	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);
}