/* Find the most appropriate selector matching a given selector name  */
static const struct mapping_selector* selector_find(const char *string, size_t slen, int linenum)
/* Find the most appropriate selector matching a given selector name  */
static const struct mapping_selector* selector_find(const char *string, size_t slen, int linenum)
{
  const struct mapping_selector *	found = NULL;
  int			ambig = 0;
  int			i;
  for(i = 0; selector_list[i].name != NULL; ++i)
    {
      if(strncasecmp(selector_list[i].name, string, slen) != 0)
	continue;
      if(slen == strlen(selector_list[i].name))
	return &selector_list[i];
      if(found == NULL)
	found = &selector_list[i];
      else
	if (selector_list[i].add_fn != found->add_fn)
	  ambig = 1;
    }
  if(found == NULL)
    {
      fprintf(stderr, "Error: Unknown selector `%.*s' at line %d.\n",
	      (int) slen, string, linenum);
      return NULL;
    }
  if(ambig)
    {
      fprintf(stderr, "Selector `%.*s'at line %d is ambiguous.\n",
	      (int) slen, string, linenum);
      return NULL;
    }
  return found;
}