5
  7   ˆl–Ðz¾”d
eJeA
ãa¸ÓŠbÑ¿�þ[r¬Ü¬¼È%i°4ð?ŸÔ„u¿ÓÒÑ ?÷     #!/usr/bin/perl -w

######################################################################
#
# fragmaster.pl
#
# creates EPS and PDF graphics from source EPS and control files
# with \psfrag commands
#
# Version: 1.7
#
# Copyright (C) 2004 Tilman Vogel <tilman vogel web de> (dot at dot)
# Copyright (C) 2011-2015 Agustin Martin <agustin6martin gmail com> (at dot)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# See pod section at the end of this script for more information
# ----------------------------------------------------------------------------

use strict;
use Cwd;
use File::Temp qw(tempdir);
use Pod::Usage;

my $clean;
my $debug;
my $force;
my $global_dirfm_mtime;
my $global_dirfm_file   = "fragmaster.dfm";
my $fragmaster_status   = "fragmaster.sts";
my $global_fmclass      = "article";
my $global_fmclassopt   = "12pt";
my $global_fmopt        = "";
my @global_fmhead       = ();
my @global_fmfile       = ();
my %dirdata_last_status = ();


foreach my $option ( @ARGV ){
  if ( $option eq "--force" ){
    $force++;
  } elsif ( $option eq "--clean" ){
    print STDERR "Clean auto-generated \$basename.{eps,pdf} files\n";
    $clean++;
  } elsif ( $option eq "--debug" ){
    print STDERR "Debug enabled\n";
    $debug++;
  } elsif ( $option =~ s/^--dirfm(=|\#)// ) {
    if ( -e $option ){
      $global_dirfm_file = $option;
      print STDERR "fragmaster: using \"$global_dirfm_file\" directory control file.\n"
	if $debug;
    } else {
      die "fragmaster: Could not find given \"$option\" directory control file. Aborting ....\n";
    }
  } elsif ( $option eq "-h" || $option eq "--help" ) {
    pod2usage(1);
    exit 1;
  } elsif ( $option eq "-m" || $option eq "--man" ) {
    pod2usage(-exitstatus => 0, -verbose => 2);
    exit 1;
  } else {
    print STDERR "\nfragmaster: Unsupported option \"$option\"\n\n";
    pod2usage(1);
    exit 1;
  }
}

# Function definitions

# ----------------------------------------------------------------------------
sub win32_which {
# ----------------------------------------------------------------------------
# Look if given basename matches a win32 executable under $PATH
# ----------------------------------------------------------------------------
  my $basename   = shift;
  my @extensions = (".exe");

  foreach my $path ( '.', split(';',$ENV{'PATH'}) ){
    foreach my $ext ( @extensions ){
      my $exec_location = "$path\\$basename$ext";
      if ( -x "$exec_location" ){
	print STDERR "fragmaster: Found gs executable at \"$exec_location\"\n"
	  if $debug;
	return $basename;
      } else {
	print STDERR "fragmaster: No gs executable found at \"$exec_location\"\n"
	  if $debug;
      }
    }
  }
}

# ----------------------------------------------------------------------------
sub parse_fmfile {
# ----------------------------------------------------------------------------
  my $file   = shift;
  my %fmdata = ();
  my @fmfile = ();      # A copy of original file
  my @fmhead = ();      # Preamble to use
  my $fmopt;            # Options to \includegraphics
  my $fmclass;          # Class to use
  my $fmclassopt;       # Options for class invocation

  die "fragmaster::parse_fmfile: No file to parse passed as argument. Aborting ...\n"
    unless $file;

  open FMFILE, "<$file"
    or die "fragmaster: Cannot read \"$file\"!. Aborting ...\n";

  while (<FMFILE>) {
  