1#!/bin/sh 2# $Id: ps2epsi,v 1.10 2004/08/04 00:55:46 giles Exp $ 3 4# This definition is changed on install to match the 5# executable name set in the makefile 6GS_EXECUTABLE=gs 7 8tmpfile=/tmp/ps2epsi$$ 9 10export outfile 11 12if [ $# -lt 1 -o $# -gt 2 ]; then 13 echo "Usage: `basename $0` file.ps [file.epsi]" 1>&2 14 exit 1 15fi 16 17infile=$1; 18 19if [ $# -eq 1 ] 20then 21 case "${infile}" in 22 *.ps) base=`basename "${infile}" .ps` ;; 23 *.cps) base=`basename "${infile}" .cps` ;; 24 *.eps) base=`basename "${infile}" .eps` ;; 25 *.epsf) base=`basename "${infile}" .epsf` ;; 26 *) base=`basename "${infile}"` ;; 27 esac 28 outfile=${base}.epsi 29else 30 outfile=$2 31fi 32 33ls -l "${infile}" | 34awk 'F==1 { 35 cd="%%CreationDate: " $6 " " $7 " " $8; 36 t="%%Title: " $9; 37 f="%%For:" U " " $3; 38 c="%%Creator: Ghostscript ps2epsi from " $9; 39 next; 40 } 41 /^%!/ {next;} 42 /^%%Title:/ {t=$0; next;} 43 /^%%Creator:/ {c=$0; next;} 44 /^%%CreationDate:/ {cd=$0; next;} 45 /^%%For:/ {f=$0; next;} 46 !/^%/ { 47 print "/ps2edict 30 dict def"; 48 print "ps2edict begin"; 49 print "/epsititle (" t "\\n) def"; 50 print "/epsicreator (" c "\\n) def"; 51 print "/epsicrdt (" cd "\\n) def"; 52 print "/epsifor (" f "\\n) def"; 53 print "end"; 54 exit(0); 55 } 56 ' U="$USERNAME$LOGNAME" F=1 - F=2 "${infile}" >$tmpfile 57 58$GS_EXECUTABLE -q -dNOPAUSE -dSAFER -dDELAYSAFER -r72 -sDEVICE=bit -sOutputFile=/dev/null $tmpfile ps2epsi.ps $tmpfile <"${infile}" 1>&2 59rm -f $tmpfile 60 61( 62cat << BEGINEPS 63save countdictstack mark newpath /showpage {} def /setpagedevice {pop} def 64%%EndProlog 65%%Page 1 1 66BEGINEPS 67 68cat "${infile}" | 69sed -e '/^%%BeginPreview:/,/^%%EndPreview[^!-~]*$/d' -e '/^%!PS-Adobe/d'\ 70 -e '/^%%[A-Za-z][A-Za-z]*[^!-~]*$/d' -e '/^%%[A-Za-z][A-Za-z]*: /d' 71 72cat << ENDEPS 73%%Trailer 74cleartomark countdictstack exch sub { end } repeat restore 75%%EOF 76ENDEPS 77 78) >> "${outfile}" 79 80exit 0 81