1 | #!/bin/sh
|
---|
2 | # $Id: ps2epsi 8491 2008-01-18 06:17:02Z alexcher $
|
---|
3 |
|
---|
4 | # This definition is changed on install to match the
|
---|
5 | # executable name set in the makefile
|
---|
6 | GS_EXECUTABLE=gs
|
---|
7 | gs="`dirname $0`/$GS_EXECUTABLE"
|
---|
8 | if test ! -x "$gs"; then
|
---|
9 | gs="$GS_EXECUTABLE"
|
---|
10 | fi
|
---|
11 | GS_EXECUTABLE=gs
|
---|
12 |
|
---|
13 | # try to create a temporary file securely
|
---|
14 | if test -z "$TMPDIR"; then
|
---|
15 | TMPDIR=/tmp
|
---|
16 | fi
|
---|
17 | if which mktemp >/dev/null 2>/dev/null; then
|
---|
18 | tmpfile="`mktemp $TMPDIR/ps2epsi.XXXXXX`"
|
---|
19 | else
|
---|
20 | tmpdir=$TMPDIR/ps2epsi.$$
|
---|
21 | (umask 077 && mkdir "$tmpdir")
|
---|
22 | if test ! -d "$tmpdir"; then
|
---|
23 | echo "failed: could not create temporary file"
|
---|
24 | exit 1
|
---|
25 | fi
|
---|
26 | tmpfile="$tmpdir"/ps2epsi$$
|
---|
27 | fi
|
---|
28 | trap "rm -rf \"$tmpfile\"" 0 1 2 3 7 13 15
|
---|
29 |
|
---|
30 | export outfile
|
---|
31 |
|
---|
32 | if [ $# -lt 1 -o $# -gt 2 ]; then
|
---|
33 | echo "Usage: `basename $0` file.ps [file.epsi]" 1>&2
|
---|
34 | exit 1
|
---|
35 | fi
|
---|
36 |
|
---|
37 | infile=$1;
|
---|
38 |
|
---|
39 | if [ $# -eq 1 ]
|
---|
40 | then
|
---|
41 | case "${infile}" in
|
---|
42 | *.ps) base=`basename "${infile}" .ps` ;;
|
---|
43 | *.cps) base=`basename "${infile}" .cps` ;;
|
---|
44 | *.eps) base=`basename "${infile}" .eps` ;;
|
---|
45 | *.epsf) base=`basename "${infile}" .epsf` ;;
|
---|
46 | *) base=`basename "${infile}"` ;;
|
---|
47 | esac
|
---|
48 | outfile=${base}.epsi
|
---|
49 | else
|
---|
50 | outfile=$2
|
---|
51 | fi
|
---|
52 |
|
---|
53 | ls -l "${infile}" |
|
---|
54 | awk 'F==1 {
|
---|
55 | cd="%%CreationDate: " $6 " " $7 " " $8;
|
---|
56 | t="%%Title: " $9;
|
---|
57 | f="%%For:" U " " $3;
|
---|
58 | c="%%Creator: Ghostscript ps2epsi from " $9;
|
---|
59 | next;
|
---|
60 | }
|
---|
61 | /^%!/ {next;}
|
---|
62 | /^%%Title:/ {t=$0; next;}
|
---|
63 | /^%%Creator:/ {c=$0; next;}
|
---|
64 | /^%%CreationDate:/ {cd=$0; next;}
|
---|
65 | /^%%For:/ {f=$0; next;}
|
---|
66 | !/^%/ {
|
---|
67 | print "/ps2edict 30 dict def";
|
---|
68 | print "ps2edict begin";
|
---|
69 | print "/epsititle (" t "\\n) def";
|
---|
70 | print "/epsicreator (" c "\\n) def";
|
---|
71 | print "/epsicrdt (" cd "\\n) def";
|
---|
72 | print "/epsifor (" f "\\n) def";
|
---|
73 | print "end";
|
---|
74 | exit(0);
|
---|
75 | }
|
---|
76 | ' U="$USERNAME$LOGNAME" F=1 - F=2 "${infile}" >"$tmpfile"
|
---|
77 |
|
---|
78 | "$GS_EXECUTABLE" -q -dNOPAUSE -dSAFER -dDELAYSAFER -r72 -sDEVICE=bit -sOutputFile=/dev/null "$tmpfile" ps2epsi.ps "$tmpfile" <"${infile}" 1>&2
|
---|
79 | rm -f "$tmpfile"
|
---|
80 | rm -rf "$tmpdir"
|
---|
81 |
|
---|
82 | (
|
---|
83 | cat << BEGINEPS
|
---|
84 | save countdictstack mark newpath /showpage {} def /setpagedevice /pop load def
|
---|
85 | %%EndProlog
|
---|
86 | %%Page 1 1
|
---|
87 | BEGINEPS
|
---|
88 |
|
---|
89 | cat "${infile}" |
|
---|
90 | LC_ALL=C \
|
---|
91 | sed -e '/^%%BeginPreview:/,/^%%EndPreview[^!-\~]*$/d' -e '/^%!PS-Adobe/d'\
|
---|
92 | -e '/^%%[A-Za-z][A-Za-z]*[^!-\~]*$/d' -e '/^%%[A-Za-z][A-Za-z]*: /d'
|
---|
93 |
|
---|
94 | cat << ENDEPS
|
---|
95 | %%Trailer
|
---|
96 | cleartomark countdictstack exch sub { end } repeat restore
|
---|
97 | %%EOF
|
---|
98 | ENDEPS
|
---|
99 |
|
---|
100 | ) >> "${outfile}"
|
---|
101 |
|
---|
102 | exit 0
|
---|