Jean-Marc Lasgouttes wrote: > Another option that you could explore (in order to avoid to push > tokens), is to use LyXLex::eatLine() instead of LyXLex::nextToken(). This > uses the remainder of the line as next token. I am not sure whether it > will give you correctly an empty token when the argument to > \paperpackage is missing, but it is probably worth trying.
It does give an empty token. > It would give something like: > > + lex.eatLine(); > + if (lex.getString().empty()) { > + params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4; > + } else { > + int tmpret = lex.findToken(string_paperpackages); > + if (tmpret == -1) { > + ++tmpret; > + params.paperpackage = BufferParams::PACKAGE_NONE; > + } else > + params.paperpackage = tmpret; > + } > > What do you think of that? This is almost working, but the token needs still to be pushed if there is an argument, because getString() removes it. I think the attached patch is finally safe. OK to apply it? Georg
Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.1021.2.38 diff -u -r1.1021.2.38 ChangeLog --- src/ChangeLog 4 Jul 2004 10:17:28 -0000 1.1021.2.38 +++ src/ChangeLog 7 Jul 2004 18:58:25 -0000 @@ -1,3 +1,9 @@ +2004-07-07 Georg Baum <[EMAIL PROTECTED]> + + * buffer.C (parseSingleLyXformat2Token): fix the off-by-one-error + in the paperpackage selection without modifying the file format + with help from Jean-Marc Lasgouttes + 2004-07-04 Jürgen Spitzmüller <[EMAIL PROTECTED]> * tex-strings.C: revert paperpackage fix from 2004-06-27 as it Index: src/buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.399.2.8 diff -u -r1.399.2.8 buffer.C --- src/buffer.C 4 May 2004 09:15:44 -0000 1.399.2.8 +++ src/buffer.C 7 Jul 2004 18:58:28 -0000 @@ -751,12 +751,27 @@ else params.papersize2 = tmpret; } else if (token == "\\paperpackage") { - int tmpret = lex.findToken(string_paperpackages); - if (tmpret == -1) { - ++tmpret; - params.paperpackage = BufferParams::PACKAGE_NONE; - } else - params.paperpackage = tmpret; + // string_paperpackages is missing the first entry "none". + // Therefore, the strings in the .lyx file are off by one, + // and the last setting PACKAGE_WIDEMARGINSA4 is written as + // an empty string. + // Since we cannot fix string_paperpackages because this + // would be a file format change, we have to recognize the + // empty argument of "\\paperpackage" as PACKAGE_WIDEMARGINSA4 + // here. + lex.eatLine(); + string const nextToken = lex.getString(); + if (nextToken.empty()) { + params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4; + } else { + lex.pushToken(nextToken); + int tmpret = lex.findToken(string_paperpackages); + if (tmpret == -1) { + ++tmpret; + params.paperpackage = BufferParams::PACKAGE_NONE; + } else + params.paperpackage = tmpret; + } } else if (token == "\\use_geometry") { lex.nextToken(); params.use_geometry = lex.getInteger();