# HG changeset patch # User Mychaela Falconia # Date 1656281846 28800 # Node ID 26b98505684e47c3493764d29524e0a14fb71924 # Parent 6560915b0d27905c72e04edd7a30d0bc2cd9cf2e themwi-check-own utility written, compiles diff -r 6560915b0d27 -r 26b98505684e .hgignore --- a/.hgignore Sun Jun 26 13:52:29 2022 -0800 +++ b/.hgignore Sun Jun 26 14:17:26 2022 -0800 @@ -2,5 +2,6 @@ \.[oa]$ +^utils/themwi-check-own$ ^utils/themwi-dump-numdb$ ^utils/themwi-update-numdb$ diff -r 6560915b0d27 -r 26b98505684e utils/Makefile --- a/utils/Makefile Sun Jun 26 13:52:29 2022 -0800 +++ b/utils/Makefile Sun Jun 26 14:17:26 2022 -0800 @@ -1,11 +1,15 @@ CC= gcc CFLAGS= -O2 -PROGS= themwi-dump-numdb themwi-update-numdb +PROGS= themwi-check-own themwi-dump-numdb themwi-update-numdb +LIBNUMDB=../libnumdb/libnumdb.a LIBUTIL=../libutil/libutil.a INSTBIN=/usr/local/bin all: ${PROGS} +themwi-check-own: themwi-check-own.o ${LIBNUMDB} ${LIBUTIL} + ${CC} ${CFLAGS} -o $@ $@.o ${LIBNUMDB} ${LIBUTIL} + themwi-dump-numdb: themwi-dump-numdb.c ${CC} ${CFLAGS} -o $@ $@.c diff -r 6560915b0d27 -r 26b98505684e utils/themwi-check-own.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/themwi-check-own.c Sun Jun 26 14:17:26 2022 -0800 @@ -0,0 +1,35 @@ +/* + * This utility performs a lookup in ThemWi number database to see + * if a given NANP number is owned by us. + */ + +#include +#include +#include + +main(argc, argv) + char **argv; +{ + char nanp[11]; + + if (argc != 2) { +usage: fprintf(stderr, "usage: %s 10-digit-number\n", argv[0]); + exit(1); + } + if (grok_number_string(argv[1], 1) != 10) + goto usage; + dehyphen_number_string(argv[1], nanp); + if (!is_nanp_valid_prefix(nanp)) { + fprintf(stderr, "error: number violates NANP rules\n"); + exit(1); + } + openlog("themwi-check-own", 0, LOG_LOCAL5); + if (read_number_db() < 0) { + fprintf(stderr, "error reading number database\n"); + exit(1); + } + printf("+1-%.3s-%.3s-%s is %s\n", nanp, nanp+3, nanp+6, + is_nanp_locally_owned(nanp) ? "locally owned" + : "NOT owned by us"); + exit(0); +}