#!/usr/bin/perl -w # fig2pdftex # by Aaron Rendahl # Mostly stolen shamelessly from # fig2ps : convert xfig files to ps processing text with LaTeX # Copyright (C) 2004-2006 Vincent Fourmond # Licensed under GPL my $path = $ENV{'PATH'}; my $force_special = 1; $ENV{'PATH'}="/sw/bin:".$path; if(@ARGV <=0) { die "You need to specify at least one fig file to work on"; } # we add a way to report errors my %results; MAINLOOP: foreach my $file (@ARGV) { $results{$file} = {}; print STDERR "Processing file $file\n"; # we use an alias to write the data: local *res = \$results{$file}; $res->{'file'} = $file; # failed by default $res->{'success'} = 0; if (! (-e $file)) { $res->{'error'} = "$file doesn't exist\n"; next MAINLOOP; } my $baseName = $file; $baseName =~ s/\.fig$//; my $fig_file=$file; my $figtmp=$baseName."-sp.fig"; my $tex_file=$baseName.".pdftex_t"; my $pdf_file=$baseName.".pdftex"; if($force_special) { $fig_file = $figtmp; if(my $err = make_special($file, $figtmp)) { $res->{'error'} = "Didn't manage to turn on special texts: $err"; next MAINLOOP; } } if(system "fig2dev -L pdftex '$fig_file' > '$pdf_file'") { $res->{'error'} = "Problems with fig2dev: command returned $?"; next MAINLOOP; } if(system "fig2dev -L pdftex_t -p '$pdf_file' '$fig_file' > '$tex_file'") { $res->{'error'} = "Problems with fig2dev: command returned $?"; next MAINLOOP; } $res->{'success'} = 1; } foreach (@ARGV) { my $res = $results{$_}; if($res->{'success'}) { print STDERR "Conversion succeded for file ". $res->{'file'} ."\n"; } else { print STDERR "Conversion failed for file ". $res->{'file'} .":\n\t". $res->{'error'}."\n"; } $baseName = $res->{'file'}; $baseName =~ s/\.fig$//; my $figtmp=$baseName."-sp.fig"; system( "rm -f $figtmp"); } sub make_special { my $input = shift @_ or return "Not enough args"; my $output = shift @_ or return "Not enough args"; open IN, $input or return "Failed to open $input"; open OUT, "> $output" or return "Failed to open $output"; while() { if (/^4 /) # if this is a text { my @data = split / +/; if ($data[8] & 2) # already in special { print OUT; } else { $data[8] ^= 2; print OUT join ' ', @data; } } else { print OUT; } } close IN; close OUT; return undef; }