changeset 3:5bf2648e5413

themwi-update-numdb compiles in the new model
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 13 Dec 2023 02:01:24 +0000
parents 1773886ef54e
children b280d93e8bc1
files .hgignore utils/Makefile utils/themwi-update-numdb.c
diffstat 3 files changed, 47 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Dec 13 01:23:47 2023 +0000
+++ b/.hgignore	Wed Dec 13 02:01:24 2023 +0000
@@ -1,3 +1,5 @@
 syntax: regexp
 
 \.[oa]$
+
+^utils/themwi-update-numdb$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/Makefile	Wed Dec 13 02:01:24 2023 +0000
@@ -0,0 +1,13 @@
+CC=	gcc
+CFLAGS=	-O2 -I../build-inc
+PROGS=	themwi-update-numdb
+LIBNUMDB=../libnumdb/libnumdb.a
+LIBUTIL=../libnumutil/libnumutil.a
+
+all:	${PROGS}
+
+themwi-update-numdb:	themwi-update-numdb.o ${LIBUTIL}
+	${CC} -o $@ $@.o ${LIBUTIL}
+
+clean:
+	rm -f *.o ${PROGS} errs
--- a/utils/themwi-update-numdb.c	Wed Dec 13 01:23:47 2023 +0000
+++ b/utils/themwi-update-numdb.c	Wed Dec 13 02:01:24 2023 +0000
@@ -11,7 +11,9 @@
 #include <string.h>
 #include <strings.h>
 #include <unistd.h>
-#include "../include/number_db_v2.h"
+
+#include <themwi/nanp/number_db_v2.h>
+#include <themwi/nanp/number_utils.h>
 
 #define	MAX_OWNED_NUMBERS	1000
 #define	MAX_SHORT_NUMBERS	1000
@@ -27,9 +29,7 @@
 static int prefix_set, prefix_allows_abbrev;
 static uint16_t prefix_buf[2];
 
-static void
-enter_owned_number(rec)
-	struct owned_number_rec *rec;
+static void enter_owned_number(const struct owned_number_rec *rec)
 {
 	if (owned_number_count >= MAX_OWNED_NUMBERS) {
 		fprintf(stderr, "error: MAX_OWNED_NUMBERS exceeded\n");
@@ -40,9 +40,7 @@
 	owned_number_count++;
 }
 
-static void
-enter_short_number(rec)
-	struct short_number_rec *rec;
+static void enter_short_number(const struct short_number_rec *rec)
 {
 	if (short_number_count >= MAX_SHORT_NUMBERS) {
 		fprintf(stderr, "error: MAX_SHORT_NUMBERS exceeded\n");
@@ -53,9 +51,7 @@
 	short_number_count++;
 }
 
-static void
-handle_prefix_line(cp)
-	char *cp;
+static void handle_prefix_line(char *cp)
 {
 	char *np, prefix[7];
 
@@ -99,10 +95,7 @@
 	exit(1);
 }
 
-static int
-parse_extra_number(rec, numstr)
-	struct owned_number_rec *rec;
-	char *numstr;
+static int parse_extra_number(struct owned_number_rec *rec, const char *numstr)
 {
 	char buf[11];
 	int rc;
@@ -128,10 +121,7 @@
 	}
 }
 
-static void
-handle_number_attr(rec, tail)
-	struct owned_number_rec *rec;
-	char *tail;
+static void handle_number_attr(struct owned_number_rec *rec, char *tail)
 {
 	char *cp, *np;
 	int rc;
@@ -208,9 +198,7 @@
 	}
 }
 
-static void
-handle_suffix_line(cp)
-	char *cp;
+static void handle_suffix_line(char *cp)
 {
 	char *np;
 	uint16_t suffix;
@@ -253,9 +241,7 @@
 	enter_short_number(&short_rec);
 }
 
-static void
-handle_full10_line(cp)
-	char *cp;
+static void handle_full10_line(char *cp)
 {
 	char *np, full10[11];
 	struct owned_number_rec own_rec;
@@ -286,9 +272,7 @@
 	enter_owned_number(&own_rec);
 }
 
-static void
-handle_itn_line(cp)
-	char *cp;
+static void handle_itn_line(char *cp)
 {
 	char *np;
 	struct short_number_rec short_rec;
@@ -310,9 +294,7 @@
 	enter_short_number(&short_rec);
 }
 
-static void
-handle_test_sink_line(cp)
-	char *cp;
+static void handle_test_sink_line(char *cp)
 {
 	char *np;
 	struct short_number_rec short_rec;
@@ -334,11 +316,10 @@
 	enter_short_number(&short_rec);
 }
 
-static void
-process_line()
+static void process_line(void)
 {
 	char *cp, *np;
-	void (*handler)();
+	void (*handler)(char *);
 
 	if (!index(linebuf, '\n')) {
 		fprintf(stderr,
@@ -381,10 +362,10 @@
 	handler(cp);
 }
 
-static int
-compare_owned_num(p1, p2)
-	uint16_t *p1, *p2;
+static int compare_owned_num(const void *p1v, const void *p2v)
 {
+	const uint16_t *p1 = p1v, *p2 = p2v;
+
 	if (p1[0] < p2[0])
 		return(-1);
 	if (p1[0] > p2[0])
@@ -400,10 +381,10 @@
 	return(0);
 }
 
-static int
-compare_short_num(p1, p2)
-	uint16_t *p1, *p2;
+static int compare_short_num(const void *p1v, const void *p2v)
 {
+	const uint16_t *p1 = p1v, *p2 = p2v;
+
 	if (*p1 < *p2)
 		return(-1);
 	if (*p1 > *p2)
@@ -411,10 +392,9 @@
 	return(0);
 }
 
-static void
-owned_num_check_dup()
+static void owned_num_check_dup(void)
 {
-	struct owned_number_rec *p, *endp;
+	const struct owned_number_rec *p, *endp;
 
 	endp = owned_number_buf + owned_number_count - 1;
 	for (p = owned_number_buf; p < endp; p++) {
@@ -429,10 +409,9 @@
 	}
 }
 
-static void
-short_num_check_dup()
+static void short_num_check_dup(void)
 {
-	struct short_number_rec *p, *endp;
+	const struct short_number_rec *p, *endp;
 
 	endp = short_number_buf + short_number_count - 1;
 	for (p = short_number_buf; p < endp; p++) {
@@ -445,11 +424,9 @@
 	}
 }
 
-static void
-check_secondnum_mapto(src)
-	struct owned_number_rec *src;
+static void check_secondnum_mapto(const struct owned_number_rec *src)
 {
-	struct owned_number_rec *dest;
+	const struct owned_number_rec *dest;
 
 	dest = bsearch(src->remap, owned_number_buf, owned_number_count,
 			sizeof(struct owned_number_rec), compare_owned_num);
@@ -467,11 +444,9 @@
 	}
 }
 
-static void
-check_secondnum_e911via(src)
-	struct owned_number_rec *src;
+static void check_secondnum_e911via(const struct owned_number_rec *src)
 {
-	struct owned_number_rec *dest;
+	const struct owned_number_rec *dest;
 
 	dest = bsearch(src->remap, owned_number_buf, owned_number_count,
 			sizeof(struct owned_number_rec), compare_owned_num);
@@ -489,10 +464,9 @@
 	}
 }
 
-static void
-check_secondary_numbers()
+static void check_secondary_numbers(void)
 {
-	struct owned_number_rec *p, *endp;
+	const struct owned_number_rec *p, *endp;
 
 	endp = owned_number_buf + owned_number_count;
 	for (p = owned_number_buf; p < endp; p++) {
@@ -503,8 +477,7 @@
 	}
 }
 
-static void
-emit_output()
+static void emit_output(void)
 {
 	FILE *outf;
 	struct numdb_file_hdr hdr;
@@ -529,8 +502,7 @@
 	fclose(outf);
 }
 
-main(argc, argv)
-	char **argv;
+int main(int argc, char **argv)
 {
 	if (argc > 2) {
 		fprintf(stderr, "usage: %s [directory]\n", argv[0]);