Leaked source code of windows server 2003
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.

153 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. infmerge.c
  5. Abstract:
  6. This module implements a program that merge two inf files
  7. to one inf file.
  8. See below for more information.
  9. Author:
  10. Katsumi Yokomichi (Katsumiy) 22-May-2000
  11. Revision History:
  12. --*/
  13. /*
  14. */
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <tchar.h>
  18. #include <shellapi.h>
  19. #include <setupapi.h>
  20. #include <spapip.h>
  21. CHAR Buffer[1024];
  22. CHAR Buffer2[1024];
  23. CHAR Section[1024];
  24. CHAR Section2[1024];
  25. FILE *InFile1;
  26. FILE *InFile2;
  27. FILE *OutFile;
  28. CHAR PrevSection[1024];
  29. /* Extract Section name (inside of []) from Line text. */
  30. BOOL GetSection(CHAR *p, CHAR *SectionName, INT SectionSize)
  31. {
  32. CHAR *cp;
  33. CHAR *sp1;
  34. CHAR *sp2;
  35. CHAR *q1;
  36. CHAR *q2 = 0;
  37. cp = strchr(p, ';');
  38. sp1 = strchr(p, '[');
  39. sp2 = strchr(p, ']');
  40. q1 = strchr(p, '"');
  41. if ( q1 ) {
  42. q2 = strchr(q1+1, '"');
  43. }
  44. if ((sp1 == NULL) ||
  45. (sp2 == NULL) ||
  46. (sp1 > sp2) ||
  47. (cp != NULL && cp < sp1) ||
  48. (q1 < sp1 && q2 > sp1)) {
  49. return FALSE;
  50. }
  51. strncpy(SectionName, sp1, max(SectionSize, sp2 - sp1));
  52. return TRUE;
  53. }
  54. /* Read 1 section from 2nd file and merge into Output file. */
  55. VOID Merge(VOID)
  56. {
  57. BOOL InSection2;
  58. fseek(InFile2, 0, SEEK_SET);
  59. InSection2 = FALSE;
  60. while (fgets(Buffer2, sizeof(Buffer2), InFile2)) {
  61. if (GetSection(Buffer2,Section2, sizeof(Section2))) {
  62. if (InSection2) {
  63. break;
  64. } else {
  65. if (0 == strcmp(Section2, PrevSection)) {
  66. InSection2 = TRUE;
  67. continue;
  68. }
  69. }
  70. }
  71. if (InSection2) {
  72. fputs(Buffer2, OutFile);
  73. }
  74. }
  75. }
  76. int
  77. __cdecl
  78. main(
  79. IN int argc,
  80. IN CHAR *argv[]
  81. )
  82. {
  83. BOOL InSection;
  84. if (argc != 4) {
  85. goto ErrorExit;
  86. }
  87. if ((InFile1 = fopen(argv[1], "r")) == NULL) {
  88. fprintf(stderr, "Can't open %s.\n", argv[1]);
  89. goto ErrorExit;
  90. }
  91. if ((InFile2 = fopen(argv[2], "r")) == NULL) {
  92. fprintf(stderr, "Can't open %s.\n", argv[2]);
  93. goto ErrorExit;
  94. }
  95. if ((OutFile = fopen(argv[3], "w")) == NULL) {
  96. fprintf(stderr, "Can't open %s.\n", argv[3]);
  97. goto ErrorExit;
  98. }
  99. InSection = FALSE;
  100. while (fgets(Buffer, sizeof(Buffer), InFile1)) {
  101. if (GetSection(Buffer,Section, sizeof(Section))) {
  102. if (InSection) {
  103. Merge();
  104. strcpy(PrevSection, Section);
  105. } else {
  106. InSection = TRUE;
  107. strcpy(PrevSection, Section);
  108. }
  109. }
  110. fputs(Buffer, OutFile);
  111. }
  112. if (InSection) {
  113. Merge();
  114. }
  115. return 0;
  116. ErrorExit:
  117. fprintf(stderr, "Usage: %s InputFile1 InputFile2 OutputFile.\n", argv[0]);
  118. return 1;
  119. }