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.

116 lines
3.2 KiB

  1. ###############################################################################
  2. # token.per
  3. #
  4. # Perl script for replacing a token in a text file.
  5. #
  6. # History:
  7. # 04/11/96 RossW Created.
  8. # 07/03/96 t-jackie Modified.
  9. #
  10. # Copyright(C) 1996. Microsoft Corporation. All rights reserved.
  11. ###############################################################################
  12. if($ARGV[0] eq "") { &PRINTUSAGE; exit; }
  13. %Tokens;
  14. # Handling the switches.
  15. while($ARGV[0] =~ /^-/)
  16. {
  17. $_ = shift;
  18. /^-(v)/i && (eval "\$$1 = 1", next);
  19. /^-t([^=]*)=([^\s]*)/i && (eval "\$Tokens{\$1} = \"\$2\"", next);
  20. die "Unrecognized switch: $_\n";
  21. }
  22. $x1 = sprintf "%4.4lx", $Tokens{TOK_BUILDNUM};
  23. $Tokens{TOK_BLDNUMSTR} = sprintf "%2s,%2s", substr($x1, 0, 2), substr($x1, 2, 2);
  24. if($ARGV[0] eq "") { &PRINTUSAGE; die "No input file given!"; }
  25. # Not a switch, must be the input file.
  26. $file = $ARGV[0];
  27. if($v) { print STDERR "\n"; }
  28. # Handling the environment variable for external builds.
  29. $BuildType = $ENV{'BUILDTYPE'};
  30. # Setting flag if BUILDTYPE environment variable is not set.
  31. if($BuildType eq "")
  32. {
  33. if($v) { print STDERR "BUILDTYPE environment variable not set!\n"; }
  34. }
  35. if($v) { print STDERR "Opening the input file: $file\n"; }
  36. open(INPUT, "<$file") || die "Could not open $file\n";
  37. if($v) { print STDERR "Replacing tokens.\n"; }
  38. $omit = 0;
  39. $linecount = 0;
  40. while(<INPUT>)
  41. {
  42. if($v)
  43. {
  44. if((++$linecount % 100) == 0)
  45. { print(STDERR "line: $linecount\n"); }
  46. }
  47. if($omit && !(/^\s*<\/BUILDTYPE>\s*$/)) { next; }
  48. foreach $key (sort keys(%Tokens))
  49. {
  50. s/$key/$Tokens{$key}/g;
  51. }
  52. if(/^\s*<BUILDTYPE=([^>]*)>\s*$/)
  53. {
  54. if($BuildType eq "") { $omit = 0; next; }
  55. $keep = 0;
  56. @Types = split(/,/, $1);
  57. foreach $type (@Types)
  58. {
  59. if("\U$BuildType\E" eq "\U$type\E") { $keep = 1; last; }
  60. }
  61. if(!$keep) { $omit = 1; }
  62. next;
  63. }
  64. elsif(/^\s*<\/BUILDTYPE>\s*$/)
  65. {
  66. $omit = 0;
  67. next;
  68. }
  69. print;
  70. }
  71. if($omit && $v) { print STDERR "No end of INTERNAL flag!\n"; }
  72. close(INPUT);
  73. if($v) { print STDERR "Done!\n"; }
  74. sub PRINTUSAGE
  75. {
  76. print STDERR "\ntoken.per v0.2 usage:\n";
  77. print STDERR "\nperl token.per [-v] [-tsymbol1=value1 .. -tsymbolX=valueX] <TextFile>\n\n";
  78. print STDERR " <TextFile> The file to replace tokens in.\n";
  79. print STDERR " -tsymbol=value Define a new symbol value.\n";
  80. print STDERR " -v verbose mode; default is quiet.\n";
  81. print STDERR "\nOutput goes to STDOUT, errors to STDERR.\n";
  82. print STDERR "\nInclusion of lines based on BUILDTYPE:\n";
  83. print STDERR "\t1. Set the environment variable BUILDTYPE.\n";
  84. print STDERR "\t2. In the input file put <BUILDTYPE=type1,type2,..typeN>\n";
  85. print STDERR "\t on the line before lines to be included\n";
  86. print STDERR "\t if BUILDTYPE == type1 | type2 | .. | typeN\n";
  87. print STDERR "\t3. In the input file put </BUILDTYPE> on the line after\n";
  88. print STDERR "\t the inclusion lines.\n";
  89. print STDERR "The BUILDTYPE lines in the input file will be removed by this program.\n\n";
  90. }