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.

149 lines
3.7 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM mergetables.cmd - jtolman
  5. REM Combines old and new inf data tables to create a table based
  6. REM on the current build.
  7. REM
  8. REM Copyright (c) Microsoft Corporation. All rights reserved.
  9. REM
  10. REM ------------------------------------------------------------------
  11. perl -x "%~f0" %*
  12. goto :EOF
  13. #!perl
  14. use strict;
  15. use lib $ENV{RAZZLETOOLPATH} . "\\postbuildscripts";
  16. use lib $ENV{RAZZLETOOLPATH} . "\\sp";
  17. use lib $ENV{RAZZLETOOLPATH};
  18. use PbuildEnv;
  19. use ParseArgs;
  20. use Logmsg;
  21. use InfData;
  22. sub Usage { print<<USAGE; exit(1) }
  23. mergetables <old_table> <new_table> <diff_table> <out_table> <out_diff_table>
  24. <old_table> "Original" table, taken from a main build or from
  25. a previous run of this script.
  26. <new_table> New table, taken from an sp of the build for old_table.
  27. <diff_table> infdiff.tbl that goes with old_table.
  28. <out_table> Location to write the generated table to.
  29. <out_diff_table> Location to write the generated diff table to.
  30. Creates an inf data table by combining data from an old build with
  31. data from a service pack.
  32. USAGE
  33. my ($old, $new, $diff, $out, $out_diff);
  34. parseargs('?' => \&Usage,
  35. \$old,
  36. \$new,
  37. \$diff,
  38. \$out,
  39. \$out_diff);
  40. my @skuletters = ("p", "c");
  41. # Parse a database file.
  42. sub readDB {
  43. my ($file) = @_;
  44. my %db = ();
  45. if ( !open (DBFILE, $file) ) {
  46. errmsg( "Unable to read $file: $!" );
  47. exit 1;
  48. }
  49. foreach ( <DBFILE> ) {
  50. chomp;
  51. my $line = InfData->new();
  52. if ( !$line->readLine($_, \@skuletters) ) {
  53. wrnmsg( "Unrecognized DB-file entry: $_" );
  54. next;
  55. }
  56. my $dir = $line->getSrcDir();
  57. my $key = $line->getSrc();
  58. $db{$key} = [ () ] if !exists $db{$key};
  59. push @{ $db{$key} }, $line;
  60. }
  61. close DBFILE;
  62. return %db;
  63. }
  64. # Add a database into another.
  65. sub addDB {
  66. my ($src, $dst) = @_;
  67. foreach my $file (keys %$src) {
  68. my $list1 = $src->{$file};
  69. my $list2 = $dst->{$file};
  70. $list2 = [ () ] if !defined $list2;
  71. foreach my $entry ( @$list1 ) {
  72. my $test = undef;
  73. foreach my $ent ( @$list2 ) {
  74. $test = $ent->addBit($entry);
  75. last if $test;
  76. }
  77. push @$list2, $entry if !$test;
  78. }
  79. $dst->{$file} = $list2;
  80. }
  81. }
  82. # Subtract a database from another.
  83. sub subDB {
  84. my ($src, $dst) = @_;
  85. foreach my $file (keys %$dst) {
  86. my $list1 = $src->{$file};
  87. my $list2 = $dst->{$file};
  88. $list1 = [ () ] if !defined $list1;
  89. foreach my $entry ( @$list1 ) {
  90. my @temp = ();
  91. foreach my $ent ( @$list2 ) {
  92. my $newent = $ent->delBit2($entry);
  93. push @temp, $newent if defined $newent;
  94. }
  95. $list2 = \@temp;
  96. }
  97. $dst->{$file} = $list2;
  98. delete $dst->{$file} if $#$list2 < 0;
  99. }
  100. }
  101. # Print out a database to a file.
  102. sub printDB {
  103. my ($db, $out) = @_;
  104. if ( !open OUT, ">$out" ) {
  105. errmsg "Unable to open $out: $!";
  106. die;
  107. }
  108. foreach my $file (sort keys %$db) {
  109. foreach my $entry ( @{ $db->{$file} } ) {
  110. print OUT $entry->getLine(\@skuletters);
  111. print OUT "\n";
  112. }
  113. }
  114. close OUT;
  115. }
  116. # Read in the database files.
  117. my (%old, %new, %diff);
  118. %diff = ();
  119. %old = readDB($old);
  120. %new = readDB($new);
  121. %diff= readDB($diff) if -f $diff;
  122. # Add the stuff from old to diff.
  123. subDB(\%new, \%old);
  124. addDB(\%old, \%diff);
  125. %old = readDB($old);
  126. # Add the stuff from new to diff.
  127. subDB(\%old, \%new);
  128. addDB(\%new, \%diff);
  129. # Construct the new minimal table.
  130. subDB(\%diff, \%old);
  131. # Output the tables.
  132. printDB(\%old, $out);
  133. printDB(\%diff, $out_diff);