Avoid multiple execution of AddToPreamble and friends

When trying to read a textclass, read(Lexer, Readtype) parses and
executes the first token and only then verifies that its effect was to
set format properly. Otherwise it exits.

This is wrong, because if the first tag is "AddToPreamble", then it will
have modified the preamble by the time we notice it was not "Format" and
therefore exit.

The new code starts by requiring a correct "Format" tag.

Fixes bug #10725.
This commit is contained in:
Jean-Marc Lasgouttes 2017-07-13 19:03:06 +02:00
parent bebfa84d79
commit ebb9d7b058

View File

@ -408,11 +408,14 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
if (!lexrc.isOK()) if (!lexrc.isOK())
return ERROR; return ERROR;
// Format of files before the 'Format' tag was introduced // The first usable line should be
int format = 1; // Format LAYOUT_FORMAT
bool error = false; if (lexrc.lex() != TC_FORMAT || !lexrc.next()
|| lexrc.getInteger() != LAYOUT_FORMAT)
return FORMAT_MISMATCH;
// parsing // parsing
bool error = false;
while (lexrc.isOK() && !error) { while (lexrc.isOK() && !error) {
int le = lexrc.lex(); int le = lexrc.lex();
@ -437,8 +440,8 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
switch (static_cast<TextClassTags>(le)) { switch (static_cast<TextClassTags>(le)) {
case TC_FORMAT: case TC_FORMAT:
if (lexrc.next()) lexrc.next();
format = lexrc.getInteger(); lexrc.printError("Duplicate Format directive");
break; break;
case TC_OUTPUTFORMAT: case TC_OUTPUTFORMAT:
@ -853,11 +856,6 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
error = !readOutlinerName(lexrc); error = !readOutlinerName(lexrc);
break; break;
} // end of switch } // end of switch
// Note that this is triggered the first time through the loop unless
// we hit a format tag.
if (format != LAYOUT_FORMAT)
return FORMAT_MISMATCH;
} }
// at present, we abort if we encounter an error, // at present, we abort if we encounter an error,