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