From: Jean-Marc Lasgouttes Date: Tue, 22 Sep 2009 13:23:36 +0000 (+0000) Subject: Fix a bug when the language passed as an option to babel is ignored. X-Git-Tag: 2.0.0~5464 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d87a67d8dca69b9e6da3b08f89ee572438fd29c1;p=features.git Fix a bug when the language passed as an option to babel is ignored. This can be seen by trying out the document attached to ticket #6142. The problem was that handle_opt() is not used only to parse languages, and thus setting a lang-related bool in there is asking for trouble. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31440 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index 99cad01760..0bf7da3257 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -50,7 +50,7 @@ map > used_packages; bool one_language = true; // to avoid that the babel options overwrite the documentclass options -bool documentclass_language; +bool documentclass_language = false; namespace { @@ -141,11 +141,13 @@ string h_output_changes = "false"; string h_margins = ""; -void handle_opt(vector & opts, char const * const * what, string & target) +// returns true if at least one of the options in what has been found +bool handle_opt(vector & opts, char const * const * what, string & target) { if (opts.empty()) - return; + return false; + bool found = false; // the last language option is the document language (for babel and LyX) // the last size option is the document font size vector::iterator it; @@ -153,13 +155,14 @@ void handle_opt(vector & opts, char const * const * what, string & targe for (; *what; ++what) { it = find(opts.begin(), opts.end(), *what); if (it != opts.end()) { - documentclass_language = true; if (it >= position) { + found = true; target = *what; position = it; } } } + return found; } @@ -169,8 +172,7 @@ void delete_opt(vector & opts, char const * const * what) return; // remove found options from the list - // do this after handle_opt to avoid potential memory leaks and to be able - // to find in every case the last language option + // do this after handle_opt to avoid potential memory leaks vector::iterator it; for (; *what; ++what) { it = find(opts.begin(), opts.end(), *what); @@ -652,8 +654,8 @@ void parse_preamble(Parser & p, ostream & os, if (i != string::npos) h_paperfontsize.erase(i); // to avoid that the babel options overwrite the documentclass options - documentclass_language = false; - handle_opt(opts, known_languages, h_language); + documentclass_language = + handle_opt(opts, known_languages, h_language); delete_opt(opts, known_languages); if (is_known(h_language, known_brazilian_languages)) h_language = "brazilian";