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.

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