Leaked source code of windows server 2003
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.

218 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. vermsg.c
  5. Abstract:
  6. This program validates the message thunk table.
  7. Author:
  8. 19-Oct-1998 mzoran
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #define MAX_LINE_LENGTH 2048
  19. char LineBuffer[MAX_LINE_LENGTH];
  20. // string to put in front of all error messages so that BUILD can find them.
  21. const char *ErrMsgPrefix = "NMAKE : U8604: 'VERMSG' ";
  22. void
  23. __cdecl ErrMsg(
  24. char *pch,
  25. ...
  26. )
  27. /*++
  28. Routine Description:
  29. Displays an error message to stderr in a format that BUILD can find.
  30. Use this instead of fprintf(stderr, ...).
  31. Arguments:
  32. pch -- printf-style format string
  33. ... -- printf-style args
  34. Return Value:
  35. None. Message formatted and sent to stderr.
  36. --*/
  37. {
  38. va_list pArg;
  39. fputs(ErrMsgPrefix, stderr);
  40. va_start(pArg, pch);
  41. vfprintf(stderr, pch, pArg);
  42. }
  43. void
  44. __cdecl ExitErrMsg(
  45. BOOL bSysError,
  46. char *pch,
  47. ...
  48. )
  49. /*++
  50. Routine Description:
  51. Displays an error message to stderr in a format that BUILD can find.
  52. Use this instead of fprintf(stderr, ...).
  53. Arguments:
  54. bSysErr -- TRUE if the value of errno should be printed with the error
  55. pch -- printf-style format string
  56. ... -- printf-style args
  57. Return Value:
  58. None. Message formatted and sent to stderr, open files closed and
  59. deleted, process terminated.
  60. --*/
  61. {
  62. va_list pArg;
  63. if (bSysError) {
  64. fprintf(stderr, "%s System ERROR %s", ErrMsgPrefix, strerror(errno));
  65. } else {
  66. fprintf(stderr, "%s ERROR ", ErrMsgPrefix);
  67. }
  68. va_start(pArg, pch);
  69. vfprintf(stderr, pch, pArg);
  70. //
  71. // Flush stdout and stderr buffers, so that the last few printfs
  72. // get sent back to BUILD before ExitProcess() destroys them.
  73. //
  74. fflush(stdout);
  75. fflush(stderr);
  76. ExitProcess(1);
  77. }
  78. char *MyFgets(char *string, int n, FILE *stream)
  79. {
  80. char *ret;
  81. ret = fgets(string, n, stream);
  82. if (ret) {
  83. char *p;
  84. // Trim trailing carriage-return and linefeed
  85. p = strchr(string, '\r');
  86. if (p) {
  87. *p = '\0';
  88. }
  89. p = strchr(string, '\n');
  90. if (p) {
  91. *p = '\0';
  92. }
  93. // Trim trailing spaces
  94. if (strlen(string)) {
  95. p = string + strlen(string) - 1;
  96. while (p != string && isspace(*p)) {
  97. *p = '\0';
  98. p--;
  99. }
  100. }
  101. }
  102. return ret;
  103. }
  104. int __cdecl main(int argc, char*argv[])
  105. {
  106. FILE *fp;
  107. char *p;
  108. char *StopString;
  109. long LineNumber;
  110. long ExpectedMessageNumber;
  111. long ActualMessageNumber;
  112. fp = fopen("messages.h", "r");
  113. if (!fp) {
  114. ExitErrMsg(TRUE, "Could not open messages.h for read");
  115. }
  116. printf("Validating message table...\n");
  117. // Scan down until the MSG_TABLE_BEGIN has been found
  118. LineNumber = 0;
  119. do {
  120. LineNumber++;
  121. p = MyFgets(LineBuffer, MAX_LINE_LENGTH, fp);
  122. if (!p) {
  123. // EOF or error
  124. ExitErrMsg(FALSE, "EOF reached in messages.h without finding 'MSG_TABLE_BEGIN'\n");
  125. }
  126. } while (strcmp(p, "MSG_TABLE_BEGIN"));
  127. // Validate the messages are in order
  128. ExpectedMessageNumber = 0;
  129. for (;;) {
  130. LineNumber++;
  131. p = MyFgets(LineBuffer, MAX_LINE_LENGTH, fp);
  132. if (!p) {
  133. // EOF or error
  134. ExitErrMsg(FALSE, "EOF reached in messages.h without finding 'MSG_TABLE_END'\n");
  135. }
  136. // Skip leading blanks
  137. p = LineBuffer;
  138. while (isspace(*p)) {
  139. p++;
  140. }
  141. if (strcmp(p, "MSG_TABLE_END") == 0) {
  142. // hit end of the table.
  143. break;
  144. } else if (strncmp(p, "MSG_ENTRY", 9)) {
  145. // Possibly blank line or multi-line MSG_ENTRY_ macro
  146. continue;
  147. }
  148. // Find the opening paren
  149. p = strchr(p, '(');
  150. if (!p) {
  151. ExitErrMsg(FALSE, "messages.h line %d - end of line reached without finding '('\n", LineNumber);
  152. }
  153. p++; // skip the '(';
  154. // Convert the message number to a long, using the C rules to determine base
  155. ActualMessageNumber = strtol(p, &StopString, 0);
  156. if (ExpectedMessageNumber != ActualMessageNumber) {
  157. ExitErrMsg(FALSE, "messages.h line %d - Actual message 0x%x does not match expected 0x%x\n",
  158. LineNumber, ActualMessageNumber, ExpectedMessageNumber);
  159. }
  160. ExpectedMessageNumber++;
  161. }
  162. if (ExpectedMessageNumber != WM_USER) {
  163. ExitErrMsg(FALSE, "messages.h line %d - hit MSG_TABLE_END but got 0x%x messages instead of expected 0x%x\n",
  164. LineNumber, ExpectedMessageNumber, WM_USER);
  165. }
  166. printf("Message table validated OK.\n");
  167. return 0;
  168. }