| 1 |
#! /usr/bin/perl -w |
| 2 |
# |
| 3 |
# Program for inserting EPS files into MetaPost output files. Requires |
| 4 |
# the extpeps module for MetaPost -- and it is probably not even |
| 5 |
# necessary to run this program |
| 6 |
# |
| 7 |
# Copyright (C) 2005 Palle Jorgensen <[email protected]> |
| 8 |
# http://pallej.dk/exteps/ |
| 9 |
# http://pallej.dk/ |
| 10 |
# |
| 11 |
# This program is free software; you can redistribute it and/or modify |
| 12 |
# it under the terms of the GNU General Public License as published by |
| 13 |
# the Free Software Foundation; either version 2 of the License, or |
| 14 |
# (at your option) any later version. |
| 15 |
# |
| 16 |
# This program is distributed in the hope that it will be useful, but |
| 17 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 |
# General Public License for more details. |
| 20 |
# |
| 21 |
# You should have received a copy of the GNU General Public License |
| 22 |
# along with this program; if not, write to the Free Software |
| 23 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 24 |
# 02111-1307, USA. |
| 25 |
# |
| 26 |
# Bugs and comments can be reported to Palle Jorgensen, |
| 27 |
# <[email protected]>. |
| 28 |
# |
| 29 |
# This is version 0.12 Mon Dec 26 2005 |
| 30 |
|
| 31 |
use strict; |
| 32 |
our($opt_h,$opt_q,$opt_v,$opt_V,$opt_i); |
| 33 |
|
| 34 |
use Getopt::Std; |
| 35 |
getopts('-helpvqVi'); |
| 36 |
|
| 37 |
use Env qw(HOME); |
| 38 |
|
| 39 |
my $progversion = 0.12; |
| 40 |
my $progname = "delfin"; |
| 41 |
my $prognamelong = "Delfin, the Exteps Large File INserter"; |
| 42 |
if ($opt_h) { version(); help(); exit; } |
| 43 |
if ($opt_v) { version(); exit; } |
| 44 |
if ($opt_V) { versionbrief(); exit; } |
| 45 |
|
| 46 |
unless ( $opt_q ) { |
| 47 |
print "This is $progname version $progversion\n"; |
| 48 |
print "$prognamelong\n"; |
| 49 |
} |
| 50 |
|
| 51 |
foreach ( @ARGV ) { |
| 52 |
my $mpsfile = $_; |
| 53 |
my $elffound = 0; |
| 54 |
open (MPSIN, "$mpsfile") or die "Cannot open file $mpsfile"; |
| 55 |
my @OUT; |
| 56 |
foreach ( <MPSIN> ) { |
| 57 |
if ($_ =~ /^%% MetaPost exteps large file->/) { |
| 58 |
$elffound = 1; |
| 59 |
my $epsfile = (split(/->|\n/,$_))[1]; |
| 60 |
unless ( $opt_q ) { |
| 61 |
print "Inserting $epsfile into $mpsfile\n"; |
| 62 |
} |
| 63 |
open(EPS, "$epsfile") or die "cannot open file $epsfile"; |
| 64 |
push (@OUT, <EPS>); |
| 65 |
} else { |
| 66 |
push (@OUT, $_); |
| 67 |
} |
| 68 |
} |
| 69 |
close MPSIN; |
| 70 |
if ( $elffound ) { |
| 71 |
open (MPSOUT, ">$_") or die "Cannot write to file $_"; |
| 72 |
print MPSOUT @OUT; |
| 73 |
close MPSOUT; |
| 74 |
} |
| 75 |
else { |
| 76 |
unless ( $opt_q ) { |
| 77 |
print "No file to insert into $mpsfile\n" |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
sub help { |
| 83 |
print << "EOF"; |
| 84 |
Usage: |
| 85 |
$progname [options] file.n [file.m [file.l ... ]] |
| 86 |
Options: |
| 87 |
-h\tPrint this message end exit |
| 88 |
-q\tBe quiet |
| 89 |
-i\tIgnore configuration file |
| 90 |
-v\tDisplay version and license and exit |
| 91 |
-V\tDisplay version number and exit |
| 92 |
See exteps.pdf for further documentation |
| 93 |
(texdoc exteps on most unix systems) |
| 94 |
EOF |
| 95 |
} |
| 96 |
|
| 97 |
sub version { |
| 98 |
print << "EOF" |
| 99 |
This is $progname version $progversion |
| 100 |
$prognamelong |
| 101 |
Copyright 2005 by Palle Jorgensen |
| 102 |
The license of $progname is GNU General Public License (GPL) |
| 103 |
EOF |
| 104 |
} |
| 105 |
|
| 106 |
sub versionbrief { |
| 107 |
print "$progversion\n"; |
| 108 |
} |