upgrade master to m38
[ooovba.git] / readlicense_oo / conv.pl
blobdd1fe5076317bb0698bd13927597eba14bc31fdd
1 #!/usr/bin/perl
3 use strict;
4 use File::Find ();
5 use File::Basename ();
6 use File::Path ();
7 use Getopt::Std;
8 use Cwd;
10 my ($startdir,$outdir,$pfx);
11 my $verbose = 0;
13 sub usage() {
14 print STDERR "usage: $0 -o <outdir> [-f <file>]\n"
17 $startdir=cwd();
19 # for the convenience of &wanted calls, including -eval statements:
20 use vars qw/*name *dir *prune/;
21 *name = *File::Find::name;
22 *dir = *File::Find::dir;
23 *prune = *File::Find::prune;
25 if ( !getopts('o:f:') ) {
26 usage();
27 exit(1);
30 if ( defined($Getopt::Std::opt_o) ) {
31 $outdir=$Getopt::Std::opt_o;
32 $outdir=~s%\\%/%g;
33 } else {
34 usage();
35 exit(1);
38 if ( defined($Getopt::Std::opt_f) ) {
39 convertfile($outdir,$Getopt::Std::opt_f);
40 } else {
41 # Traverse desired filesystems
42 $pfx="source";
43 File::Find::find({wanted => \&wanted}, 'source');
45 exit;
48 sub wanted {
49 my ($dev,$ino,$mode,$nlink,$uid,$gid);
52 /^.*\.html\z/s
54 /^license.*\.txt\z/s
56 /^LICENSE.*\z/s
58 /^readme\.txt\z/s
60 /^README\z/s
61 ) &&
62 ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
63 eval {&doconv};
66 sub doconv {
67 my($dest);
68 $dest=$dir;
69 $dest=~s/^$pfx//g;
70 $dest=$outdir.$dest;
71 convertfile($dest,$name) if $name =~ /\/$ENV{GUI}\//i;
74 sub convertfile {
75 my ($dest,$file,$destfile);
76 $dest=shift;
77 $file=shift;
78 $dest=~s%^./%%g;
79 $dest=$startdir . "/" . $dest;
80 $file=$startdir . "/" . $file;
82 $destfile=$dest . "/" . File::Basename::basename($file);
84 File::Path::mkpath($dest,0,0775);
86 open(IN,"<$file") || die "can not open $file";
87 open(OUT,">$destfile") || die "can not open $destfile";
88 print "converting: $file -> $destfile\n" if $verbose;
89 while (<IN> ) {
90 chop while ( /\n$/ || /\r$/ );
91 print OUT "$_\n";
93 close(IN);
94 close(OUT);