home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / bin / ps2epsi < prev    next >
Encoding:
Text File  |  2005-11-16  |  1.9 KB  |  89 lines

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