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.

302 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. cabcheck.c
  5. Abstract:
  6. Program to access/dump information contained in Layout INFs in a readable
  7. format. It also supports various forms of querying of the layout INF.
  8. Author:
  9. Vijesh Shetty (vijeshs)
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. // By default process the [SourceDisksFiles] section and not the platform
  15. // specific sections.
  16. DWORD Platform = LAYOUTPLATFORMS_COMMON;
  17. //Make the 3 essential arguments global
  18. TCHAR LayoutFileName[MAX_PATH];
  19. TCHAR SortedList[MAX_PATH];
  20. TCHAR OutputIndexFile[MAX_PATH];
  21. BOOL
  22. FindSingleFile( PLAYOUT_CONTEXT LayoutContext,
  23. PCTSTR FileName )
  24. {
  25. BOOL ret=FALSE;
  26. FILE_LAYOUTINFORMATION LayoutInformation;
  27. MEDIA_INFO MediaInfo;
  28. ret = FindFileInLayoutInf( LayoutContext,
  29. FileName,
  30. &LayoutInformation,
  31. NULL,
  32. NULL,
  33. &MediaInfo);
  34. return( ret );
  35. }
  36. BOOL
  37. ProcessCommandLine( int ArgCount, TCHAR *ArgArray[] )
  38. /*
  39. Function to process the command line and seperate out options into tokens
  40. */
  41. {
  42. int i;
  43. LPTSTR Arg;
  44. BOOL ret=TRUE;
  45. if(ArgCount < 4 )
  46. return FALSE;
  47. // First check if we are trying to do the Compare of drvindex files.
  48. // Get the Layout filename
  49. lstrcpy( LayoutFileName, ArgArray[1] );
  50. // Get the Sorted List filename
  51. lstrcpy( SortedList, ArgArray[2] );
  52. // Get the Output Index filename
  53. lstrcpy( OutputIndexFile, ArgArray[3] );
  54. for ( i=4;i < ArgCount;i++ ){ //Go through each directive
  55. Arg = ArgArray[i];
  56. if( (Arg[0] != TEXT('/')) && (Arg[0] != TEXT('-')))
  57. continue;
  58. if(_istlower(Arg[1]))
  59. Arg[1] = _toupper(Arg[1]);
  60. switch( Arg[1] ){
  61. case TEXT('?'):
  62. break;
  63. case TEXT('A'):
  64. Platform |= LAYOUTPLATFORMS_AMD64;
  65. break;
  66. case TEXT('I'):
  67. Platform |= LAYOUTPLATFORMS_X86;
  68. break;
  69. case TEXT('M'):
  70. Platform |= LAYOUTPLATFORMS_IA64;
  71. break;
  72. default:
  73. break;
  74. }
  75. }// for
  76. return( TRUE );
  77. }
  78. void
  79. VerifyDriverList(
  80. PLAYOUT_CONTEXT LayoutContext
  81. )
  82. /*
  83. This function takes in the sorted list of drivers and crosschecks each file against the layout.inf.
  84. It also generates a drvindex stle output file based on this.
  85. Arguments :
  86. LayoutContext - Pointer to an already built layout inf context.
  87. Return value:
  88. None.
  89. */
  90. {
  91. FILE *SortedFile, *IndexFile;
  92. TCHAR PreviousFile[MAX_PATH], FileName[MAX_PATH];
  93. PTCHAR i;
  94. //OPen the sorted driver list
  95. if( !(SortedFile = _tfopen( SortedList, TEXT("r") )) ){
  96. _ftprintf( stderr, TEXT("ERROR: Could not open %s"), SortedList);
  97. return;
  98. }
  99. if( !(IndexFile = _tfopen( OutputIndexFile, TEXT("w") )) ){
  100. _ftprintf( stderr, TEXT("ERROR: Could not open %s"), OutputIndexFile);
  101. fclose(SortedFile);
  102. return;
  103. }
  104. //Write the header info to the file
  105. _ftprintf( IndexFile, TEXT("[Version]\n"));
  106. _ftprintf( IndexFile, TEXT("signature=\"$Windows NT$\"\n"));
  107. _ftprintf( IndexFile, TEXT("CabFiles=driver\n\n\n"));
  108. _ftprintf( IndexFile, TEXT("[driver]\n"));
  109. lstrcpy( PreviousFile, TEXT("$$$.#$$") );
  110. // HAck because of bug that doesn't allow the use of _TEOF. Bcoz of the bug
  111. // fscanf returns EOF but fwscanf returns 0 when it should return 0xffff. So _TEOF
  112. // is useless and causes us to loop.
  113. while(TRUE){
  114. #ifdef UNICODE
  115. if( (_ftscanf( SortedFile, TEXT("%s"), FileName )) == 0 )
  116. #else
  117. if( (_ftscanf( SortedFile, TEXT("%s"), FileName )) == _TEOF )
  118. #endif
  119. break;
  120. if(lstrcmpi( PreviousFile, FileName )){
  121. // Cross check against layout context
  122. if (FindFileInLayoutInf( LayoutContext,FileName,NULL,NULL,NULL,NULL)){
  123. for( i = FileName; i < FileName + lstrlen( FileName ); i++ ) {
  124. *i = (TCHAR)towlower( *i );
  125. }
  126. // File present - Write it out
  127. _ftprintf( IndexFile, TEXT("%s\n"), _tcslwr(FileName) );
  128. }
  129. }
  130. lstrcpy( PreviousFile, FileName );
  131. }
  132. clearerr(SortedFile);
  133. fflush(SortedFile);
  134. fclose(SortedFile);
  135. _ftprintf( IndexFile, TEXT("\n\n\n[Cabs]\n"));
  136. _ftprintf( IndexFile, TEXT("driver=driver.cab\n"));
  137. _flushall();
  138. _fcloseall();
  139. return;
  140. }
  141. void
  142. CmdLineHelp( )
  143. /*
  144. This routine displays the CmdLine help.
  145. */
  146. {
  147. _putts(TEXT("Program to process a sorted list of drivers and cross-check their existance in layout.inf\n")
  148. TEXT("This is to be used in the build process to cross-check the driver cab's contents against layout.inf\n\n" )
  149. TEXT("Usage: Cabcheck <Inf Filename> <Sorted driver list> <Output Index File> [arguments] \n" )
  150. TEXT("<Inf Filename> - Path to Layout File to examine (ex.layout.inf)\n")
  151. TEXT("<Sorted driver file> - File containing sorted list of drivers\n")
  152. TEXT("<Output Index File> - Output index filename\n\n")
  153. TEXT("Process Platform specific SourceDisksFiles section. Defaults to the [SourceDisksFiles] section only\n")
  154. TEXT("/i - Process for Intel i386\n")
  155. TEXT("/a - Process for AMD AMD64\n")
  156. TEXT("/m - Process for Intel IA64\n")
  157. TEXT("\n\n" ));
  158. return;
  159. }
  160. int
  161. _cdecl _tmain( int argc, TCHAR *argv[ ], char *envp[ ] )
  162. {
  163. PLAYOUT_CONTEXT LayoutContext;
  164. LPTSTR CommandLine;
  165. LPWSTR *CmdlineV;
  166. int CmdlineC;
  167. if(!pSetupInitializeUtils()) {
  168. _tprintf(TEXT("Initialize failure\n") );
  169. return 1;
  170. }
  171. if( !ProcessCommandLine( argc, argv ) ){
  172. CmdLineHelp();
  173. return 1;
  174. }
  175. _ftprintf( stderr, TEXT("\nParsing Layout file...wait...\n"));
  176. LayoutContext = BuildLayoutInfContext( LayoutFileName, Platform, 0);
  177. if( !LayoutContext ){
  178. _ftprintf(stderr,TEXT("\nError - Could not build Layout Inf context\n"));
  179. return 1;
  180. }
  181. VerifyDriverList( LayoutContext );
  182. CloseLayoutInfContext( LayoutContext );
  183. pSetupUninitializeUtils();
  184. return 0;
  185. }