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.

235 lines
5.5 KiB

  1. //
  2. // 05.10.94 Joe Holman Add better messaging and commented out some
  3. // debugging code for media generation.
  4. //
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <windows.h>
  9. #include <time.h>
  10. #include "general.h"
  11. FILE* logFile;
  12. void Msg ( const char * szFormat, ... ) {
  13. va_list vaArgs;
  14. va_start ( vaArgs, szFormat );
  15. vprintf ( szFormat, vaArgs );
  16. vfprintf ( logFile, szFormat, vaArgs );
  17. va_end ( vaArgs );
  18. }
  19. void Header(argv)
  20. char* argv[];
  21. {
  22. time_t t;
  23. PRINT1("\n=========== INFS ===============\n");
  24. PRINT2("Input Layout: %s\n",argv[2]);
  25. PRINT2("Target directory for file lists: %s\n",argv[3]);
  26. time(&t); PRINT2("Time: %s",ctime(&t))
  27. PRINT1("================================\n\n");
  28. }
  29. void Usage()
  30. {
  31. printf("PURPOSE: Creates INF file lists.\n");
  32. printf("\n");
  33. printf("PARAMETERS:\n");
  34. printf("\n");
  35. printf("[LogFile] - Path to append a log of actions and errors.\n");
  36. printf("[InLayout] - Path of Layout file from which INFs are generated.\n");
  37. printf("[Target Dir] - Directory where i386, mips, and alpha dirs are for lists.\n\n");
  38. }
  39. int Same(a,b)
  40. char* a;
  41. char* b;
  42. {
  43. int i;
  44. int j;
  45. char tempa[100];
  46. char tempb[100];
  47. strcpy(tempa,a);
  48. strcpy(tempb,b);
  49. i=j=0;
  50. while (tempa[j]=tempa[i++])
  51. if (tempa[j]!=' ')
  52. j++;
  53. i=j=0;
  54. while (tempb[j]=tempb[i++])
  55. if (tempb[j]!=' ')
  56. j++;
  57. return(_stricmp(tempa,tempb));
  58. }
  59. void CreateInfs(e,path,records,cdProduct)
  60. Entry* e;
  61. char* path;
  62. int records;
  63. int cdProduct;
  64. {
  65. int i,j,t,quotes;
  66. char inf[MAX_PATH];
  67. char infPath[MAX_PATH];
  68. char section[MAX_PATH];
  69. char line[MAX_PATH];
  70. FILE *f=NULL;
  71. inf[0]='\0';
  72. section[0]='\0';
  73. for (i=0;i<records;i++) {
  74. //Msg ( "inf = %s, i=%d\n", e[i].inf,i );
  75. if (e[i].inf[0]) {
  76. if (_stricmp(e[i].inf,inf)) {
  77. if (f!=NULL) {
  78. fprintf(f,"\r\n");
  79. fclose(f);
  80. }
  81. strcpy(inf,e[i].inf);
  82. strcpy(infPath,path);
  83. if (path[strlen(path)-1]!='\\') {
  84. strcat(infPath,"\\");
  85. }
  86. strcat(infPath,inf);
  87. if (MyOpenFile(&f,infPath,"wb")) {
  88. Msg ( "ERROR: Must fix this problem, since all inf filelist's did not get created...\n" );
  89. exit(1);
  90. }
  91. //Msg ( "opening file: %s\n", infPath );
  92. PRINT2("INFO Making file list: %s\n",infPath)
  93. }
  94. if (_stricmp(e[i].section,section) ||
  95. (!i) ||
  96. _stricmp(e[i].inf,e[i-1].inf)) {
  97. strcpy(section,e[i].section);
  98. //Msg ("section=%s\n", section );
  99. fprintf(f,"\r\n%s\r\n",section);
  100. }
  101. if ((i==0) || (!((!_stricmp(e[i].name,e[i-1].name)) &&
  102. (!Same(e[i].inf,e[i-1].inf)) &&
  103. (!Same(e[i].infline,e[i-1].infline)) &&
  104. (!_stricmp(e[i].section,e[i-1].section))))) {
  105. quotes=t=j=0;
  106. line[0]='\0';
  107. while (e[i].infline[j]) {
  108. if (e[i].infline[j]=='\"')
  109. quotes++;
  110. if ((e[i].infline[j]!='\"') || ((quotes>2) && (quotes%2))){
  111. switch(e[i].infline[j])
  112. {
  113. case '[':
  114. j++;
  115. switch (e[i].infline[j])
  116. {
  117. case 's': case 'S':
  118. sprintf(&line[t],"%d\0",e[i].size);
  119. break;
  120. case 'd': case 'D':
  121. sprintf(&line[t],"%d\0",e[i].disk);
  122. break;
  123. case 'n': case 'N':
  124. sprintf(&line[t],"%s\0",strlen(e[i].medianame) ? e[i].medianame : e[i].name);
  125. break;
  126. break;
  127. }
  128. while(e[i].infline[j++]!=']');
  129. j--;
  130. break;
  131. default:
  132. line[t++]=e[i].infline[j];
  133. line[t]='\0';
  134. break;
  135. }
  136. while(line[t++]);
  137. t--;
  138. }
  139. j++;
  140. }
  141. line[t]='\0';
  142. fprintf(f,"%s\r\n",line);
  143. //Msg ( "line=%s\n", line );
  144. if (!e[i].infline[0]) {
  145. PRINT2("WARNING - No INF line specified for %s\n",e[i].name)
  146. }
  147. }
  148. }
  149. else {
  150. PRINT2("WARNING - No INF file specified for %s\n",e[i].name)
  151. }
  152. }
  153. fclose(f);
  154. }
  155. int __cdecl InfCompare(const void*,const void*);
  156. int __cdecl main(argc,argv)
  157. int argc;
  158. char* argv[];
  159. {
  160. Entry *e;
  161. char* buf;
  162. int records,i;
  163. int cdProduct;
  164. if (argc!=4) { Usage(); return(1); }
  165. if ((logFile=fopen(argv[1],"a"))==NULL)
  166. {
  167. printf("ERROR Couldn't open %s.\n",argv[1]);
  168. return(1);
  169. }
  170. Header(argv);
  171. LoadFile(argv[2],&buf,&e,&records,"ALL");
  172. //Msg ( "loaded records = %d\n", records );
  173. qsort(e,records,sizeof(Entry),InfCompare);
  174. //
  175. // If this is a cd-rom layout, all files will be on disk 1.
  176. // If floppy layout, some files will be on other disks.
  177. //
  178. for(cdProduct=1,i=0; i<records; i++) {
  179. if(e[i].disk > 1) {
  180. cdProduct=0;
  181. break;
  182. }
  183. }
  184. CreateInfs(e,argv[3],records,cdProduct);
  185. fclose(logFile);
  186. free(e);
  187. free(buf);
  188. return(0);
  189. }
  190. int __cdecl InfCompare(const void *v1, const void *v2)
  191. {
  192. int result;
  193. Entry *e1 = (Entry *)v1;
  194. Entry *e2 = (Entry *)v2;
  195. if (result=_stricmp(e1->inf,e2->inf)) return(result);
  196. if (result=_stricmp(e1->section,e2->section)) return(result);
  197. if (result=_stricmp(e1->infline,e2->infline)) return(result);
  198. return(_stricmp(e1->name,e2->name));
  199. }