2003-07-25 05:52:58 -05:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use File::Find ();
|
|
|
|
use File::Basename ();
|
|
|
|
use File::Path ();
|
|
|
|
use Getopt::Std;
|
|
|
|
use Cwd;
|
|
|
|
|
|
|
|
my ($startdir,$outdir,$pfx);
|
2005-01-21 02:47:39 -06:00
|
|
|
my $verbose = 0;
|
2003-07-25 05:52:58 -05:00
|
|
|
|
|
|
|
sub usage() {
|
|
|
|
print STDERR "usage: $0 -o <outdir> [-f <file>]\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
$startdir=cwd();
|
|
|
|
|
|
|
|
# for the convenience of &wanted calls, including -eval statements:
|
|
|
|
use vars qw/*name *dir *prune/;
|
|
|
|
*name = *File::Find::name;
|
|
|
|
*dir = *File::Find::dir;
|
|
|
|
*prune = *File::Find::prune;
|
|
|
|
|
|
|
|
if ( !getopts('o:f:') ) {
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( defined($Getopt::Std::opt_o) ) {
|
|
|
|
$outdir=$Getopt::Std::opt_o;
|
|
|
|
$outdir=~s%\\%/%g;
|
|
|
|
} else {
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( defined($Getopt::Std::opt_f) ) {
|
|
|
|
convertfile($outdir,$Getopt::Std::opt_f);
|
|
|
|
} else {
|
|
|
|
# Traverse desired filesystems
|
|
|
|
$pfx="source";
|
|
|
|
File::Find::find({wanted => \&wanted}, 'source');
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
|
|
sub wanted {
|
|
|
|
my ($dev,$ino,$mode,$nlink,$uid,$gid);
|
|
|
|
|
|
|
|
(
|
|
|
|
/^.*\.html\z/s
|
|
|
|
||
|
2005-01-21 02:47:39 -06:00
|
|
|
/^license.*\.txt\z/s
|
2003-07-25 05:52:58 -05:00
|
|
|
||
|
2005-01-21 02:47:39 -06:00
|
|
|
/^LICENSE.*\z/s
|
2003-07-25 05:52:58 -05:00
|
|
|
||
|
|
|
|
/^readme\.txt\z/s
|
|
|
|
||
|
|
|
|
/^README\z/s
|
|
|
|
) &&
|
|
|
|
($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
|
|
|
|
eval {&doconv};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub doconv {
|
|
|
|
my($dest);
|
|
|
|
$dest=$dir;
|
|
|
|
$dest=~s/^$pfx//g;
|
|
|
|
$dest=$outdir.$dest;
|
2005-01-21 02:47:39 -06:00
|
|
|
convertfile($dest,$name) if $name =~ /\/$ENV{GUI}\//i;
|
2003-07-25 05:52:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub convertfile {
|
|
|
|
my ($dest,$file,$destfile);
|
|
|
|
$dest=shift;
|
|
|
|
$file=shift;
|
|
|
|
$dest=~s%^./%%g;
|
|
|
|
$dest=$startdir . "/" . $dest;
|
|
|
|
$file=$startdir . "/" . $file;
|
|
|
|
|
|
|
|
$destfile=$dest . "/" . File::Basename::basename($file);
|
|
|
|
|
2003-08-21 03:21:21 -05:00
|
|
|
File::Path::mkpath($dest,0,0775);
|
2003-07-25 05:52:58 -05:00
|
|
|
|
|
|
|
open(IN,"<$file") || die "can not open $file";
|
|
|
|
open(OUT,">$destfile") || die "can not open $destfile";
|
2005-01-21 02:47:39 -06:00
|
|
|
print "converting: $file -> $destfile\n" if $verbose;
|
2003-07-25 05:52:58 -05:00
|
|
|
while (<IN> ) {
|
|
|
|
chop while ( /\n$/ || /\r$/ );
|
|
|
|
print OUT "$_\n";
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
close(OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|