Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. hd.c
  5. Abstract:
  6. This module contains the definitions of all constants and structures
  7. used in hd.c
  8. Authors:
  9. Jaime F. Sasson (jaimes) 12-Nov-1990
  10. David J. Gilman (davegi) 12-Nov-1990
  11. Environment:
  12. C run time library
  13. Revision History:
  14. --*/
  15. /************************************
  16. *
  17. * Definition of constants
  18. *
  19. ************************************/
  20. #define RECORD_SIZE 16 // Maximum size of a record. A record is a
  21. // buffer that contains a set of bytes read
  22. // from the file, in order to be converted and
  23. // displayed.
  24. #define LINE_SIZE 160 // Size of the buffer that will contain the
  25. // representation of a record. Such a buffer
  26. // can be bigger than one line (80 characters)
  27. // depending on the arguments passed to hd
  28. // (eg. -cC -A). For this reason, the size of
  29. // this buffer was made 160 (size of two lines
  30. // in the screen, wich is large enough to
  31. // contain all characters converted.
  32. #define BUFFER_SIZE 512 // Size of the buffer that will contain data read
  33. // from the file to be displayed. The file will
  34. // be accessed to obtain blocks of BUFFER_SIZE
  35. // characters
  36. /************************************
  37. *
  38. * ASCII characters
  39. *
  40. ************************************/
  41. #define DOT '.'
  42. #define SPACE ' '
  43. #define NUL '\0'
  44. /************************************
  45. *
  46. * Messages used by sprintf
  47. *
  48. ************************************/
  49. #define MSG_ADDR_FIELD " "
  50. #define MSG_ADDR_DEC_FMT "%010lu"
  51. #define MSG_ADDR_HEX_FMT "%08lx"
  52. #define MSG_SINGLE_BYTE_DEC_FMT "%3u"
  53. #define MSG_SINGLE_BYTE_HEX_FMT "%02x"
  54. #define MSG_SINGLE_WORD_DEC_FMT "%5u"
  55. #define MSG_SINGLE_WORD_HEX_FMT "%04x"
  56. #define MSG_WORD_BYTE_DEC_FMT "%5u %3u"
  57. #define MSG_WORD_BYTE_HEX_FMT "%04x %02x"
  58. #define MSG_DATA_ASCII_FMT MSG_ADDR_FIELD \
  59. "%s %s %s %s %s %s %s %s " \
  60. "%s %s %s %s %s %s %s %s "
  61. #define MSG_DATA_BYTE_DEC_FMT MSG_ADDR_FIELD \
  62. "%3u %3u %3u %3u %3u %3u %3u %3u " \
  63. "%3u %3u %3u %3u %3u %3u %3u %3u "
  64. #define MSG_DATA_BYTE_HEX_FMT MSG_ADDR_FIELD \
  65. "%02x %02x %02x %02x %02x %02x %02x %02x " \
  66. "%02x %02x %02x %02x %02x %02x %02x %02x "
  67. #define MSG_DATA_WORD_DEC_FMT MSG_ADDR_FIELD \
  68. "%5u %5u %5u %5u %5u %5u %5u %5u "
  69. #define MSG_DATA_WORD_HEX_FMT MSG_ADDR_FIELD \
  70. "%04x %04x %04x %04x %04x %04x %04x %04x "
  71. #define MSG_DATA_DWORD_DEC_FMT MSG_ADDR_FIELD \
  72. "%10lu %10lu %10lu %10lu "
  73. #define MSG_DATA_DWORD_HEX_FMT MSG_ADDR_FIELD \
  74. "%08lx %08lx %08lx %08lx "
  75. #define MSG_PRINT_CHAR_FMT "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c"
  76. /************************************
  77. *
  78. * Help Message
  79. *
  80. ************************************/
  81. #define HELP_MESSAGE "\n" \
  82. "usage: hd [options] [file1] [file2] ... \n" \
  83. "options: \n" \
  84. " -ad|x displays address in decimal or hex \n" \
  85. " -A append printable characters to the end of the line\n" \
  86. " -ch|C|e|r displays bytes as ascii (characters, ascii C, \n" \
  87. " acsii code or ascii ctrl) \n" \
  88. " -bd|x displays byte as decimal or hex number \n" \
  89. " -wd|x displays word as decimal or hex number \n" \
  90. " -ld|x displays dword as decimal or hex number \n" \
  91. " -s <offset> starting address \n" \
  92. " -n <number> number of bytes to interpret \n" \
  93. " -i supresses printing redundant lines\n" \
  94. " -?|h|H displays this help message \n" \
  95. "\n" \
  96. "default: -ax -bx -A \n" \
  97. "\n"
  98. /************************************
  99. *
  100. * Enumerations
  101. *
  102. ************************************/
  103. typedef enum _FORMAT { // Possible formats used to display data
  104. ASCII_CHAR,
  105. ASCII_C,
  106. ASCII_CODE,
  107. ASCII_CTRL,
  108. BYTE_DEC,
  109. BYTE_HEX,
  110. WORD_DEC,
  111. WORD_HEX,
  112. DWORD_DEC,
  113. DWORD_HEX,
  114. PRINT_CHAR
  115. } FORMAT;
  116. typedef enum _BASE { // Bases used to display numbers
  117. DEC,
  118. HEX
  119. } BASE;
  120. typedef enum _YESNO { // Options for DumpAscii
  121. NOT_DEFINED,
  122. YES,
  123. NO
  124. } YESNO;
  125.