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.

458 lines
12 KiB

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