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.

400 lines
9.5 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. gpdcheck.c
  5. Abstract:
  6. gpd parser test program
  7. Environment:
  8. uni driver, gpd parser, Check build only
  9. Revision History:
  10. 03/27/97 -peterwo-
  11. Created it.
  12. --*/
  13. #include "lib.h"
  14. PTSTR pwstrGenerateGPDfilename(
  15. PTSTR ptstrSrcFilename
  16. ) ;
  17. BOOL BcreateGPDbinary(
  18. PWSTR pwstrFileName, // root GPD file
  19. DWORD dwVerbosity );
  20. // ---- functions defined in treewalk.c ---- //
  21. BOOL GetGPDResourceIDs(
  22. PDWORD pdwResArray,
  23. DWORD dwArraySize, // number of elements in array.
  24. PDWORD pdwNeeded,
  25. BOOL bFontIDs,
  26. PRAWBINARYDATA prbd) ;
  27. #ifndef DBG
  28. //
  29. // Variable to control the amount of debug messages generated
  30. //
  31. INT giDebugLevel = DBG_WARNING;
  32. PCSTR
  33. StripDirPrefixA(
  34. IN PCSTR pstrFilename
  35. )
  36. /*++
  37. Routine Description:
  38. Strip the directory prefix off a filename (ANSI version)
  39. Arguments:
  40. pstrFilename - Pointer to filename string
  41. Return Value:
  42. Pointer to the last component of a filename (without directory prefix)
  43. --*/
  44. {
  45. PCSTR pstr;
  46. if (pstr = strrchr(pstrFilename, PATH_SEPARATOR))
  47. return pstr + 1;
  48. return pstrFilename;
  49. }
  50. #endif
  51. HINSTANCE ghInstance;
  52. PSTR gstrProgName;
  53. PINFOHEADER gpInfoHdr;
  54. PUIINFO gpUIInfo;
  55. DWORD gdwTotalSize, gdwNumFiles, gdwMaxFileSize;
  56. FILE *stream ;
  57. #define DumpInt(label, n) DbgPrint("%s: %d\n", label, n)
  58. #define DumpHex(label, n) DbgPrint("%s: 0x%x\n", label, n)
  59. #define DumpStrW(label, offset) DbgPrint("%s: %ws\n", label, OFFSET_TO_POINTER(gpRawData, offset))
  60. #define DumpStrA(label, offset) DbgPrint("%s: %s\n", label, OFFSET_TO_POINTER(gpRawData, offset))
  61. #define DumpFix(label, n) DbgPrint("%s: %f\n", label, (FLOAT) (n) / FIX_24_8_SCALE)
  62. #define DumpInvo(label, p) DbgPrint("%s: %d bytes\n", label, (p)->dwCount)
  63. #define DumpSize(label, p) DbgPrint("%s: %d x %d\n", label, (p)->cx, (p)->cy)
  64. #define DumpRect(label, p) DbgPrint("%s: (%d, %d) - (%d, %d)\n", label, \
  65. (p)->left, (p)->top, (p)->right, (p)->bottom)
  66. ULONG _cdecl
  67. DbgPrint(
  68. PCSTR pstrFormat,
  69. ...
  70. )
  71. {
  72. va_list ap;
  73. va_start(ap, pstrFormat);
  74. vfprintf(stream, pstrFormat, ap);
  75. va_end(ap);
  76. return 0;
  77. }
  78. VOID
  79. usage(
  80. VOID
  81. )
  82. {
  83. printf("usage: %s [-options] filenames ...\n", gstrProgName);
  84. printf("where options are:\n");
  85. printf(" -n delete existing log file, instead of appending to it\n");
  86. printf(" -k keep the binary GPD data\n");
  87. printf(" -x perform additional semantics check\n") ;
  88. printf(" -s suppress all console output\n") ;
  89. printf(" -v(0-4) set verbosity level -v0 lowest, -v4 highest\n") ;
  90. printf(" -h display help information\n");
  91. exit(-1);
  92. }
  93. INT _cdecl
  94. main(
  95. INT argc,
  96. CHAR **argv
  97. )
  98. {
  99. BOOL bDeleteLog, bKeepBUD, bFirstFile, bSuppress, bSemantics;
  100. DWORD dwTime;
  101. DWORD dwVerbosity = 0;
  102. //
  103. // Go through the command line arguments
  104. //
  105. ghInstance = GetModuleHandle(NULL);
  106. bSuppress = bDeleteLog = bKeepBUD = bSemantics = FALSE;
  107. bFirstFile = TRUE ;
  108. giDebugLevel = DBG_TERSE;
  109. gdwTotalSize = gdwNumFiles = gdwMaxFileSize = 0 ;
  110. gstrProgName = *argv++;
  111. argc--;
  112. if (argc == 0)
  113. usage();
  114. dwTime = GetTickCount();
  115. for ( ; argc--; argv++)
  116. {
  117. PSTR pArg = *argv;
  118. if (*pArg == '-' || *pArg == '/')
  119. {
  120. //
  121. // The argument is an option flag
  122. //
  123. switch (*++pArg) {
  124. case 'n':
  125. case 'N':
  126. bDeleteLog = TRUE;
  127. break;
  128. case 'k':
  129. case 'K':
  130. bKeepBUD = TRUE;
  131. break;
  132. case 's':
  133. case 'S':
  134. bSuppress = TRUE;
  135. break;
  136. case 'x':
  137. case 'X':
  138. bSemantics = TRUE;
  139. break;
  140. case 'v':
  141. case 'V':
  142. if (*++pArg >= '0' && *pArg <= '4')
  143. {
  144. dwVerbosity = *pArg - '0';
  145. }
  146. break;
  147. default:
  148. if(!bSuppress)
  149. usage();
  150. break;
  151. }
  152. }
  153. else
  154. {
  155. WCHAR wstrFilename[MAX_PATH];
  156. PTSTR ptstrBudFilename;
  157. if(bFirstFile && bDeleteLog)
  158. { // truncate
  159. stream = fopen("gpdparse.log", "w") ;
  160. }
  161. else
  162. stream = fopen("gpdparse.log", "a+") ;
  163. if(!stream)
  164. {
  165. printf("unable to open gpdparse.log for write access.\n");
  166. exit(-1);
  167. }
  168. bFirstFile = FALSE ;
  169. //
  170. // Convert ANSI filename to Unicode filename
  171. //
  172. MultiByteToWideChar(CP_ACP, 0, pArg, -1, wstrFilename, MAX_PATH);
  173. fprintf(stream, "\n*** GPD parsing errors for %ws\n", wstrFilename);
  174. if (BcreateGPDbinary(wstrFilename, dwVerbosity))
  175. {
  176. // gdwTotalSize += gpRawData->dwFileSize;
  177. gdwNumFiles++;
  178. // if (gpRawData->dwFileSize > gdwMaxFileSize)
  179. // gdwMaxFileSize = gpRawData->dwFileSize;
  180. // MemFree(gpRawData);
  181. if(bSemantics)
  182. {
  183. PRAWBINARYDATA pRawData ;
  184. PINFOHEADER pInfoHdr ;
  185. fprintf(stream, "\n\tsnapshot and semantics errors: \n");
  186. pRawData = LoadRawBinaryData(wstrFilename) ;
  187. #if 0
  188. // this part to test treewalk.c functions
  189. {
  190. BOOL bStatus ;
  191. PDWORD pdwResArray = NULL;
  192. DWORD dwArraySize = 0; // number of elements in array.
  193. DWORD dwNeeded = 0;
  194. BOOL bFontIDs ;
  195. bStatus = GetGPDResourceIDs(
  196. pdwResArray,
  197. dwArraySize, // number of elements in array.
  198. &dwNeeded,
  199. bFontIDs = TRUE,
  200. pRawData) ;
  201. if(bStatus)
  202. {
  203. pdwResArray = (PDWORD) VirtualAlloc(
  204. NULL, // address of region to reserve or commit
  205. dwNeeded * sizeof(DWORD), // size of region
  206. MEM_COMMIT,
  207. // type of allocation
  208. PAGE_READWRITE // type of access protection
  209. );
  210. }
  211. if(pdwResArray)
  212. {
  213. dwArraySize = dwNeeded ;
  214. bStatus = GetGPDResourceIDs(
  215. pdwResArray,
  216. dwArraySize, // number of elements in array.
  217. &dwNeeded,
  218. bFontIDs = TRUE,
  219. pRawData) ;
  220. }
  221. VirtualFree(
  222. pdwResArray, // address of region of committed pages
  223. 0, // size of region
  224. MEM_RELEASE // type of free operation
  225. );
  226. pdwResArray = NULL ;
  227. bStatus = GetGPDResourceIDs(
  228. pdwResArray,
  229. dwArraySize, // number of elements in array.
  230. &dwNeeded,
  231. bFontIDs = FALSE,
  232. pRawData) ;
  233. if(bStatus)
  234. {
  235. pdwResArray = (PDWORD) VirtualAlloc(
  236. NULL, // address of region to reserve or commit
  237. dwNeeded * sizeof(DWORD), // size of region
  238. MEM_COMMIT,
  239. // type of allocation
  240. PAGE_READWRITE // type of access protection
  241. );
  242. }
  243. if(pdwResArray)
  244. {
  245. dwArraySize = dwNeeded ;
  246. bStatus = GetGPDResourceIDs(
  247. pdwResArray,
  248. dwArraySize, // number of elements in array.
  249. &dwNeeded,
  250. bFontIDs = FALSE,
  251. pRawData) ;
  252. }
  253. VirtualFree(
  254. pdwResArray, // address of region of committed pages
  255. 0, // size of region
  256. MEM_RELEASE // type of free operation
  257. );
  258. pdwResArray = NULL ;
  259. }
  260. // end treewalk test
  261. #endif
  262. if(pRawData)
  263. pInfoHdr = InitBinaryData(pRawData, NULL, NULL ) ;
  264. if(pRawData && pInfoHdr)
  265. FreeBinaryData(pInfoHdr) ;
  266. if(pRawData)
  267. UnloadRawBinaryData(pRawData) ;
  268. }
  269. //
  270. // If -k option is not given, get rid of the Bud file after we're done
  271. //
  272. if (! bKeepBUD && (ptstrBudFilename = pwstrGenerateGPDfilename(wstrFilename)))
  273. {
  274. DeleteFile(ptstrBudFilename);
  275. MemFree(ptstrBudFilename);
  276. }
  277. }
  278. fclose(stream) ;
  279. }
  280. }
  281. if ((gdwNumFiles > 0) && !bSuppress)
  282. {
  283. dwTime = GetTickCount() - dwTime;
  284. printf("Number of files parsed: %d\n", gdwNumFiles);
  285. printf("Average parsing time per file (ms): %d\n", dwTime / gdwNumFiles);
  286. }
  287. return 0;
  288. }