view libnumdb/check_short.c @ 2:1773886ef54e

themwi-update-numdb: old source as starting point
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 13 Dec 2023 01:23:47 +0000
parents 6534965175dd
children
line wrap: on
line source

/*
 * 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 <themwi/nanp/number_db_v2.h>
#include <themwi/nanp/number_lookup.h>
#include <themwi/nanp/number_utils.h>

extern struct numdb_file_hdr numdb_hdr;
extern struct short_number_rec *numdb_short_numbers;

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)
		return(1);
	return(0);
}

const struct short_number_rec *numdb_lookup_short(const 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);
}