decout.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*====================================================================*
  2. *
  3. * void decout (const byte memory [], size_t extent, char c, char e, FILE * fp);
  4. *
  5. * memory.h
  6. *
  7. * print a memory region as a series of decimal octets separated
  8. * by character c; normally, c will be DEC_EXTENDER as defined in
  9. * number.h;
  10. *
  11. * for example, decout (memory, 4, '.', stdout) would print
  12. *
  13. * 192.168.101.002
  14. *
  15. * Motley Tools by Charles Maier;
  16. * Copyright (c) 2001-2006 by Charles Maier Associates;
  17. * Licensed under the Internet Software Consortium License;
  18. *
  19. *--------------------------------------------------------------------*/
  20. #ifndef DECOUT_SOURCE
  21. #define DECOUT_SOURCE
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #include "../tools/memory.h"
  25. #include "../tools/number.h"
  26. void decout (void const * memory, size_t extent, char c, char e, FILE * fp)
  27. {
  28. byte * offset = (byte *)(memory);
  29. while (extent--)
  30. {
  31. unsigned order = 100;
  32. while (order)
  33. {
  34. putc (DIGITS_DEC [(* offset / order) % RADIX_DEC], fp);
  35. order /= RADIX_DEC;
  36. }
  37. if ((extent) && (c))
  38. {
  39. putc (c, fp);
  40. }
  41. offset++;
  42. }
  43. if (e)
  44. {
  45. putc (e, fp);
  46. }
  47. return;
  48. }
  49. #endif