summaryrefslogtreecommitdiff
path: root/win32/sync_ext.pl
diff options
context:
space:
mode:
authorVadim Konovalov <vkonovalov@lucent.com>2001-07-23 14:56:54 +0200
committerJarkko Hietaniemi <jhi@iki.fi>2001-07-23 21:06:42 +0000
commit02b1e60408c5543387fd5ef57f131e9ef0480a95 (patch)
treeb7fdb5c6e984e7c8c2a6e6ebfbad5795792dbdb9 /win32/sync_ext.pl
parentad8fe22763798a32af6a3ef0934bfb712ab5a7e1 (diff)
downloadperl-02b1e60408c5543387fd5ef57f131e9ef0480a95.tar.gz
win32\sncfnmcs.pl corrections
From: "Konovalov, Vadim Vladimirovich (Vadim)" <vkonovalov@lucent.com> Message-ID: <E3FB32585BF1D411B9E900805FF51A080C1C5D@RU0022EXCH001U> Rename the script a little bit more sensibly. p4raw-id: //depot/perl@11453
Diffstat (limited to 'win32/sync_ext.pl')
-rw-r--r--win32/sync_ext.pl64
1 files changed, 64 insertions, 0 deletions
diff --git a/win32/sync_ext.pl b/win32/sync_ext.pl
new file mode 100644
index 0000000000..e482b69838
--- /dev/null
+++ b/win32/sync_ext.pl
@@ -0,0 +1,64 @@
+=comment
+
+Synchronize filename cases for extensions.
+
+This script takes two arguments - first and second extensions to
+synchronize filename cases with.
+
+There may be specified following options:
+ --verbose <== say everything what is going on
+ --recurse <== recurse subdirectories
+ --dummy <== do not perform actual renaming
+ --say-subdir
+Every such option can be specified with an optional "no" prefix to negate it.
+
+Typically, it is invoked as:
+ perl sync_ext.pl c obj --verbose
+
+=cut
+
+use strict;
+
+my ($ext1, $ext2) = map {quotemeta} grep {!/^--/} @ARGV;
+my %opts = (
+ #defaults
+ 'verbose' => 0,
+ 'recurse' => 1,
+ 'dummy' => 0,
+ 'say-subdir' => 0,
+ #options itself
+ (map {/^--([\-_\w]+)=(.*)$/} @ARGV), # --opt=smth
+ (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV), # --opt --no-opt --noopt
+ );
+
+my $sp = '';
+sub xx {
+ opendir DIR, '.';
+ my @t = readdir DIR;
+ my @f = map {/^(.*)\.$ext1$/i} @t;
+ my %f = map {lc($_)=>$_} map {/^(.*)\.$ext2$/i} @t;
+ for (@f) {
+ my $lc = lc($_);
+ if (exists $f{$lc} and $f{$lc} ne $_) {
+ print STDERR "$sp$f{$lc}.$ext2 <==> $_.$ext1\n" if $opts{verbose};
+ if ($opts{dummy}) {
+ print STDERR "ren $f{$lc}.$ext2 $_.$ext2\n";
+ }
+ else {
+ system "ren $f{$lc}.$ext2 $_.$ext2";
+ }
+ }
+ }
+ if ($opts{recurse}) {
+ for (grep {-d&&!/^\.\.?$/} @t) {
+ print STDERR "$sp\\$_\n" if $opts{'say-subdir'};
+ $sp .= ' ';
+ chdir $_ or die;
+ xx();
+ chdir ".." or die;
+ chop $sp;
+ }
+ }
+}
+
+xx();