FreeCalypso > hg > themwi-system-sw
view libnumdb2/check_nanp.c @ 242:f86ec96cea6f
top Makefile: utils use libnumdb2 now
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 15:44:33 -0800 |
parents | bd493b21f215 |
children |
line wrap: on
line source
/* * The library function implemented in this module consults ThemWi number db * to see if a given NANP number is owned by us or not. */ #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include "../include/number_db_v2.h" extern struct numdb_file_hdr numdb_hdr; extern struct owned_number_rec *numdb_owned_numbers; static int compare_owned_num(p1, p2) uint16_t *p1, *p2; { if (p1[0] < p2[0]) return(-1); if (p1[0] > p2[0]) return(1); if (p1[1] < p2[1]) return(-1); if (p1[1] > p2[1]) return(1); if (p1[2] < p2[2]) return(-1); if (p1[2] > p2[2]) return(1); return(0); } struct owned_number_rec * numdb_lookup_nanp(numstr) char *numstr; { uint16_t key[3]; if (!numdb_owned_numbers || !numdb_hdr.owned_number_count) return(0); key[0] = digits3_to_uint16(numstr); key[1] = digits3_to_uint16(numstr + 3); key[2] = digits4_to_uint16(numstr + 6); return bsearch(key, numdb_owned_numbers, numdb_hdr.owned_number_count, sizeof(struct owned_number_rec), compare_owned_num); }