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.

186 lines
5.6 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: structo.c
  3. *
  4. * Structure parser - struct field name-offset tabel generator.
  5. *
  6. * Copyright (c) 1985-96, Microsoft Corporation
  7. *
  8. * 04/09/96 GerardoB Created
  9. \***************************************************************************/
  10. #include "structo.h"
  11. /*********************************************************************
  12. * soProcessParameters
  13. *
  14. \***************************************************************************/
  15. UINT soProcessParameters(int argc, LPSTR argv[], PWORKINGFILES pwf)
  16. {
  17. char c, *p;
  18. int argcParm = argc;
  19. while (--argc) {
  20. p = *++argv;
  21. if (*p == '/' || *p == '-') {
  22. while (c = *++p) {
  23. switch (toupper(c)) {
  24. case 'I':
  25. if (pwf->pszIncInputFileExt != NULL) {
  26. soLogMsg(SOLM_ERROR, "Invalid -i parameter");
  27. goto PrintHelp;
  28. }
  29. pwf->dwOptions |= SOWF_INCLUDEINPUTFILE;
  30. argc--, argv++;
  31. pwf->pszIncInputFileExt = *argv;
  32. break;
  33. case 'L':
  34. pwf->dwOptions |= SOWF_LISTONLY;
  35. break;
  36. case 'O':
  37. if (pwf->pszOutputFile != NULL) {
  38. soLogMsg(SOLM_ERROR, "Invalid -o parameter");
  39. goto PrintHelp;
  40. }
  41. argc--, argv++;
  42. pwf->pszOutputFile = *argv;
  43. break;
  44. case 'P':
  45. pwf->dwOptions |= SOWF_INLCLUDEPRECOMPH;
  46. break;
  47. case 'S':
  48. if (pwf->pszStructsFile != NULL) {
  49. soLogMsg(SOLM_ERROR, "Invalid -s parameter");
  50. goto PrintHelp;
  51. }
  52. argc--, argv++;
  53. pwf->pszStructsFile = *argv;
  54. break;
  55. default:
  56. soLogMsg(SOLM_ERROR, "Invalid parameter: %c", c);
  57. // Fall through
  58. case '?':
  59. goto PrintHelp;
  60. }
  61. } /* while (c = *++p) */
  62. } else { /* if switch */
  63. pwf->pszInputFile = *argv;
  64. break;
  65. }
  66. } /* while (--argc) */
  67. if ((pwf->pszInputFile == NULL) || (pwf->pszOutputFile == NULL)) {
  68. goto PrintHelp;
  69. }
  70. if ((pwf->dwOptions & SOWF_LISTONLY) && (pwf->pszStructsFile != NULL)) {
  71. soLogMsg(SOLM_ERROR, "Cannot use -s and -l together ");
  72. goto PrintHelp;
  73. }
  74. return argcParm - argc;
  75. PrintHelp:
  76. soLogMsg(SOLM_DEFAULT, "Structure Field Name-Offset Table Generator");
  77. soLogMsg(SOLM_NOLABEL, "Usage: structo [options] <-o OutputFile> InputFile1 ...");
  78. soLogMsg(SOLM_NOLABEL, "\tInputFile - Preprocessed C header file");
  79. soLogMsg(SOLM_NOLABEL, "\t[-i ext] #include input file name using extension ext");
  80. soLogMsg(SOLM_NOLABEL, "\t[-l] Build structure list only");
  81. soLogMsg(SOLM_NOLABEL, "\t<-o OutputFile> required");
  82. soLogMsg(SOLM_NOLABEL, "\t[-p] #include \"precomp.h\" and #pragma hdrstop in output file");
  83. soLogMsg(SOLM_NOLABEL, "\t[-s StructFile] Struct names text file.");
  84. return 0;
  85. }
  86. /*********************************************************************
  87. * soGenerateTable
  88. *
  89. \***************************************************************************/
  90. BOOL soGenerateTable (PWORKINGFILES pwf)
  91. {
  92. char * pTag;
  93. UINT uLoops;
  94. if (!soOpenWorkingFiles(pwf)) {
  95. return FALSE;
  96. }
  97. soLogMsg (SOLM_NOEOL, "Processing %s ...", pwf->pszInputFile);
  98. uLoops = 0;
  99. while (pTag = soFindTag(pwf->pmap, pwf->pmapEnd, gszStructTag)) {
  100. pwf->pmap = pTag;
  101. pTag = soParseStruct (pwf);
  102. if (pTag == NULL) {
  103. break;
  104. }
  105. pwf->pmap = pTag;
  106. if (++uLoops == 50) {
  107. soLogMsg (SOLM_APPEND, ".");
  108. uLoops = 0;
  109. }
  110. }
  111. soLogMsg (SOLM_NOLABEL, ".");
  112. soCloseWorkingFiles(pwf, SOCWF_DEFAULT);
  113. return TRUE;
  114. }
  115. /*********************************************************************
  116. * InitWF
  117. \***************************************************************************/
  118. BOOL InitWF (PWORKINGFILES pwf)
  119. {
  120. ZeroMemory (pwf, sizeof(WORKINGFILES));
  121. pwf->hfileInput = INVALID_HANDLE_VALUE ;
  122. pwf->hfileOutput = INVALID_HANDLE_VALUE ;
  123. pwf->hfileTemp = INVALID_HANDLE_VALUE ;
  124. return TRUE;
  125. }
  126. /*********************************************************************
  127. * main
  128. *
  129. \***************************************************************************/
  130. int __cdecl main (int argc, char *argv[])
  131. {
  132. BOOL fGenerated = TRUE;
  133. int argcProcessed;
  134. WORKINGFILES wf;
  135. InitWF(&wf);
  136. do {
  137. argcProcessed = soProcessParameters(argc, argv, &wf);
  138. if (argcProcessed == 0) {
  139. break;
  140. }
  141. argc -= argcProcessed;
  142. argv += argcProcessed;
  143. if (!soGenerateTable(&wf)) {
  144. fGenerated = FALSE;
  145. break;
  146. }
  147. wf.dwOptions |= SOWF_APPENDOUTPUT;
  148. } while (argc > 1);
  149. if (fGenerated && (wf.hfileTemp != INVALID_HANDLE_VALUE)) {
  150. fGenerated = soCopyStructuresTable (&wf);
  151. if (fGenerated) {
  152. soLogMsg (SOLM_DEFAULT, "%s has been succesfully generated.", wf.pszOutputFile);
  153. }
  154. }
  155. soCloseWorkingFiles (&wf, SOCWF_CLEANUP);
  156. return !fGenerated;
  157. }