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.

214 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1994 - 1995 Microsoft Corporation
  3. Module Name:
  4. inf.c
  5. Abstract:
  6. Create New Inf from Old Inf
  7. Author:
  8. Muhunthan Sivapragasam (MuhuntS) 5-Oct-1995
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <memory.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <tchar.h>
  19. #define COUNT 1000
  20. #define LEN 25
  21. #define LEN2 55
  22. #define MANF 4
  23. int
  24. main (argc, argv)
  25. int argc;
  26. char *argv[];
  27. {
  28. FILE *OldInf, *NewInf;
  29. char Line[MAX_PATH];
  30. char *DriverName, *ui, *secn, *type, *p;
  31. char Section[COUNT][LEN], Model[COUNT][LEN2];
  32. int i, Lines;
  33. if ( argc != 3 ) {
  34. printf("Usage: %s <old-inf-name> <new-inf-name>\n", argv[0]);
  35. return;
  36. }
  37. OldInf = NewInf = NULL;
  38. OldInf = fopen(argv[1], "r");
  39. NewInf = fopen(argv[2], "w");
  40. if ( !OldInf ) {
  41. printf("%s: Can't open %s to read\n", argv[0], argv[1]);
  42. goto Cleanup;
  43. }
  44. if ( !NewInf ) {
  45. printf("%s: Can't open %s to write\n", argv[0], argv[2]);
  46. goto Cleanup;
  47. }
  48. Lines = 0;
  49. while ( fgets(Line, MAX_PATH-1, OldInf) ) {
  50. DriverName = strtok(Line+1, "\"");
  51. strtok(NULL, "=");
  52. ui = strtok(NULL, ",");
  53. secn = strtok(NULL, ",") + 1;
  54. type = strtok(NULL, "\n");
  55. while ( *ui == ' ' )
  56. ++ui;
  57. while ( *secn == ' ' )
  58. ++secn;
  59. while ( *type == ' ' )
  60. ++type;
  61. strcpy(Section[Lines], secn);
  62. strcpy(Model[Lines], DriverName);
  63. for ( p = Section[Lines] ; *p ; ++p )
  64. *p = toupper(*p);
  65. for ( p = DriverName ; *p ; ++p ) {
  66. if ( isalpha(*p) )
  67. *p = toupper(*p);
  68. else if ( !isdigit(*p) )
  69. *p = '_';
  70. }
  71. if ( strcmp(type, "rasdd") )
  72. strcat(Section[Lines], ".DLL");
  73. else if ( strcmp(type, "pscript") )
  74. strcat(Section[Lines], ".PPD");
  75. else if ( strcmp(type, "plotter") )
  76. strcat(Section[Lines], ".PCD");
  77. else
  78. printf("Error: <%s> <%s> <%s> <%s> on Line %d\n",
  79. DriverName, ui, secn, type, Lines);
  80. if ( !Lines || strncmp(Model[Lines], Model[Lines-1], 3) )
  81. fprintf(NewInf, "\n[%s]\n", DriverName);
  82. fprintf(NewInf, "%%%s%%", DriverName);
  83. for ( i = strlen(DriverName)+1 ; i < 54 ; ++i )
  84. fputc(' ', NewInf);
  85. fprintf(NewInf, "= %s\n", Section[Lines]);
  86. ++Lines;
  87. }
  88. fprintf(NewInf,"\n\n\n\n\n");
  89. qsort(Section, Lines, LEN, strcmp);
  90. i = 0;
  91. while ( i < Lines ) {
  92. fprintf(NewInf, "\[%s\]\n", Section[i]);
  93. fprintf(NewInf, "CopyFiles=@%s,", Section[i]);
  94. p = Section[i] + strlen(Section[i]) - 3;
  95. if ( strcmp(p, "DLL") ) {
  96. fprintf(NewInf, "RASDD\nDataSection=RASDD_DATA\n\n");
  97. } else if ( strcmp(p, "PPD") ) {
  98. fprintf(NewInf, "PSCRIPT\nDataSection=PSCRIPT_DATA\n\n");
  99. } else if ( strcmp(p, "PCD") ) {
  100. fprintf(NewInf, "PLOTTER\nDataSection=PLOTTER_DATA\n\n");
  101. } else
  102. printf("%s -- ???\n", p);
  103. ++i;
  104. }
  105. fprintf(NewInf, "\n\n\n\n\n");
  106. fprintf(NewInf, "[PSCRIPT]\n");
  107. fprintf(NewInf, "PSCRIPT.DLL\n");
  108. fprintf(NewInf, "PSCRPTUI.DLL\n");
  109. fprintf(NewInf, "PSCRIPT.HLP\n\n");
  110. fprintf(NewInf, "[RASDD]\n");
  111. fprintf(NewInf, "RASDD.DLL\n");
  112. fprintf(NewInf, "RASDDUI.DLL\n");
  113. fprintf(NewInf, "RASDDUI.HLP\n\n");
  114. fprintf(NewInf, "[PLOTTER]\n");
  115. fprintf(NewInf, "PLOTTER.DLL\n");
  116. fprintf(NewInf, "PLOTUI.DLL\n");
  117. fprintf(NewInf, "PLOTUI.HLP\n\n");
  118. fprintf(NewInf, "\n\n\n\n\n");
  119. fprintf(NewInf, "[PSCRIPT_DATA]\n");
  120. fprintf(NewInf, "DriverFile=PSCRIPT.DLL\n");
  121. fprintf(NewInf, "ConfigFile=PSCRPTUI.DLL\n");
  122. fprintf(NewInf, "HelpFile=PSCRIPT.HLP\n\n");
  123. fprintf(NewInf, "[RASDD_DATA]\n");
  124. fprintf(NewInf, "DriverFile=RASDD.DLL\n");
  125. fprintf(NewInf, "ConfigFile=RASDDUI.DLL\n");
  126. fprintf(NewInf, "HelpFile=RASDD.HLP\n\n");
  127. fprintf(NewInf, "[PLOTTER_DATA]\n");
  128. fprintf(NewInf, "DriverFile=PLOTTER.DLL\n");
  129. fprintf(NewInf, "ConfigFile=PLOTUI.DLL\n");
  130. fprintf(NewInf, "HelpFile=PLOTUI.HLP\n\n");
  131. fprintf(NewInf, "\n\n\n\n\n");
  132. fprintf(NewInf, "[Strings]\n");
  133. i = 0;
  134. for ( i = 0 ; i < Lines ; ++i ) {
  135. for ( p = Model[i] ; *p ; ++p ) {
  136. if ( isalpha(*p) )
  137. fputc(toupper(*p), NewInf);
  138. else if ( !isdigit(*p) )
  139. fputc('_', NewInf);
  140. else
  141. fputc(*p, NewInf);
  142. }
  143. fprintf(NewInf, "=\"%s\"\n", Model[i]);
  144. }
  145. Cleanup:
  146. if ( OldInf )
  147. fclose(OldInf);
  148. if ( NewInf )
  149. fclose(NewInf);
  150. }