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.

334 lines
9.6 KiB

  1. #include "main.h"
  2. #include "depends.h"
  3. #include "resource.h"
  4. //
  5. // Code by AaronL
  6. // copied most of it from the depends source code.
  7. //
  8. //
  9. // prototypes...
  10. //
  11. int __cdecl main(int ,char *argv[]);
  12. void ShowHelp(void);
  13. void ProcessManyFiles(char * szTheDir, char * szTheFileNameOrWildCard);
  14. void ProcessOneFile(LPSTR szTempFileName);
  15. void OutputToScreen(char * szTheString1, char * szTheString2);
  16. //
  17. // Globals
  18. //
  19. int g_Flag_R = FALSE;
  20. HINSTANCE g_hModuleHandle = NULL;
  21. #define ALL_FILES 0xff
  22. //-------------------------------------------------------------------
  23. // purpose: main
  24. //-------------------------------------------------------------------
  25. int __cdecl main(int argc,char *argv[])
  26. {
  27. LPSTR pArg = NULL;
  28. LPSTR pCmdStart = NULL;
  29. int argno;
  30. int nflags=0;
  31. char szTempFileName[MAX_PATH];
  32. char szTempString[MAX_PATH];
  33. szTempFileName[0] = '\0';
  34. g_hModuleHandle = GetModuleHandle(NULL);
  35. // process command line arguments
  36. for(argno=1; argno<argc; argno++)
  37. {
  38. if ( argv[argno][0] == '-' || argv[argno][0] == '/' )
  39. {
  40. nflags++;
  41. switch (argv[argno][1])
  42. {
  43. case 'r':
  44. case 'R':
  45. g_Flag_R = TRUE;
  46. break;
  47. case '?':
  48. goto main_exit_with_help;
  49. break;
  50. }
  51. } // if switch character found
  52. else
  53. {
  54. if ( *szTempFileName == '\0' )
  55. {
  56. // if no arguments, then
  57. strcpy(szTempFileName, argv[argno]);
  58. }
  59. } // non-switch char found
  60. } // for all arguments
  61. char szTheDriveOnly[_MAX_DRIVE];
  62. char szTheDirOnly[_MAX_DIR];
  63. char szTheFileNameOnly[_MAX_FNAME];
  64. char szTheEXTOnly[_MAX_EXT];
  65. char szTheFileNameAndExt[_MAX_FNAME + _MAX_EXT];
  66. char szTheDriveAndDir[_MAX_PATH];
  67. if (strcmp(szTempFileName, "") == 0)
  68. {
  69. goto main_exit_with_help;
  70. }
  71. _splitpath(szTempFileName, szTheDriveOnly, szTheDirOnly, szTheFileNameOnly, szTheEXTOnly);
  72. sprintf(szTheFileNameAndExt, "%s%s", szTheFileNameOnly, szTheEXTOnly);
  73. sprintf(szTheDriveAndDir, "%s%s", szTheDriveOnly, szTheDirOnly);
  74. ProcessManyFiles(szTheDriveAndDir, szTheFileNameAndExt);
  75. goto main_exit_gracefully;
  76. main_exit_gracefully:
  77. return TRUE;
  78. main_exit_with_help:
  79. ShowHelp();
  80. return FALSE;
  81. }
  82. void ShowHelp()
  83. {
  84. char szModuleName[_MAX_PATH];
  85. char szFilename_only[_MAX_FNAME];
  86. char szMyBigString[255];
  87. char szMyPrintString[255 + _MAX_PATH];
  88. GetModuleFileName(NULL, szModuleName, _MAX_PATH);
  89. // Trim off the filename only.
  90. _tsplitpath(szModuleName, NULL, NULL, szFilename_only, NULL);
  91. MyLoadString(IDS_STRING1, szMyBigString);
  92. sprintf(szMyPrintString, szMyBigString, szFilename_only);
  93. printf(szMyPrintString);
  94. MyLoadString(IDS_STRING2, szMyBigString);
  95. printf(szMyBigString);
  96. MyLoadString(IDS_STRING3, szMyBigString);
  97. sprintf(szMyPrintString, szMyBigString, szFilename_only);
  98. printf(szMyPrintString);
  99. MyLoadString(IDS_STRING4, szMyBigString);
  100. sprintf(szMyPrintString, szMyBigString, szFilename_only);
  101. printf(szMyPrintString);
  102. return;
  103. }
  104. void ProcessOneFile(char * szTempFileName)
  105. {
  106. CDepends DependsStuff;
  107. char szMyPrintString[_MAX_PATH + 50];
  108. sprintf(szMyPrintString, "%s\r\n", (LPSTR) szTempFileName);
  109. printf(szMyPrintString);
  110. DependsStuff.SetInitialFilename(szTempFileName);
  111. if (DependsStuff.m_fOutOfMemory)
  112. {
  113. char szMyBigString[_MAX_PATH + 50];
  114. MyLoadString(IDS_STRING5, szMyBigString);
  115. sprintf(szMyPrintString, szMyBigString, (LPSTR) szTempFileName);
  116. printf(szMyPrintString);
  117. }
  118. // Display a message if the module contains a circular dependency error.
  119. if (DependsStuff.m_fCircularError)
  120. {
  121. char szMyBigString[_MAX_PATH + 50];
  122. MyLoadString(IDS_STRING6, szMyBigString);
  123. sprintf(szMyPrintString, szMyBigString, (LPSTR) szTempFileName);
  124. printf(szMyPrintString);
  125. }
  126. // Display a message if the module contains a mixed machine error.
  127. if (DependsStuff.m_fMixedMachineError)
  128. {
  129. //sprintf(szMyPrintString, " MixedMachineError:%s\r\n", (LPSTR) szTempFileName);
  130. //printf(szMyPrintString);
  131. }
  132. DependsStuff.LoopThruAndPrintLosers(DependsStuff.m_pModuleRoot);
  133. DependsStuff.DeleteContents();
  134. }
  135. void ProcessManyFiles(char * szTheDir, char * szTheFileNameOrWildCard)
  136. {
  137. WIN32_FIND_DATA FindFileData;
  138. char szTheFullMonty[_MAX_PATH];
  139. char szTheRealWildcards[_MAX_PATH];
  140. int iFoundWildCard = FALSE;
  141. if (0 == strcmp(szTheDir, ""))
  142. {
  143. // if there is no specified directory
  144. strcpy(szTheFullMonty, szTheFileNameOrWildCard);
  145. }
  146. else
  147. {
  148. // if there is a dir, check if ends with a '\'
  149. // if it does, then kool, if it doesn't then add it.
  150. // then tack them together
  151. char *pTemp = NULL;
  152. pTemp = strrchr(szTheDir, (int) '\\');
  153. if (pTemp != NULL)
  154. {
  155. sprintf(szTheFullMonty, "%s%s", szTheDir, szTheFileNameOrWildCard);
  156. }
  157. else
  158. {
  159. sprintf(szTheFullMonty, "%s\\%s", szTheDir, szTheFileNameOrWildCard);
  160. }
  161. }
  162. //printf(szTheFullMonty);printf("<--\n");
  163. // if the fullmonty is a directory
  164. // then we have a directory.
  165. // get out.
  166. int retCode = GetFileAttributes(szTheFullMonty);
  167. if (retCode == 0xFFFFFFFF || (retCode & FILE_ATTRIBUTE_DIRECTORY))
  168. {
  169. // if there are wildcards in there, then
  170. // let it come thru, if not get out.
  171. char szFileNamePart[_MAX_FNAME];
  172. char *pdest = NULL;
  173. strcpy(szFileNamePart, szTheFileNameOrWildCard);
  174. pdest = strrchr(szFileNamePart, (int) '?');
  175. if (pdest != NULL)
  176. {
  177. iFoundWildCard = TRUE;
  178. }
  179. if (FALSE == iFoundWildCard)
  180. {
  181. pdest = NULL;
  182. pdest = strrchr(szFileNamePart,(int) '*');
  183. if (pdest != NULL)
  184. {
  185. iFoundWildCard = TRUE;
  186. }
  187. }
  188. if (FALSE == iFoundWildCard)
  189. {
  190. return;
  191. }
  192. }
  193. // if we have something which includes wildcards,
  194. // then change it to *.*
  195. if (TRUE == iFoundWildCard)
  196. {
  197. char szTheDriveOnly[_MAX_DRIVE];
  198. char szTheDirOnly[_MAX_DIR];
  199. char szTheFileNameOnly[_MAX_FNAME];
  200. char szTheEXTOnly[_MAX_EXT];
  201. char szTheFileNameAndExt[_MAX_FNAME + _MAX_EXT];
  202. char szTheDriveAndDir[_MAX_PATH];
  203. _splitpath(szTheFullMonty, szTheDriveOnly, szTheDirOnly, szTheFileNameOnly, szTheEXTOnly);
  204. sprintf(szTheFileNameAndExt, "%s%s", szTheFileNameOnly, szTheEXTOnly);
  205. sprintf(szTheDriveAndDir, "%s%s", szTheDriveOnly, szTheDirOnly);
  206. printf(szTheFullMonty);
  207. printf("\n");
  208. printf(szTheFileNameAndExt);
  209. printf("\n");
  210. printf(szTheFileNameAndExt);
  211. printf("\n");
  212. }
  213. HANDLE hFile = FindFirstFile(szTheFullMonty, &FindFileData);
  214. if (hFile != INVALID_HANDLE_VALUE)
  215. {
  216. do {
  217. //printf("=%s\n",FindFileData.cFileName);
  218. if ( _tcsicmp(FindFileData.cFileName, _T(".")) != 0 && _tcsicmp(FindFileData.cFileName, _T("..")) != 0 )
  219. {
  220. if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  221. {
  222. // this is a directory, so let's skip it
  223. // if it's supposed to recurse thru dirs, then let's go into it.
  224. if (TRUE == g_Flag_R)
  225. {
  226. char szSubDir[_MAX_PATH];
  227. _stprintf(szSubDir, _T("%s"), FindFileData.cFileName);
  228. //printf("found dir=%s,filename=%s\n",szSubDir,szTheFileNameOrWildCard);
  229. ProcessManyFiles(szSubDir, szTheFileNameOrWildCard);
  230. }
  231. }
  232. else
  233. {
  234. // this is a file, so let's do something
  235. char szTempFileName[_MAX_PATH];
  236. if (0 == strcmp(szTheDir, ""))
  237. {
  238. // if there is no specified directory
  239. strcpy(szTempFileName,FindFileData.cFileName);
  240. }
  241. else
  242. {
  243. char *pTemp = NULL;
  244. pTemp = strrchr(szTheDir, (int) '\\');
  245. if (pTemp != NULL)
  246. {
  247. sprintf(szTempFileName, "%s%s", szTheDir, FindFileData.cFileName);
  248. }
  249. else
  250. {
  251. sprintf(szTempFileName, "%s\\%s", szTheDir, FindFileData.cFileName);
  252. }
  253. }
  254. // This is a file so lets act upon it.
  255. ProcessOneFile(szTempFileName);
  256. }
  257. }
  258. // get the next file
  259. if ( !FindNextFile(hFile, &FindFileData) )
  260. {
  261. FindClose(hFile);
  262. break;
  263. }
  264. } while (TRUE);
  265. }
  266. }
  267. void OutputToScreen(char * szTheString1, char * szTheString2)
  268. {
  269. char szMyPrintString[_MAX_PATH + _MAX_PATH];
  270. sprintf(szMyPrintString, szTheString1, szTheString2);
  271. printf(szMyPrintString);
  272. return;
  273. }
  274. void MyLoadString(int nID, char *szResult)
  275. {
  276. char buf[1024];
  277. if (g_hModuleHandle == NULL) {return;}
  278. if (LoadString(g_hModuleHandle, nID, buf, sizeof(buf)))
  279. {strcpy(szResult, buf);}
  280. return;
  281. }