]> git.lyx.org Git - features.git/commitdiff
Fix crash reported by Norbert Koksch, using a hard-coded 5 digits (boo! hiss!)
authorAngus Leeming <leeming@lyx.org>
Tue, 3 Sep 2002 16:15:03 +0000 (16:15 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 3 Sep 2002 16:15:03 +0000 (16:15 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5197 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/scripts/lyxpreview2ppm.sh
src/graphics/ChangeLog
src/graphics/PreviewLoader.C

index 4a586013bd6493a5a6ca58d390ac924c6e7e3254..cb22810d9d9683a28a3017e9379ae6831e5ba580 100644 (file)
@@ -3,6 +3,12 @@
        * lyx2lyx/lyxconvert_218.py (update_tabular): Prevent changing
        of non-tabular lines.
 
+2002-09-03  Angus Leeming  <leeming@lyx.org>
+
+       * scripts/lyxpreview2ppm.sh: fix crash reported by Norbert Koksch when
+       generating more than 999 preview snippets by passing and using the
+       number of digits needed by the filenames generated by gs.
+
 2002-09-03  Angus Leeming  <leeming@lyx.org>
 
        * scripts/lyxpreview2ppm.sh: re-written to make use of the "lyx"
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}
index 27743c2f34486d2d37c73d79053f2779472d368f..1b8b84681c43e08c78438cfe267cad465e7ab008 100644 (file)
@@ -1,3 +1,11 @@
+2002-09-03  Angus Leeming  <leeming@lyx.org>
+
+       * PreviewLoader.C: fix crash reported by Norbert Koksch when
+       generating more than 999 preview snippets. Use filenames with 5 digit
+       numbers, not 3, in the first instance, although more general code is
+       commented out. I don't suppose /anyone/ has 100000 formulae in one
+       document...
+
 2002-09-03  Angus Leeming  <leeming@lyx.org>
 
        * PreviewLoader.C: activate #ifdef USING_NEW_PREVIEW_STY code.
index 389686f21df444a5a7be06cc389bf1d8494a3605..ccb825af73a26967f1d6a5beb3447ada99e11cb9 100644 (file)
@@ -86,6 +86,16 @@ private:
 };
 
 
+// Given a base-10 number return the number of digits needed to store it.
+// Eg 2 requires 1 digit, 22 requires 2 digits and 999 requires 3 digits.
+// Note that AndrĂ© suggests just returning '12' here...
+int ndigits(int num)
+{
+       //return 1 + int(std::log10(double(num)));
+       return 5;
+}
+
+
 /// Store info on a currently executing, forked process.
 struct InProgress {
        ///
@@ -246,15 +256,16 @@ namespace {
 
 struct IncrementedFileName {
        IncrementedFileName(string const & to_format,
-                           string const & filename_base)
-               : to_format_(to_format), base_(filename_base), counter_(1)
+                           string const & filename_base, int nd)
+               : to_format_(to_format), base_(filename_base),
+                 ndigits_(nd), counter_(1)
        {}
 
        StrPair const operator()(string const & snippet)
        {
                ostringstream os;
                os << base_
-                  << setfill('0') << setw(3) << counter_++
+                  << setfill('0') << setw(ndigits_) << counter_++
                   << "." << to_format_;
 
                string const file = os.str().c_str();
@@ -265,6 +276,7 @@ struct IncrementedFileName {
 private:
        string const & to_format_;
        string const & base_;
+       int const ndigits_;
        int counter_;
 };
 
@@ -281,7 +293,8 @@ InProgress::InProgress(string const & filename_base,
        BitmapFile::iterator sit = snippets.begin();
 
        std::transform(pit, pend, sit,
-                      IncrementedFileName(to_format, filename_base));
+                      IncrementedFileName(to_format, filename_base,
+                                          ndigits(int(snippets.size()))));
 }
 
 
@@ -458,9 +471,6 @@ void PreviewLoader::Impl::startLoading()
        // such processes if it starts correctly.
        InProgress inprogress(filename_base, pending_, pconverter_->to);
 
-       // clear pending_, so we're ready to start afresh.
-       pending_.clear();
-
        // Output the LaTeX file.
        string const latexfile = filename_base + ".tex";
 
@@ -475,10 +485,14 @@ void PreviewLoader::Impl::startLoading()
        // The conversion command.
        ostringstream cs;
        cs << pconverter_->command << " " << latexfile << " "
-          << int(font_scaling_factor_);
+          << int(font_scaling_factor_) << " "
+          << ndigits(int(pending_.size()));
 
        string const command = LibScriptSearch(cs.str().c_str());
 
+       // clear pending_, so we're ready to start afresh.
+       pending_.clear();
+
        // Initiate the conversion from LaTeX to bitmap images files.
        Forkedcall::SignalTypePtr convert_ptr;
        convert_ptr.reset(new Forkedcall::SignalType);