]> git.lyx.org Git - features.git/commitdiff
Fix a bug when the language passed as an option to babel is ignored.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 22 Sep 2009 13:23:36 +0000 (13:23 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 22 Sep 2009 13:23:36 +0000 (13:23 +0000)
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

src/tex2lyx/preamble.cpp

index 99cad01760c3abce14e9be208df9a0126225fe68..0bf7da3257ddb19452f6ca1105b3317aa3b7ac1c 100644 (file)
@@ -50,7 +50,7 @@ map<string, vector<string> > 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<string> & 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<string> & 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<string>::iterator it;
@@ -153,13 +155,14 @@ void handle_opt(vector<string> & 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<string> & 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<string>::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";