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.

163 lines
4.2 KiB

  1. #! /usr/bin/perl
  2. #
  3. # Create the copywowlist file given the result of wowlist filtering.
  4. # To be called from copywow64.cmd.
  5. #
  6. # sergueik - 03/07/01
  7. #
  8. # Perl CopyWowlist.pl <Input_DirectoryMappingFile> <Input_Filelist> <Output_Copywowlist>
  9. #
  10. #
  11. my $self = $0;
  12. $self =~ s/^.*\\([^\\]*)$/$1/g;
  13. my $pos = -1;
  14. my %mapping = ();
  15. my $section;
  16. if ( $ENV{ "_BuildArch" } =~ /amd64/i ) {
  17. $section = q(\[SourceDisksNames\.amd64\]);
  18. } else {
  19. $section = q(\[SourceDisksNames\.ia64\]);
  20. }
  21. my $DEBUG = 0;
  22. &usage and exit 0 if grep /[\/\-][\h?]/, @ARGV;
  23. my $status = &VerifyCommandLine(
  24. {"argv"=>\@ARGV,
  25. "argc"=>3,
  26. 0 => "-e \"FILE\"",
  27. 1 => "-e \"FILE\""});
  28. $status and die "$self: wrong call";
  29. my $Input_DirectoryMappingFile = $ARGV[0];
  30. my $Input_Filelist = $ARGV[1];
  31. my $Output_Copywowlist = $ARGV[2];
  32. open (HINT, $Input_DirectoryMappingFile) or die "cannot read Input_DirectoryMappingFile $Input_DirectoryMappingFile: $!";
  33. {
  34. my $mapping = 0;
  35. my @mapping = ();
  36. my @mappingpart = ();
  37. # Put in the @mapping array all entries from the [SourceDisksNames] section.
  38. while (<HINT>){
  39. chomp;
  40. do{
  41. $mapping = 1; @mappingpart = ();
  42. }if /^$section/;
  43. do{
  44. push @mapping, @mappingpart;
  45. $mapping = 0;
  46. }if $mapping && scalar (@mappingpart) && $_!~/\S/;
  47. push @mappingpart, $_ if $mapping && /=/;
  48. }
  49. # The keys in the %mapping hash are the directory numbers
  50. # and the relative path is the value.
  51. %mapping = map {split /\s*=\s*/, $_} @mapping;
  52. foreach (keys (%mapping)){
  53. my $data = $mapping{$_};
  54. $mapping{$_}=[split(/\s*,\s*/,$data)];
  55. }
  56. foreach (keys (%mapping)){
  57. my $data = $mapping{$_}->[$pos];
  58. $data =~ s/^\\[^\\]+(\\)?//;
  59. $mapping{$_}->[$pos]=$data;
  60. }
  61. map { $mapping{$_} = $mapping{$_}->[$pos]} keys (%mapping);
  62. print STDERR join( "\n",
  63. map
  64. {"\"".$_."\"\t=>\t\"".$mapping{$_}."\""}
  65. keys (%mapping)),
  66. "\n" if $DEBUG;
  67. }
  68. close(HINT);
  69. my @data=();
  70. my $pos2 = 0;
  71. # Read the filenames and their directories from the second argument.
  72. open (UNFIXED, $Input_Filelist) or die "cannot read Input_Filelist $Input_Filelist : $!";
  73. do {push @data, $_ unless ($_!~/\S/); }while(<UNFIXED>);
  74. close(UNFIXED);
  75. print STDERR "$#data\n" if $DEBUG;
  76. foreach $row (0..$#data){
  77. my $line = $data[$row];
  78. chomp $line;
  79. my ($file, $rest) = split(/\s*=\s*/, $line);
  80. my @rest = split (/,/, $rest);
  81. my $index = $rest[$pos2];
  82. my $path = $mapping{$index};
  83. $file = join ("\\", $path, $file) if $path;
  84. $data[$row] = $file;
  85. }
  86. # Write the output
  87. open (FIXED, ">".$Output_Copywowlist) or die "canot write to Output_Copywowlist $Output_Copywowlist: $!";
  88. select FIXED;
  89. $|=1;
  90. map {print "$_\n"} @data;
  91. select STDOUT;
  92. close(FIXED);
  93. sub VerifyCommandLine{
  94. my $messages = {"-e \"FILE\"" => "file \"FILE\" does not exist\n",
  95. "!-e \"FILE\"" => "cannot clobber existing file: \"FILE\"\n" };
  96. my $named = shift;
  97. my %named = %$named;
  98. my $argv = $named->{"argv"};
  99. my $argc = $named->{"argc"};
  100. my $result = 0;
  101. $result = 1 if scalar(@$argv) != $argc;
  102. if ($result ){
  103. print STDERR "$self: wrong number of args\n";
  104. } else{
  105. foreach $one (keys(%named)){
  106. if ($one !~ /\D/){
  107. $test = $named->{$one};
  108. $test =~ s/FILE/$argv->[$one]/g;
  109. $test =~ s/\\/\//g;
  110. do { my $message = $messages->{$named->{$one}};
  111. $message =~ s/FILE/$argv->[$one]/g;
  112. print STDERR "$self: $message";
  113. $result = 1;
  114. last;} if (!eval($test));
  115. }
  116. }
  117. }
  118. $result;
  119. }
  120. sub usage{
  121. print <<USAGE;
  122. Usage:
  123. perl $self <MappingFile> <Input> <Output>
  124. Create the copywowlist file given the result of wowlist filtering.
  125. To be called from copywow64.cmd.
  126. USAGE
  127. }