#! /usr/bin/perl
#
# clean up y2k-incompatible filenames
# 20000103fk

$VERSION = "Mon Jan  3 09:09:27 MET 2000";

($0) = ($0 =~ /\/?([^\/]+)$/);  # strip path...

require "getopts.pl";

&Getopts ("hC");

$opt_h && &Help;

$lastcentury = "19";          # what was forgotten
@files = ();

if ($#ARGV == -1) {           # no args given, read from STDIN
    while (<>) {
	chomp;
	if (/([.-])(9[0-9])(01|02|03|04|05|06|07|08|09|10|11|12)/) { 
	    $y2kfixed{$_} = $` . $1 . '19' . $2 . $3 . $';
	}
    }
}

foreach $file (keys(%y2kfixed)) {
    print "$file -> $y2kfixed{$file}\n";
}

exit 0 unless $opt_C;

print " doing the renaming - hold your breath...\n";
sleep 5;
foreach $file (keys(%y2kfixed)) {
    print "rename $file to $y2kfixed{$file}\n";
    system ("mv $file $y2kfixed{$file}");
}
print "done...\n";


sub Help {

    print <<"EOM";

$0
------------------------------------------------------------------------------
Fixes y2k-incompatible file names of the form 9[0-9]mm{dd}. Prints out fixed
names but renames the files only when started with -C option...

input: STDIN

output: list of fixes

options: -h     this help
         -C     make the proposed changes

version: $VERSION

EOM

  exit(0);
}
