FreeCalypso > hg > themwi-system-sw
changeset 236:38cac1cbe010
libnumdb2: port check_short.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 14:16:07 -0800 |
parents | bd493b21f215 |
children | f78c097108a7 |
files | libnumdb2/Makefile libnumdb2/check_short.c |
diffstat | 2 files changed, 37 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libnumdb2/Makefile Mon Aug 14 13:57:10 2023 -0800 +++ b/libnumdb2/Makefile Mon Aug 14 14:16:07 2023 -0800 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= check_nanp.o readbin.o refresh.o +OBJS= check_nanp.o check_short.o readbin.o refresh.o LIB= libnumdb.a all: ${LIB}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libnumdb2/check_short.c Mon Aug 14 14:16:07 2023 -0800 @@ -0,0 +1,36 @@ +/* + * The library function implemented in this module looks up 4-digit short + * dialing numbers in ThemWi number db to determine their disposition. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include "../include/number_db_v2.h" + +extern struct numdb_file_hdr numdb_hdr; +extern struct short_number_rec *numdb_short_numbers; + +static int +compare_short_num(p1, p2) + uint16_t *p1, *p2; +{ + if (*p1 < *p2) + return(-1); + if (*p1 > *p2) + return(1); + return(0); +} + +struct short_number_rec * +numdb_lookup_short(numstr) + char *numstr; +{ + uint16_t key; + + if (!numdb_short_numbers || !numdb_hdr.short_number_count) + return(0); + key = digits4_to_uint16(numstr); + return bsearch(&key, numdb_short_numbers, numdb_hdr.short_number_count, + sizeof(struct short_number_rec), compare_short_num); +}