]> git.lyx.org Git - features.git/blobdiff - lib/scripts/lyxpreview2ppm.sh
Fix crash reported by Norbert Koksch, using a hard-coded 5 digits (boo! hiss!)
[features.git] / lib / scripts / lyxpreview2ppm.sh
index bf20cca108baa5d0e2e7d0514284e94b4514729a..3ad5144178ed82131015ada9eedfab75738ea865 100644 (file)
 
 # preview.sty can be obtained from CTAN/macros/latex/contrib/supported/preview.
 
-# This script, lyxpreview2ppm.sh, takes two arguments, the name of the file
-# to be converted and a scale factor, used to ascertain the resolution of the
-# generated image which is then passed to gs.
+# This script, lyxpreview2ppm.sh, takes three arguments:
+# FILE:        the name of the file to be converted.
+# SCALEFACTOR: scale factor, used to ascertain the resolution of the
+#              generated imagewhich is then passed to gs.
+# NDIGITS:     the number of digits in the filenames generated by gs,
+#              ${BASE}%${NDIGITS}d.ppm
 
 # If successful it will leave in dir ${DIR} a number of image files
-# ${BASE}[0-9]\{3\}.ppm and a file ${BASE}.metrics containing info needed by
-# LyX to position the images correctly on the screen. All other files ${BASE}*
-# will be deleted.
+# ${BASE}[0-9]\{${NDIGITS}\}.ppm and a file ${BASE}.metrics containing info
+# needed by LyX to position the images correctly on the screen.
+# All other files ${BASE}* will be deleted.
 
 # Three helper functions.
 FIND_IT () {
@@ -45,7 +48,7 @@ REQUIRED_VERSION () {
 }
 
 # Preliminary check
-if [ $# -ne 2 ]; then
+if [ $# -ne 3 ]; then
        exit 1
 fi
 
@@ -59,6 +62,7 @@ DIR=`dirname $1`
 BASE=`basename $1 .tex`
 
 SCALEFACTOR=$2
+NDIGITS=$3
 
 TEXFILE=${BASE}.tex
 LOGFILE=${BASE}.log
@@ -129,7 +133,8 @@ if [ ${RESOLUTION} -gt 150 ]; then
        ALPHA=2
 fi
 
-gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pnmraw -sOutputFile=${BASE}%03d.ppm \
+gs -q -dNOPAUSE -dBATCH -dSAFER \
+    -sDEVICE=pnmraw -sOutputFile=${BASE}%0${NDIGITS}d.ppm \
     -dGraphicsAlphaBit=${ALPHA} -dTextAlphaBits=${ALPHA} -r${RESOLUTION} \
     ${PSFILE}
 
@@ -140,5 +145,6 @@ fi
 
 # All has been successful, so remove everything except the bitmap files
 # and the metrics file.
-FILES=`ls ${BASE}* | sed -e "/${BASE}.metrics/d" -e "/${BASE}[0-9]\{3\}.ppm/d"`
+FILES=`ls ${BASE}* | \
+       sed -e "/${BASE}.metrics/d" -e "/${BASE}[0-9]\{${NDIGITS}\}.ppm/d"`
 rm -f ${FILES}