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.

162 lines
4.0 KiB

  1. @rem = 'Perl from *.bat boilerplate
  2. @echo off
  3. goto endofperl
  4. ';
  5. $usage =<<end
  6. This script reports differences between source files. It assumes that the
  7. environment variable TEMP specifies the temporary file directory.
  8. Here are some example usages of this script:
  9. Compare the current checked-out "foo.h" with the latest version:
  10. sdiff foo.h
  11. Compare the current checked-out "foo.h" against version 17:
  12. sdiff foo.h 17
  13. Compare two different versions of a file (the following are equivalent):
  14. sdiff a/b/c/foo.h 17 18
  15. sdiff a/b/c/foo.h 17+
  16. sdiff a/b/c/foo.h 18-
  17. The following all compare version 10 against version 15 of file foo.cpp:
  18. sdiff foo.cpp 10 15
  19. sdiff foo.cpp 10+5
  20. sdiff foo.cpp 15-5
  21. This compares the last two versions of the file:
  22. sdiff foo.cpp -
  23. This command recursively executes the diff command on all files currently
  24. checked out:
  25. sdiff -r
  26. Note that you can also specify the diff utility to use via the DIFF environment
  27. variable. "windiff" is used if this variable is not defined.
  28. end
  29. ;
  30. # Get the temporary directory.
  31. $temp = $ENV{temp};
  32. $temp = $ENV{TEMP} if ($temp eq "");
  33. $temp = $ENV{tmp} if ($temp eq "");
  34. $temp = $ENV{TMP} if ($temp eq "");
  35. (($temp ne "") && (-d $temp)) || die "Environment variable TEMP is not set.\n";
  36. # Get the diff utility to use.
  37. $diff = $ENV{"diff"};
  38. $diff = $ENV{"DIFF"} if ($diff eq "");
  39. $diff = "start windiff" if ("$diff" eq "");
  40. if ($#ARGV == -1) {
  41. print "$usage";
  42. exit (1);
  43. } elsif ($#ARGV == 0) {
  44. if ($ARGV[0] eq '-r') {
  45. chop ($cwd = `cd`);
  46. $cwdlen = 1 + length($cwd);
  47. open (STDERR, ">&STDOUT") || die "Can't dup stdout.";
  48. open (OUTLIST, "status -rl |") || die "\"status -rl\" command failed.";
  49. while (<OUTLIST>) {
  50. chop $_;
  51. tr/\\/\//;
  52. # Get the path, base name, and version specifier.
  53. $file = substr ($_, $cwdlen);
  54. ($basename = $file) =~ s:.*/::;
  55. system ("catsrc $file >$temp\\$basename");
  56. system ("$diff $temp\\$basename $file");
  57. }
  58. close (OUTLIST);
  59. } else {
  60. # Get the path, base name, and version specifier.
  61. ($file = $ARGV[0]) =~ s:\\:/:g;
  62. ($basename = $file) =~ s:.*/::;
  63. system ("catsrc $file >$temp\\$basename");
  64. system ("$diff $temp\\$basename $file");
  65. }
  66. } else {
  67. # There are two command-line arguments, so we're doing a diff between two
  68. # different historical versions of a file.
  69. ($file = $ARGV[0]) =~ s:\\:/:g;
  70. $ver1 = $ARGV[1];
  71. $ver2 = $ARGV[2];
  72. ($targ = $file) =~ s:.*/::;
  73. $targ = "$temp\\$targ";
  74. # If we're checking a specific version against our current file, then do
  75. # a single fetch and compare, else get both versions and compare.
  76. if (!($ver1 =~ /^\d*[+-]\d*$/) && ($ver2 eq '')) {
  77. printf ("catsrc $file\@v$ver1 >${targ}_$ver1");
  78. printf ("$diff ${targ}_$ver1 $file");
  79. }
  80. else {
  81. # If version2 is nil, then we must have a version of the form
  82. # N1+[N2] or N1-[N2].
  83. if ($ver2 eq '') {
  84. if ($ver1 eq '-') {
  85. $_ = `log -1 -z $file`;
  86. ($xdate,$xuser,$xstat,$xpath,$ver2) = split ();
  87. $ver2 =~ s/v//;
  88. $ver1 = $ver2 - 1;
  89. } elsif ($ver1 =~ /[+-]$/) {
  90. $ver2 = eval ("$ver1" . "1");
  91. } else {
  92. $ver2 = eval ($ver1);
  93. }
  94. $ver1 =~ s/[+-].*$//;
  95. }
  96. if ($ver1 > $ver2) { # Ensure version1 < version2
  97. $temp = $ver1;
  98. $ver1 = $ver2;
  99. $ver2 = $temp;
  100. }
  101. system ("catsrc $file\@v$ver1 >${targ}_$ver1");
  102. system ("catsrc $file\@v$ver2 >${targ}_$ver2");
  103. system ("$diff ${targ}_$ver1 ${targ}_$ver2");
  104. }
  105. }
  106. __END__
  107. :endofperl
  108. perl -S %0.bat %1 %2 %3