13 getopts('vnsj:f:o:i:', \%opts);
17 # output is a directory
20 # output is a single file, imply -i <ext> unless -i has also been specified
21 if ($opts{o} =~ /\.(\w+)$/) {
22 $opts{i} = $1 unless exists $opts{i};
24 print "Specified -o <file>, but '$opts{o}' has no extension.\n";
29 print "Using $opts{j} processors\n" if $opts{v};
31 my $var_re = qr/[A-Za-z_][A-Za-z0-9_]*/;
34 my ($base, $iext, $oext) = @_;
35 my $cmd = $rules{$oext}{$iext};
36 my $infile = "$base.$iext";
38 $cmd =~ s!\$\<!"$infile"!g;
42 # Strip leading path from base so we can stick the file in
44 $base = basename($base);
45 $outfile = "$opts{o}/$base.$oext";
50 $outfile = "$base.$oext";
52 $outfile =~ s/"/\\"/g;
53 $cmd =~ s!\$\@!"$outfile"!g;
65 s/\$($var_re)/(exists $vars{$1} ? $vars{$1} : '$' . $1)/eg;
69 open CONF, ($opts{f} || 'Convfile') or die "Could not open Convfile";
76 if (/^([\w.]+)\s*=>\s*([\w.]+)\s*:\s*(.*)$/) {
78 } elsif (/^($var_re)\s*=\s*(.*)$/) {
79 $vars{$1} = expand($2);
81 warn "Error in Convfile line $.: $_\n";
89 # If we specify reading from stdin, do this.
90 if (exists $opts{s}) {
101 # Reversed semantics. Files are input to be converted to the specified extension
103 unless (exists $rules{$opts{i}}) {
105 You have specified -i <ext>, but the Convfile has no rule to convert to
112 print "$_ does not exist.\n";
116 if (/^(.+)\.(\w+)$/) {
119 print "Considering $base.$iext\n" if $opts{v};
120 if (exists $rules{$opts{i}}{$iext}) {
121 print "Using $base.$iext\n" if $opts{v};
122 push @queue, [$base, $iext, $opts{i}];
125 print "I don't see an extension on $_, so I don't know what to do with it.\n";
130 # Make semantics, files specified are desired output files
132 # Do something fun (convert *.foo into a list of files that would match if they existed)
138 map { s/\.(\w+)$/\.$extsub/; $_ }
147 # I like to call this the TOWER OF POWER
148 for my $ofile (@files) {
150 for my $oext (keys %rules) {
152 $oext_re =~ s/\./\\./g;
153 if ($ofile =~ /^(.*)\.$oext_re$/) {
156 for my $iext (keys %{$rules{$oext}}) {
157 print "Considering $base.$iext\n" if $opts{v};
158 if (-e "$base.$iext") {
159 print "Using $base.$iext\n" if $opts{v};
160 push @queue, [$base, $iext, $oext];
166 print "No suitable input file found for $ofile\n";
173 print "No rule to make $ofile\n";
178 print scalar @queue, " items to process\n" if $opts{v};
181 foreach my $chunk (@queue) {
184 if ($procs == $opts{j}) {
191 # vim:ts=4 sts=4 sw=4 expandtab