decdecode.c.html 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. decdecode.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='debug.c.html' title=' debug.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='decout.c.html' title=' decout.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * size_t decdecode (void const * memory, size_t extent, char buffer [], size_t length);
  24. *
  25. * memory.h
  26. *
  27. * decode a memory block of given length in bytes as a string of
  28. * separated hexadecimal bytes; terminate once the string fills
  29. * or the memory ends; terminate the string and return the actual
  30. * string bytes;
  31. *
  32. * allow three string characters for each memory byte; this means
  33. * that the buffer must have at least three characters or nothing
  34. * will be decoded; the maximum number of bytes is the lesser of
  35. * chars/3 and bytes;;
  36. *
  37. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  38. * Copyright (c) 2001-2006 by Charles Maier Associates;
  39. * Licensed under the Internet Software Consortium License;
  40. *
  41. *--------------------------------------------------------------------*/
  42. #ifndef DECDECODE_SOURCE
  43. #define DECDECODE_SOURCE
  44. #include &quot;../tools/memory.h&quot;
  45. #include &quot;../tools/number.h&quot;
  46. size_t decdecode (void const * memory, register size_t extent, char buffer [], register size_t length)
  47. {
  48. register char * string = (char *)(buffer);
  49. register byte * offset = (byte *)(memory);
  50. if (length)
  51. {
  52. length /= DEC_DIGITS + 1;
  53. while ((length--) &amp;&amp; (extent--))
  54. {
  55. unsigned octet = *offset;
  56. unsigned digit = DEC_DIGITS;
  57. while (digit--)
  58. {
  59. string [digit] = '0' + octet % RADIX_DEC;
  60. octet /= RADIX_DEC;
  61. }
  62. string += DEC_DIGITS;
  63. if ((length) &amp;&amp; (extent))
  64. {
  65. *string++ = DEC_EXTENDER;
  66. }
  67. offset++;
  68. }
  69. *string = (char) (0);
  70. }
  71. return (string - buffer);
  72. }
  73. #endif
  74. </pre>
  75. <div class='footerlink'>
  76. [<a href='debug.c.html' title=' debug.c '>PREV</a>]
  77. [<a href='toolkit.html' title=' Index '>HOME</a>]
  78. [<a href='decout.c.html' title=' decout.c '>NEXT</a>]
  79. </div>
  80. </body>
  81. </html>