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.

65 lines
1.4 KiB

  1. use strict;
  2. sub Usage { print<<USAGE; exit(1) }
  3. Usage: makeinftable <out_file> <inx_file> <lang_file>
  4. <out_file> File to save the table in.
  5. <inx_file> Inx file to generate the table from.
  6. <lang_file> Language file used for localization.
  7. USAGE
  8. my ($out, $inx, $lang) = @ARGV;
  9. Usage() if $out eq "/?";
  10. # Parse the language file.
  11. my %defs;
  12. if ( !open LANG, $lang ) {
  13. print "Unable to open language file: $lang\n";
  14. die;
  15. }
  16. while ( <LANG> ) {
  17. s/\s*$//;
  18. next if /^$/;
  19. if ( !/=/ ) {
  20. print "WARNING: Line skipped: $_\n";
  21. next;
  22. }
  23. my ($key, $value) = split(/\s*=\s*/, $_, 2);
  24. $defs{$key} = [ () ] if !exists $defs{$key};
  25. push @{ $defs{$key} }, $value;
  26. }
  27. close LANG;
  28. # Do language based substitution in the file.
  29. if ( !open INX, $inx ) {
  30. print "Unable to open inx file: $inx\n";
  31. die;
  32. }
  33. if ( !open OUT, ">$out" ) {
  34. print "Unable to open temp file: $out\n";
  35. die;
  36. }
  37. while( <INX> ) {
  38. next if /^\s*$/;
  39. my @lines = ($_);
  40. while ( /%([^%]*)%/ ) {
  41. my $key = $1;
  42. my @old = @lines;
  43. @lines = ();
  44. foreach my $val ( @{ $defs{$key} } ) {
  45. foreach my $line ( @old ) {
  46. my $temp = $line;
  47. $temp =~ s/\%\Q$key\E\%/$val/g;
  48. push @lines, $temp;
  49. }
  50. }
  51. s/\%\Q$key\E\%//g;
  52. }
  53. foreach my $line ( @lines ) {
  54. print OUT $line;
  55. }
  56. }
  57. close OUT;
  58. close INX;