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.

213 lines
3.7 KiB

  1. package ExtUtils::Command;
  2. use 5.005_64;
  3. use strict;
  4. # use AutoLoader;
  5. use Carp;
  6. use File::Copy;
  7. use File::Compare;
  8. use File::Basename;
  9. use File::Path qw(rmtree);
  10. require Exporter;
  11. our(@ISA, @EXPORT, $VERSION);
  12. @ISA = qw(Exporter);
  13. @EXPORT = qw(cp rm_f rm_rf mv cat eqtime mkpath touch test_f);
  14. $VERSION = '1.01';
  15. =head1 NAME
  16. ExtUtils::Command - utilities to replace common UNIX commands in Makefiles etc.
  17. =head1 SYNOPSIS
  18. perl -MExtUtils::Command -e cat files... > destination
  19. perl -MExtUtils::Command -e mv source... destination
  20. perl -MExtUtils::Command -e cp source... destination
  21. perl -MExtUtils::Command -e touch files...
  22. perl -MExtUtils::Command -e rm_f file...
  23. perl -MExtUtils::Command -e rm_rf directories...
  24. perl -MExtUtils::Command -e mkpath directories...
  25. perl -MExtUtils::Command -e eqtime source destination
  26. perl -MExtUtils::Command -e chmod mode files...
  27. perl -MExtUtils::Command -e test_f file
  28. =head1 DESCRIPTION
  29. The module is used in the Win32 port to replace common UNIX commands.
  30. Most commands are wrappers on generic modules File::Path and File::Basename.
  31. =over 4
  32. =cut
  33. sub expand_wildcards
  34. {
  35. @ARGV = map(/[\*\?]/ ? glob($_) : $_,@ARGV);
  36. }
  37. =item cat
  38. Concatenates all files mentioned on command line to STDOUT.
  39. =cut
  40. sub cat ()
  41. {
  42. expand_wildcards();
  43. print while (<>);
  44. }
  45. =item eqtime src dst
  46. Sets modified time of dst to that of src
  47. =cut
  48. sub eqtime
  49. {
  50. my ($src,$dst) = @ARGV;
  51. open(F,">$dst");
  52. close(F);
  53. utime((stat($src))[8,9],$dst);
  54. }
  55. =item rm_f files....
  56. Removes directories - recursively (even if readonly)
  57. =cut
  58. sub rm_rf
  59. {
  60. rmtree([grep -e $_,expand_wildcards()],0,0);
  61. }
  62. =item rm_f files....
  63. Removes files (even if readonly)
  64. =cut
  65. sub rm_f
  66. {
  67. foreach (expand_wildcards())
  68. {
  69. next unless -f $_;
  70. next if unlink($_);
  71. chmod(0777,$_);
  72. next if unlink($_);
  73. carp "Cannot delete $_:$!";
  74. }
  75. }
  76. =item touch files ...
  77. Makes files exist, with current timestamp
  78. =cut
  79. sub touch
  80. {
  81. expand_wildcards();
  82. my $t = time;
  83. while (@ARGV)
  84. {
  85. my $file = shift(@ARGV);
  86. open(FILE,">>$file") || die "Cannot write $file:$!";
  87. close(FILE);
  88. utime($t,$t,$file);
  89. }
  90. }
  91. =item mv source... destination
  92. Moves source to destination.
  93. Multiple sources are allowed if destination is an existing directory.
  94. =cut
  95. sub mv
  96. {
  97. my $dst = pop(@ARGV);
  98. expand_wildcards();
  99. croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
  100. while (@ARGV)
  101. {
  102. my $src = shift(@ARGV);
  103. move($src,$dst);
  104. }
  105. }
  106. =item cp source... destination
  107. Copies source to destination.
  108. Multiple sources are allowed if destination is an existing directory.
  109. =cut
  110. sub cp
  111. {
  112. my $dst = pop(@ARGV);
  113. expand_wildcards();
  114. croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
  115. while (@ARGV)
  116. {
  117. my $src = shift(@ARGV);
  118. copy($src,$dst);
  119. }
  120. }
  121. =item chmod mode files...
  122. Sets UNIX like permissions 'mode' on all the files.
  123. =cut
  124. sub chmod
  125. {
  126. my $mode = shift(@ARGV);
  127. chmod($mode,expand_wildcards()) || die "Cannot chmod ".join(' ',$mode,@ARGV).":$!";
  128. }
  129. =item mkpath directory...
  130. Creates directory, including any parent directories.
  131. =cut
  132. sub mkpath
  133. {
  134. File::Path::mkpath([expand_wildcards()],0,0777);
  135. }
  136. =item test_f file
  137. Tests if a file exists
  138. =cut
  139. sub test_f
  140. {
  141. exit !-f shift(@ARGV);
  142. }
  143. 1;
  144. __END__
  145. =back
  146. =head1 BUGS
  147. Should probably be Auto/Self loaded.
  148. =head1 SEE ALSO
  149. ExtUtils::MakeMaker, ExtUtils::MM_Unix, ExtUtils::MM_Win32
  150. =head1 AUTHOR
  151. Nick Ing-Simmons <F<[email protected]>>.
  152. =cut