/* findhash.c */

/* Copyright 1997-2000 by Eberhard Mattes <em-gw@windhager.de>
   Donated to the public domain.  No warranty.

   1997-09-09 Initial version
   2000-04-15 Make NAME_data const (see HASH_IDX) */

#include <string.h>
#include "libemfw.h"

/* Find an entry in a hash table.  Note that letter case matters.  If
   you want to search case-insensitively, convert the search string to
   lowercase and ensure that all table entries are given in
   lowercase. */

const struct hash_entry *
find_hash_entry (const struct hash_entry * const *table,
		 unsigned hash_size,
		 const char *s, size_t n)
{
  unsigned h = hash (s, n, hash_size);
  const struct hash_entry *p = table[h];
  while (p != NULL)
    {
      if (p->len == n && memcmp (p->name, s, n) == 0)
	return p;
      p = p->next;
    }
  return NULL;
}
