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.

139 lines
3.7 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // idlclean
  3. //
  4. // Copyright (c) 1996-1999 Microsoft Corporation
  5. //
  6. // Takes a MIDL-generated .H file and converts the commented-out
  7. // [in] and [out] keywords into IN and OUT so sortpp/genthnk can
  8. // find them.
  9. //
  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. // string to put in front of all error messages so that BUILD can find them.
  19. const char *ErrMsgPrefix = "NMAKE : U8603: 'IDLCLEAN' ";
  20. #define BUFLEN 8192
  21. char buffer[BUFLEN];
  22. const char szLinePrefix[]="/* ";
  23. const char szIn[] = "[in]";
  24. const char szOut[] = "[out]";
  25. int __cdecl main(int argc, char *argv[])
  26. {
  27. FILE *fpIn, *fpOut;
  28. char *p;
  29. char *pchLineStart;
  30. BOOL fInPrinted;
  31. BOOL fOutPrinted;
  32. if (argc != 3) {
  33. fprintf(stderr, "%sUsage: IDLCLEAN infile outfile\n", ErrMsgPrefix);
  34. return 1;
  35. }
  36. fpIn = fopen(argv[1], "r");
  37. if (!fpIn) {
  38. fprintf(stderr, "%sCould not open input file '%s'\n", ErrMsgPrefix, argv[1]);
  39. return 1;
  40. }
  41. fpOut = fopen(argv[2], "w");
  42. if (!fpOut) {
  43. fprintf(stderr, "%sCould not open output file '%s\n", ErrMsgPrefix, argv[2]);
  44. return 1;
  45. }
  46. while (!feof(fpIn)) {
  47. //
  48. // Read a line from the input file
  49. //
  50. if (!fgets(buffer, BUFLEN, fpIn)) {
  51. break;
  52. }
  53. if (feof(fpIn)) {
  54. break;
  55. }
  56. pchLineStart = buffer;
  57. //
  58. // Skip leading spaces
  59. //
  60. while (*pchLineStart == ' ') {
  61. fprintf(fpOut, " ");
  62. pchLineStart++;
  63. }
  64. if (strncmp(pchLineStart, szLinePrefix, sizeof(szLinePrefix)-1) != 0) {
  65. //
  66. // Line doesn't start with the character sequence which prefixes
  67. // in/out decorators on arguments.
  68. //
  69. goto PrintLine;
  70. }
  71. //
  72. // Don't generate 'IN IN', etc. caused by MIDL output like
  73. // '[in][size_is][in]'
  74. //
  75. fInPrinted = FALSE;
  76. fOutPrinted = FALSE;
  77. //
  78. // Set a pointer to the first '['
  79. //
  80. p = pchLineStart + sizeof(szLinePrefix)-1;
  81. if (*p != '[') {
  82. //
  83. // The first char inside the comment isn't a '['. Just print
  84. // the line as-is.
  85. //
  86. goto PrintLine;
  87. }
  88. //
  89. // The line needs modification. Do it now.
  90. //
  91. fprintf(fpOut, " ");
  92. while (*p == '[') {
  93. if (strncmp(p, szIn, sizeof(szIn)-1) == 0) {
  94. if (!fInPrinted) {
  95. fprintf(fpOut, "IN ");
  96. fInPrinted = TRUE;
  97. }
  98. p += sizeof(szIn)-1;
  99. } else if (strncmp(p, szOut, sizeof(szOut)-1) == 0) {
  100. if (!fOutPrinted) {
  101. fprintf(fpOut, "OUT ");
  102. fOutPrinted = TRUE;
  103. }
  104. p += sizeof(szOut)-1;
  105. } else {
  106. //
  107. // Uninterresting [keyword]. Skip it.
  108. //
  109. while (*p != ']') {
  110. p++;
  111. }
  112. p++;
  113. }
  114. }
  115. //
  116. // pchLineStart points at the first non-space in the line, so the
  117. // whole line will be printed.
  118. //
  119. PrintLine:
  120. fprintf(fpOut, "%s", pchLineStart);
  121. }
  122. fclose(fpOut);
  123. fclose(fpIn);
  124. return 0;
  125. }