Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.lang.postscript > #166
| From | Ilya Zakharevich <nospam-abuse@ilyaz.org> |
|---|---|
| Newsgroups | comp.lang.postscript |
| Subject | Using ps2pdf - enhancements? |
| Date | 2011-04-27 02:47 +0000 |
| Organization | U.C. Berkeley Math. Department. |
| Message-ID | <slrnirf0u0.8k4.nospam-abuse@chorin.math.berkeley.edu> (permalink) |
I'm puzzled why ps2pdf are so limited w.r.t. their options. Why
should people use clumsy gs command-lines directly when a trivial
change to ps2pdf would allow much more flexible syntax?
E.g., the patch below does
0) Won't overwrite a file if the input file is specified to be .pdf
1) Allows arbitrary number of input files (merging ps/pdf);
2) Allows specification of arbitrary PS commands to be interspersed
with input files using -c 'POSTSCRIPT_CODE' syntax.
I'm pretty lame with shell coding; probably this may be simplified a
lot... (I tested that a properly-looking gs command is specified, but
did not test how gs actually works.)
Comments welcome,
Ilya
=======================================================
--- ps2pdfwr-ini Wed Jun 2 17:32:06 2010
+++ ps2pdfwr Tue Apr 26 19:37:10 2011
@@ -15,14 +15,17 @@ OPTIONS="-P- -dSAFER"
while true
do
case "$1" in
+ -c) break ;;
-?*) OPTIONS="$OPTIONS $1" ;;
*) break ;;
esac
shift
done
-if [ $# -lt 1 -o $# -gt 2 ]; then
- echo "Usage: `basename \"$0\"` [options...] (input.[e]ps|-) [output.pdf|-]" 1>&2
+if [ $# -lt 1 ]; then
+ echo "Usage: `basename \"$0\"` [options...] (input.[e]ps|-)" 1>&2
+ echo " `basename \"$0\"` [options...] INPUT (output.pdf|-)" 1>&2
+ echo " INPUT may be a combination of file names and/or -c 'POSTSRIPT_CODE'" 1>&2
exit 1
fi
@@ -34,12 +37,48 @@ then
-) outfile=- ;;
*.eps) base=`basename "${infile}" .eps`; outfile="${base}.pdf" ;;
*.ps) base=`basename "${infile}" .ps`; outfile="${base}.pdf" ;;
+ *.pdf) base=`basename "${infile}" .pdf`; outfile="${base}-.pdf" ;;
*) base=`basename "${infile}"`; outfile="${base}.pdf" ;;
esac
+ set -- -f "$1"
else
- outfile="$2"
+ if [ $# -eq 2 ]
+ then # Special-case $# == 2 for brain-damaged shells
+ outfile="$2"
+ set -- -f "$1"
+ else
+ eval outfile='"$'{$#}'"'
+ ev="set --"
+ pn=0
+ had_c=2
+ for i do
+ pn="$(( 1 + $pn ))"
+ if [ $had_c -eq 2 ] ; then
+ if [ "$i" = "-c" ] ; then
+ do_f=
+ had_c=1
+ else
+ do_f=-f
+ had_c=0
+ fi
+ else
+ if [ $had_c -eq 1 ] ; then
+ had_c=2
+ else # Look for -c
+ if [ "$i" = "-c" ] ; then
+ had_c=1
+ fi
+ fi
+ do_f=
+ fi
+ if [ $pn -ne $# ] ; then
+ ev="$ev $do_f "'"$'{$pn}'"'
+ fi
+ done
+ eval $ev
+ fi
fi
# We have to include the options twice because -I only takes effect if it
# appears before other options.
-exec "$GS_EXECUTABLE" $OPTIONS -q -P- -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sstdout=%stderr "-sOutputFile=$outfile" $OPTIONS -c .setpdfwrite -f "$infile"
+exec "$GS_EXECUTABLE" $OPTIONS -q -P- -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sstdout=%stderr "-sOutputFile=$outfile" $OPTIONS -c .setpdfwrite "$@"
Back to comp.lang.postscript | Previous | Next — Next in thread | Find similar
Using ps2pdf - enhancements? Ilya Zakharevich <nospam-abuse@ilyaz.org> - 2011-04-27 02:47 +0000
Re: Using ps2pdf - enhancements? ken <ken@spamcop.net> - 2011-04-27 07:50 +0100
Re: Using ps2pdf - enhancements? Ilya Zakharevich <nospam-abuse@ilyaz.org> - 2011-04-27 07:52 +0000
csiph-web