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.

199 lines
4.7 KiB

  1. use strict;
  2. # Declare some globals to preserve namespace.
  3. my($BinplaceFile, $CDDataFile, $OutputFile);
  4. my(@BinplaceLines, @CDDataLines, $Move);
  5. # ParseCommandLine will set the three globals $BinplaceFile,
  6. # $CDDataFile, and $OutputFile.
  7. &ParseCommandLine(@ARGV);
  8. # We want to first move the files to the output directory.
  9. if ($Move) {
  10. &MoveInputFiles($Move);
  11. }
  12. # ReadBinplaceFile will set the @BinplaceLines array to the
  13. # first field in the binplace.log file.
  14. &ReadBinplaceFile($BinplaceFile);
  15. # ReadCDDataFile will set the @CDDataLines array to the name
  16. # of a file and the CDs which it is on.
  17. &ReadCDDataFile($CDDataFile);
  18. # ParseFiles will match files in @CDDataLines and @BinPlaceLines
  19. # and output to file or stdout.
  20. &ParseFiles();
  21. # Cleanup the files we moved.
  22. if ($Move) {
  23. system("del /Q $BinplaceFile");
  24. system("del /Q $CDDataFile");
  25. }
  26. # Finished!
  27. exit(0);
  28. sub MoveInputFiles
  29. {
  30. my $Dir = shift;
  31. # Create the directory if it doesn't already exist.
  32. unless (-e $Dir) {
  33. system("mkdir $Dir");
  34. }
  35. system("copy /Y $BinplaceFile $Dir");
  36. $BinplaceFile =~ /([^\\)]+)$/;
  37. $BinplaceFile = "$Dir\\$1";
  38. system("copy /Y $CDDataFile $Dir");
  39. $CDDataFile =~ /([^\\)]+)$/;
  40. $CDDataFile = "$Dir\\$1";
  41. }
  42. sub ParseCommandLine
  43. {
  44. my @Args = @_;
  45. my ($Argument, $Opt, $Value);
  46. # Set defaults.
  47. $BinplaceFile = "$ENV{'_NTTREE'}\\build_logs\\binplace.log";
  48. $CDDataFile = "$ENV{'_NTTREE'}\\build_logs\\cddata.txt.full";
  49. $Move = $OutputFile = "";
  50. # Parse command line.
  51. foreach $Argument (@Args) {
  52. if ($Argument =~ /^[\/\-](\w)\:?(.*)$/i) {
  53. $Opt = $1; $Value = $2;
  54. if ($Opt eq 'b') {
  55. # check for binplace file explicit set
  56. $BinplaceFile = $Value;
  57. } elsif ($Opt eq 'c') {
  58. # check for cddat a file explicit set
  59. $CDDataFile = $Value;
  60. } elsif ($Opt eq 'o') {
  61. # check for output file explicit set
  62. $OutputFile = $Value;
  63. } elsif ($Opt eq 'm') {
  64. $Move = $Value;
  65. } else { # Either $Opt is '?', or it's an invalid flag.
  66. &UsageAndQuit();
  67. }
  68. } else {
  69. &UsageAndQuit();
  70. }
  71. }
  72. # validate args, defaults
  73. unless(-e $BinplaceFile) {
  74. print "Can't see $BinplaceFile, exiting.\n";
  75. exit(1);
  76. }
  77. unless(-e $CDDataFile) {
  78. print "Can't see $CDDataFile, exiting.\n";
  79. exit(1);
  80. }
  81. }
  82. sub ReadBinplaceFile
  83. {
  84. my $FileName = shift;
  85. local(*INFILE);
  86. my $file;
  87. unless (open(INFILE, $FileName)) {
  88. print "Failed to open $FileName for reading, exiting ...\n";
  89. exit(1);
  90. }
  91. while (<INFILE>) {
  92. $file = lc((split(/\s+/))[0]);
  93. # Ignore WOW64-specifc files.
  94. if ($file !~ /wow6432\\obj/) {
  95. push(@BinplaceLines, $file);
  96. }
  97. }
  98. close(INFILE);
  99. }
  100. sub ReadCDDataFile
  101. {
  102. my $FileName = shift;
  103. local(*INFILE);
  104. unless (open(INFILE, $FileName)) {
  105. print "Failed to open $FileName for read, exiting ...\n";
  106. exit(1);
  107. }
  108. while (<INFILE>) {
  109. /^([^\s]+)\s+=\s+\w+:(\w+)/;
  110. push(@CDDataLines, lc($1) . " $2");
  111. }
  112. close(INFILE);
  113. }
  114. # Match lines in binplace.log to lines in cddata.txt.full.
  115. sub ParseFiles
  116. {
  117. my ($Line, $Datum, $MyName);
  118. my $ToFile = 0;
  119. # open the output file
  120. if ($OutputFile) {
  121. if (open(OUTFILE, ">$OutputFile")) {
  122. $ToFile = 1;
  123. } else {
  124. print "Failed to open output file, will print to stdout ...\n";
  125. }
  126. }
  127. foreach $Line (@BinplaceLines) {
  128. $Line =~ /.*\\(.+?)$/;
  129. $MyName = $1;
  130. foreach $Datum (@CDDataLines) {
  131. if ($Datum =~ /^$MyName/) {
  132. if ($ToFile) {
  133. print OUTFILE "$Line $Datum\n";
  134. } else {
  135. print "$Line $Datum\n";
  136. }
  137. }
  138. }
  139. }
  140. close(OUTFILE) if ($ToFile);
  141. }
  142. sub UsageAndQuit
  143. {
  144. print << " EOUAQ";
  145. $0 [-b:BinplaceFile] [-c:CDDataFile] [-o:OutputFile] [-m:TempDirectory]
  146. -b:BinplaceFile\tbinplace log to parse
  147. (default %_NTTREE%\\build_logs\\binplace.log)
  148. -c:CDDataFile\tcddata.txt file to parse\n");
  149. (default %_NTTREE%\\build_logs\\cddata.txt.full)
  150. -o:OutputFile\tfile to print to, otherwise stdout.
  151. -m:TempDirectory\tMove the input files to this directory before processing\.
  152. This tool will look at the combination of cddata.txt and binplace.log and
  153. output the source location built from, the binplace location under %_NTTREE%,
  154. and what products of CDs the file ends up on.
  155. EOUAQ
  156. exit(1);
  157. }