codename.c.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. codename.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='codelist.c.html' title=' codelist.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='config2cfg.c.html' title=' config2cfg.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * char const * codename (struct _code_ const list [], size_t size, code_t code, char const * name);
  24. *
  25. * symbol.h
  26. *
  27. * return the name associated with a given code by searching a name
  28. * table arranged in ascending order by code; return the table name
  29. * if the code is found or argument name if not;
  30. *
  31. * typedefs code_t and struct _code_ are defined in codes.h;
  32. *
  33. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  34. * Copyright (c) 2001-2006 by Charles Maier Associates;
  35. * Licensed under the Internet Software Consortium License;
  36. *
  37. *--------------------------------------------------------------------*/
  38. #ifndef CODENAME_SOURCE
  39. #define CODENAME_SOURCE
  40. #include &lt;unistd.h&gt;
  41. #include &quot;../tools/symbol.h&quot;
  42. char const * codename (struct _code_ const list [], size_t size, code_t code, char const * name)
  43. {
  44. size_t lower = 0;
  45. size_t upper = size;
  46. while (lower &lt; upper)
  47. {
  48. size_t index = (lower + upper) &gt;&gt; 1;
  49. signed order = code - list [index].code;
  50. if (order &lt; 0)
  51. {
  52. upper = index - 0;
  53. continue;
  54. }
  55. if (order &gt; 0)
  56. {
  57. lower = index + 1;
  58. continue;
  59. }
  60. return (list [index].name);
  61. }
  62. return (name);
  63. }
  64. #endif
  65. </pre>
  66. <div class='footerlink'>
  67. [<a href='codelist.c.html' title=' codelist.c '>PREV</a>]
  68. [<a href='toolkit.html' title=' Index '>HOME</a>]
  69. [<a href='config2cfg.c.html' title=' config2cfg.c '>NEXT</a>]
  70. </div>
  71. </body>
  72. </html>