synonym.c.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. synonym.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='strnpwd.c.html' title=' strnpwd.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='termlist.c.html' title=' termlist.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * char const * synonym (char const * term, const struct _term_ list [], size_t size);
  24. *
  25. * symbol.h
  26. *
  27. * lookup term and return corresponding text; return the original
  28. * term if lookup fails; the list must be in lexographic order by
  29. * term or lookups may fail; struct _term_ is defined in types.h;
  30. *
  31. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  32. * Copyright (c) 2001-2006 by Charles Maier Associates;
  33. * Licensed under the Internet Software Consortium License;
  34. *
  35. *--------------------------------------------------------------------*/
  36. #ifndef SYNONYM_SOURCE
  37. #define SYNONYM_SOURCE
  38. #include &lt;string.h&gt;
  39. #include &quot;../tools/types.h&quot;
  40. char const * synonym (char const * term, const struct _term_ list [], size_t size)
  41. {
  42. size_t lower = 0;
  43. size_t upper = size;
  44. while (lower &lt; upper)
  45. {
  46. size_t index = (lower + upper) &gt;&gt; 1;
  47. signed order = strcmp (term, list [index].term);
  48. if (order &lt; 0)
  49. {
  50. upper = index - 0;
  51. continue;
  52. }
  53. if (order &gt; 0)
  54. {
  55. lower = index + 1;
  56. continue;
  57. }
  58. return (list [index].text);
  59. }
  60. return (term);
  61. }
  62. #endif
  63. </pre>
  64. <div class='footerlink'>
  65. [<a href='strnpwd.c.html' title=' strnpwd.c '>PREV</a>]
  66. [<a href='toolkit.html' title=' Index '>HOME</a>]
  67. [<a href='termlist.c.html' title=' termlist.c '>NEXT</a>]
  68. </div>
  69. </body>
  70. </html>