lookup.c 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*====================================================================*
  2. *
  3. * signed lookup (char const * name, struct _code_ const list [], size_t size);
  4. *
  5. * symbol.h
  6. *
  7. * search a name list and return the associated name; return the
  8. * corresponding code on success or -1 on failure; the search is
  9. * case insensitive;
  10. *
  11. * Motley Tools by Charles Maier;
  12. * Copyright (c) 2001-2006 by Charles Maier Associates;
  13. * Licensed under the Internet Software Consortium License;
  14. *
  15. *--------------------------------------------------------------------*/
  16. #ifndef LOOKUP_SOURCE
  17. #define LOOKUP_SOURCE
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include "../tools/symbol.h"
  21. signed lookup (char const * name, struct _code_ const list [], size_t size)
  22. {
  23. struct _code_ const * item = list;
  24. if ((name) && (*name)) while ((unsigned)(item - list) < size)
  25. {
  26. if (!strcasecmp (item->name, name))
  27. {
  28. return (item->code);
  29. }
  30. item++;
  31. }
  32. return (-1);
  33. }
  34. #endif