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.

54 lines
1.5 KiB

  1. while ($_ = $ARGV[0], /^[-|\/]/) {
  2. shift;
  3. last if /^--$/;
  4. /^[-|\/]v:(.*)/i && ($variablelist = $1);
  5. /^[-|\/]f:(.*)/i && ($filename = $1);
  6. }
  7. ($variablelist && $filename) ||
  8. die "Usage: ChangeWiseVar.pl <-v:Variable=Value;Variable=Value;...> <-f:Filename>\n";
  9. foreach $variable (split (/;/, $variablelist)) {
  10. ($name, $value) = split (/=/, $variable);
  11. if ( $value eq "get_date()" ) {
  12. &get_date;
  13. $value = $date;
  14. }
  15. $VARS{$name} = $value;
  16. }
  17. if ( -f "$filename.bak" ) {
  18. system ("del /f $filename.bak");
  19. }
  20. rename ("$filename", "$filename.bak") ||
  21. die "Error renaming $filename to $filename.bak: $!.\n";
  22. open (INFILE, "<$filename.bak") || die "Error opening file $filename.bak: $!.\n";
  23. open (OUTFILE, ">$filename") || die "Error opening file $filename: $!.\n";
  24. print "\n$filename...\n";
  25. while (<INFILE>) {
  26. foreach $var (keys %VARS) {
  27. (/.*Variable Name(\d{1,2})=$var$/i) && ($varname = $var) && ($varnum = $1);
  28. }
  29. if ( $varnum ) {
  30. if ( s/(.*Variable Default$varnum=).*/$1$VARS{$varname}/ ) {
  31. print "Changed variable $varnum: $varname to \"$VARS{$varname}\"\n";
  32. $varnum = 0;
  33. }
  34. }
  35. print OUTFILE;
  36. }
  37. close INFILE, OUTFILE;
  38. chmod 0444, "$filename";
  39. exit 0;
  40. sub get_date {
  41. @months = ('January','February','March','April','May','June','July',
  42. 'August','September','October','November','December');
  43. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  44. $year = $year + 1900;
  45. $date = "$months[$mon] $mday, $year";
  46. }