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.

474 lines
12 KiB

  1. //
  2. // 08.08.94 Joe Holman Added code for PPC.
  3. //
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <windows.h>
  8. #include "general.h"
  9. extern FILE* logFile;
  10. #define PLATFORM_COUNT 4
  11. #define X86_PLATFORM 2 // index #2 into PSTR's below.
  12. PSTR GenericSubstitutions[PLATFORM_COUNT] = { "alpha","mips","i386", "ppc" };
  13. PSTR PlatformSubstitutions[PLATFORM_COUNT] = { "alpha","mips","x86", "ppc" };
  14. PSTR AclpathSubstitutions[PLATFORM_COUNT] = { "w32alpha","w32mips","w32x86", "w32ppc" };
  15. typedef struct _TRACKED_STRING {
  16. struct _TRACKED_STRING *Next;
  17. PSTR String;
  18. } TRACKED_STRING, *PTRACKED_STRING;
  19. PTRACKED_STRING SourceFieldStrings;
  20. PTRACKED_STRING PathFieldStrings;
  21. PTRACKED_STRING PlatformFieldStrings;
  22. PTRACKED_STRING CdPathFieldStrings;
  23. PTRACKED_STRING InfFileFieldStrings;
  24. PTRACKED_STRING InfSectionFieldStrings;
  25. PTRACKED_STRING AclPathFieldStrings;
  26. VOID
  27. ExpandField(
  28. IN OUT PSTR *Field,
  29. IN PSTR SubstituteText,
  30. IN OUT PTRACKED_STRING *StringList
  31. )
  32. {
  33. unsigned c;
  34. PSTR p;
  35. CHAR buf[1000];
  36. PTRACKED_STRING s;
  37. if(p = strchr(*Field,'@')) {
  38. c = p - (*Field);
  39. //
  40. // Create the platform-specific string.
  41. //
  42. strncpy(buf,*Field,c);
  43. buf[c] = 0;
  44. strcat(buf,SubstituteText);
  45. strcat(buf,(*Field) + c + 1);
  46. } else {
  47. //
  48. // No @, field doesn't need to change.
  49. //
  50. return;
  51. }
  52. //
  53. // See whether we already have this string.
  54. //
  55. s = *StringList;
  56. while(s) {
  57. if(!_stricmp(buf,s->String)) {
  58. *Field = s->String;
  59. return;
  60. }
  61. s = s->Next;
  62. }
  63. //
  64. // We don't already have it. Create it.
  65. //
  66. s = malloc(sizeof(TRACKED_STRING));
  67. if(!s) {
  68. PRINT1("ERROR Couldn't allocate enough memory.\n")
  69. exit(1);
  70. }
  71. s->String = _strdup(buf);
  72. if(!s->String) {
  73. PRINT1("ERROR Couldn't allocate enough memory.\n")
  74. exit(1);
  75. }
  76. *Field = s->String;
  77. s->Next = *StringList;
  78. *StringList = s;
  79. }
  80. VOID
  81. ExpandPlatformIndependentEntry(
  82. IN OUT Entry *e,
  83. IN int FirstRecord
  84. )
  85. {
  86. int i,j;
  87. Entry t;
  88. t = *(e+FirstRecord);
  89. for(i=0,j=FirstRecord; i<PLATFORM_COUNT; i++,j++) {
  90. *(e+j) = t;
  91. //
  92. // expand the source field.
  93. //
  94. ExpandField(&e[j].source,PlatformSubstitutions[i],&SourceFieldStrings);
  95. //
  96. // expand the path field.
  97. //
  98. ExpandField(&e[j].path,GenericSubstitutions[i],&PathFieldStrings);
  99. //
  100. // expand the platform field.
  101. //
  102. ExpandField(&e[j].platform,PlatformSubstitutions[i],&PlatformFieldStrings);
  103. //
  104. // expand the cdpath field.
  105. //
  106. ExpandField(&e[j].cdpath,GenericSubstitutions[i],&CdPathFieldStrings);
  107. //
  108. // expand the inf file field.
  109. //
  110. ExpandField(&e[j].inf,GenericSubstitutions[i],&InfFileFieldStrings);
  111. //
  112. // expand the inf section field.
  113. //
  114. ExpandField(&e[j].section,GenericSubstitutions[i],&InfSectionFieldStrings);
  115. //
  116. // expand the aclpath section field.
  117. //
  118. ExpandField(&e[j].aclpath,AclpathSubstitutions[i],&AclPathFieldStrings);
  119. }
  120. }
  121. VOID
  122. ExpandPlatformEntryX86Only(
  123. IN OUT Entry *e,
  124. IN int FirstRecord
  125. )
  126. {
  127. int i,j;
  128. Entry t;
  129. t = *(e+FirstRecord);
  130. i = X86_PLATFORM;
  131. j = FirstRecord;
  132. *(e+j) = t;
  133. //
  134. // expand the source field.
  135. //
  136. ExpandField(&e[j].source,PlatformSubstitutions[i],&SourceFieldStrings);
  137. //
  138. // expand the path field.
  139. //
  140. ExpandField(&e[j].path,GenericSubstitutions[i],&PathFieldStrings);
  141. //
  142. // expand the platform field.
  143. //
  144. ExpandField(&e[j].platform,PlatformSubstitutions[i],&PlatformFieldStrings);
  145. //
  146. // expand the cdpath field.
  147. //
  148. ExpandField(&e[j].cdpath,GenericSubstitutions[i],&CdPathFieldStrings);
  149. //
  150. // expand the inf file field.
  151. //
  152. ExpandField(&e[j].inf,GenericSubstitutions[i],&InfFileFieldStrings);
  153. //
  154. // expand the inf section field.
  155. //
  156. ExpandField(&e[j].section,GenericSubstitutions[i],&InfSectionFieldStrings);
  157. //
  158. // expand the aclpath section field.
  159. //
  160. ExpandField(&e[j].aclpath,AclpathSubstitutions[i],&AclPathFieldStrings);
  161. }
  162. void LoadFile(name,buf,e,records,product)
  163. char* name;
  164. char** buf;
  165. Entry** e;
  166. int* records;
  167. char* product;
  168. {
  169. int match,i;
  170. HANDLE h;
  171. DWORD size,sizeRead,x;
  172. BOOL result;
  173. char* j;
  174. (*records)=0;
  175. h=CreateFile(name,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  176. size=GetFileSize(h,NULL);
  177. if ((h==INVALID_HANDLE_VALUE) || (size==-1))
  178. {
  179. PRINT2("ERROR Couldn't open %s for reading.\n",name)
  180. exit(1);
  181. }
  182. if (((*buf)=malloc(size))==NULL)
  183. {
  184. PRINT1("ERROR Couldn't allocate enough memory to read file.\n")
  185. exit(1);
  186. }
  187. result=ReadFile(h,*buf,size,&sizeRead,NULL);
  188. if ((sizeRead!=size) || (result==FALSE))
  189. {
  190. PRINT2("ERROR Couldn't read all of %s.\n",name)
  191. exit(1);
  192. }
  193. x=0; while((*buf)[x++]!='\n');
  194. while(x<size) {
  195. if ((*buf)[x]=='\t') (*buf)[x]='\0';
  196. if ((*buf)[x]=='\n') (*records)++;
  197. x++;
  198. }
  199. CloseHandle(h);
  200. //
  201. // Allocate maximum possible number of entries required.
  202. //
  203. if (((*e)=malloc(PLATFORM_COUNT*sizeof(Entry)*(*records)))==NULL) {
  204. PRINT1("ERROR Couldn't allocate enough space for database entries.\n")
  205. exit(1);
  206. }
  207. j=(*buf);
  208. while (*j++!='\n');
  209. match=0;
  210. for (i=0;i<(*records);i++) {
  211. (*e)[match].name=j; while ((*j!='\n') && (*j++));
  212. (*e)[match].source=j; while ((*j!='\n') && (*j++));
  213. (*e)[match].path=j; while ((*j!='\n') && (*j++));
  214. (*e)[match].flopmedia=j; while ((*j!='\n') && (*j++));
  215. (*e)[match].comment=j; while ((*j!='\n') && (*j++));
  216. (*e)[match].product=j; while ((*j!='\n') && (*j++));
  217. (*e)[match].sdk=j; while ((*j!='\n') && (*j++));
  218. (*e)[match].platform=j; while ((*j!='\n') && (*j++));
  219. (*e)[match].cdpath=j; while ((*j!='\n') && (*j++));
  220. (*e)[match].inf=j; while ((*j!='\n') && (*j++));
  221. (*e)[match].section=j; while ((*j!='\n') && (*j++));
  222. (*e)[match].infline=j; while ((*j!='\n') && (*j++));
  223. (*e)[match].size=atoi(j); while((*j!='\n') && (*j++));
  224. (*e)[match].csize=atoi(j); while((*j!='\n') && (*j++));
  225. (*e)[match].nocompress=j; while ((*j!='\n') && (*j++));
  226. (*e)[match].priority=atoi(j); while ((*j!='\n') && (*j++));
  227. (*e)[match].lmacl=j; while ((*j!='\n') && (*j++));
  228. (*e)[match].ntacl=j; while ((*j!='\n') && (*j++));
  229. (*e)[match].aclpath=j; while ((*j!='\n') && (*j++));
  230. (*e)[match].medianame=j; while ((*j!='\n') && (*j++));
  231. (*e)[match].disk=atoi(j); while ((*j!='\n') && (*j++));
  232. j++;
  233. (*e)[match].name=_strupr((*e)[match].name);
  234. (*e)[match].medianame=_strupr((*e)[match].medianame);
  235. if (EntryMatchProduct(&((*e)[match]),product)) {
  236. //
  237. // If this is a platform-independent entry,
  238. // expand it into one entry per platform.
  239. //
  240. if(((*e)[match].platform[0] == '@')
  241. || ((*e)[match].source[0] == '@')
  242. || ((*e)[match].cdpath[1] == '@'))
  243. {
  244. // If we are working with x86 floppies,
  245. // just expand for x86, no need for overhead with
  246. // other platforms.
  247. //
  248. if ( !_stricmp(product,"LMFLOP") ||
  249. !_stricmp(product,"NTFLOP") ) {
  250. PRINT2( "%s: Expanding ONLY for X86 flops...\n", (*e)[match].name );
  251. ExpandPlatformEntryX86Only( *e, match );
  252. ++match;
  253. }
  254. else {
  255. ExpandPlatformIndependentEntry(*e,match);
  256. match += PLATFORM_COUNT;
  257. }
  258. } else {
  259. // The data is ok as is here.
  260. match++;
  261. }
  262. }
  263. }
  264. //
  265. // Skip first line (column headings).
  266. //
  267. j=*buf;
  268. while (*j++!='\n');
  269. //
  270. // Change newlines into line terminators,
  271. // so the final field on each line will be terminated properly.
  272. //
  273. while(*records) {
  274. if((*j)=='\n') {
  275. *j='\0';
  276. (*records)--;
  277. }
  278. j++;
  279. }
  280. //
  281. // Shrink the array of records to its actual size.
  282. //
  283. *e = realloc(*e,match*sizeof(Entry));
  284. (*records)=match;
  285. }
  286. void EntryPrint(entry,f)
  287. Entry* entry;
  288. FILE *f;
  289. {
  290. fprintf(f,"%s\t",entry->name);
  291. fprintf(f,"%s\t",entry->source);
  292. fprintf(f,"%s\t",entry->path);
  293. fprintf(f,"%s\t",entry->flopmedia);
  294. fprintf(f,"%s\t",entry->comment);
  295. fprintf(f,"%s\t",entry->product);
  296. fprintf(f,"%s\t",entry->sdk);
  297. fprintf(f,"%s\t",entry->platform);
  298. fprintf(f,"%s\t",entry->cdpath);
  299. fprintf(f,"%s\t",entry->inf);
  300. fprintf(f,"%s\t",entry->section);
  301. fprintf(f,"%s\t",entry->infline);
  302. fprintf(f,"%d\t",entry->size);
  303. fprintf(f,"%d\t",entry->csize);
  304. fprintf(f,"%s\t",entry->nocompress);
  305. fprintf(f,"%d\t",entry->priority);
  306. fprintf(f,"%s\t",entry->lmacl);
  307. fprintf(f,"%s\t",entry->ntacl);
  308. fprintf(f,"%s\t",entry->aclpath);
  309. fprintf(f,"%s\t",entry->medianame);
  310. fprintf(f,"%d\r\n",entry->disk);
  311. }
  312. int EntryMatchProduct(entry,product)
  313. Entry* entry;
  314. char* product;
  315. {
  316. if (!_stricmp(product,"ALL"))
  317. return(1);
  318. return
  319. //
  320. // Laying out NT floppies AND entry is not for AS-only
  321. // AND entry specifies that this file goes on floppy
  322. //
  323. (!_stricmp(product,"NTFLOP") // include X86 floppy files
  324. && _stricmp(entry->product,"as") // exclude AS only files
  325. && (entry->priority < 1000) // include prioty < 1000
  326. && _stricmp(entry->source,"alphabins") // exclude alphabins files
  327. && _stricmp(entry->source,"mipsbins") // exclude mipsbins files
  328. && _stricmp(entry->source,"ppcbins") // exclude ppcbins files
  329. && _stricmp(entry->path,"\\mips") // exclude mips path files
  330. && _stricmp(entry->path,"\\alpha") // exclude alpha path files
  331. && _stricmp(entry->path,"\\ppc") // exclude ppc path files
  332. && _stricmp(entry->source,"alphadbg") // exclude alphadbg files
  333. && _stricmp(entry->source,"mipsdbg") // exclude mipsdbg files
  334. && _stricmp(entry->source,"ppcdbg" ) // exclude ppcdbg files
  335. && _stricmp(entry->source,"x86dbg") // exclude x86dbg files
  336. )
  337. //
  338. // Laying out AS floppies AND entry is not for NT-only
  339. // AND entry specified that this file goes on floppy
  340. //
  341. || (!_stricmp(product,"LMFLOP")
  342. && _stricmp(entry->product,"nt") // exclude NT only files
  343. && (entry->priority < 1000)
  344. && _stricmp(entry->source,"alphabins")
  345. && _stricmp(entry->source,"mipsbins")
  346. && _stricmp(entry->source,"ppcbins") // exclude ppcbins files
  347. && _stricmp(entry->path,"\\mips")
  348. && _stricmp(entry->path,"\\alpha")
  349. && _stricmp(entry->path,"\\ppc") // exclude ppc path files
  350. && _stricmp(entry->source,"alphadbg")
  351. && _stricmp(entry->source,"mipsdbg")
  352. && _stricmp(entry->source,"ppcdbg" ) // exclude ppcdbg files
  353. && _stricmp(entry->source,"x86dbg")
  354. )
  355. //
  356. // Laying out nt cd-rom and entry is not for as only
  357. //
  358. || (!_stricmp(product,"NTCD") && _stricmp(entry->product,"as"))
  359. //
  360. // Laying out as cd-rom and entry is not for nt only
  361. //
  362. || (!_stricmp(product,"LMCD") && _stricmp(entry->product,"nt"))
  363. //
  364. // Laying out sdk
  365. //
  366. || (!_stricmp(product,"SDK") && !_stricmp(entry->sdk,"x"));
  367. }
  368. int MyOpenFile(f,fileName,mode)
  369. FILE** f;
  370. char* fileName;
  371. char* mode;
  372. {
  373. if ((*f=fopen(fileName,mode))==NULL)
  374. {
  375. PRINT3("ERROR Couldn't open %s for %s\n",fileName,mode)
  376. return(1);
  377. }
  378. return(0);
  379. }
  380. void convertName(oldName,newName)
  381. char* oldName;
  382. char* newName;
  383. {
  384. unsigned i;
  385. unsigned period;
  386. strcpy(newName,oldName);
  387. for (period=(unsigned)(-1),i=0;i<strlen(oldName);i++) if (oldName[i]=='.') period=i;
  388. if (period==(strlen(oldName)-4))
  389. newName[strlen(newName)-1]='_';
  390. else if (period==(unsigned)(-1))
  391. strcat(newName,"._");
  392. else
  393. strcat(newName,"_");
  394. }