]> git.lyx.org Git - lyx.git/blobdiff - src/lyxrc.C
Fix crash when running lyx -dbg insets -e ...
[lyx.git] / src / lyxrc.C
index f4caddcd0b627abb4c836a7207553053b7cb29e7..bc3b7d302ebf40235cff681c85ce36216d338e4b 100644 (file)
@@ -4,7 +4,7 @@
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2000 The LyX Team.
+ *          Copyright 1995-2001 The LyX Team.
  *
  * ====================================================== */
 
@@ -31,6 +31,7 @@
 #include "support/filetools.h"
 #include "lyxtext.h"
 #include "converter.h"
+#include "gettext.h"
 
 using std::ostream;
 using std::ofstream;
@@ -40,10 +41,10 @@ using std::endl;
 using std::vector;
 
 extern LyXAction lyxaction;
-extern kb_keymap * toplevel_keymap;
+extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
+namespace {
 
-static
 keyword_item lyxrcTags[] = {
        { "\\accept_compound", LyXRC::RC_ACCEPT_COMPOUND },
        { "\\alternate_language", LyXRC::RC_ALT_LANG },
@@ -68,10 +69,6 @@ keyword_item lyxrcTags[] = {
        { "\\document_path", LyXRC::RC_DOCUMENTPATH },
        { "\\escape_chars", LyXRC::RC_ESC_CHARS },
        { "\\exit_confirmation", LyXRC::RC_EXIT_CONFIRMATION },
-#if 0
-       { "\\fax_command", LyXRC::RC_FAX_COMMAND },
-       { "\\fax_program", LyXRC::RC_FAXPROGRAM },
-#endif
        { "\\font_encoding", LyXRC::RC_FONT_ENCODING },
        { "\\format", LyXRC::RC_FORMAT },
        { "\\input", LyXRC::RC_INPUT },
@@ -83,7 +80,10 @@ keyword_item lyxrcTags[] = {
        { "\\language_auto_end", LyXRC::RC_LANGUAGE_AUTO_END },
        { "\\language_command_begin", LyXRC::RC_LANGUAGE_COMMAND_BEGIN },
        { "\\language_command_end", LyXRC::RC_LANGUAGE_COMMAND_END },
+       { "\\language_command_local", LyXRC::RC_LANGUAGE_COMMAND_LOCAL },
+       { "\\language_global_options", LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS },
        { "\\language_package", LyXRC::RC_LANGUAGE_PACKAGE },
+       { "\\language_use_babel", LyXRC::RC_LANGUAGE_USE_BABEL },
        { "\\lastfiles", LyXRC::RC_LASTFILES },
        { "\\make_backup", LyXRC::RC_MAKE_BACKUP },
        { "\\mark_foreign_language", LyXRC::RC_MARK_FOREIGN_LANGUAGE },
@@ -91,9 +91,6 @@ keyword_item lyxrcTags[] = {
        { "\\num_lastfiles", LyXRC::RC_NUMLASTFILES },
        { "\\override_x_deadkeys", LyXRC::RC_OVERRIDE_X_DEADKEYS },
        { "\\personal_dictionary", LyXRC::RC_PERS_DICT },
-#if 0
-       { "\\phone_book", LyXRC::RC_PHONEBOOK },
-#endif
        { "\\print_adapt_output", LyXRC::RC_PRINT_ADAPTOUTPUT },
        { "\\print_collcopies_flag", LyXRC::RC_PRINTCOLLCOPIESFLAG },
        { "\\print_command", LyXRC::RC_PRINT_COMMAND },
@@ -136,6 +133,9 @@ keyword_item lyxrcTags[] = {
        { "\\use_escape_chars", LyXRC::RC_USE_ESC_CHARS },
        { "\\use_input_encoding", LyXRC::RC_USE_INP_ENC },
        { "\\use_personal_dictionary", LyXRC::RC_USE_PERS_DICT },
+#ifdef USE_PSPELL
+       { "\\use_pspell", LyXRC::RC_USE_PSPELL },
+#endif
        { "\\use_tempdir", LyXRC::RC_USETEMPDIR },
        { "\\view_dvi_paper_option", LyXRC::RC_VIEWDVI_PAPEROPTION },
        { "\\viewer" ,LyXRC::RC_VIEWER}, 
@@ -143,7 +143,9 @@ keyword_item lyxrcTags[] = {
 };
 
 /* Let the range depend of the size of lyxrcTags.  Alejandro 240596 */
-static const int lyxrcCount = sizeof(lyxrcTags) / sizeof(keyword_item);
+const int lyxrcCount = sizeof(lyxrcTags) / sizeof(keyword_item);
+
+} // namespace anon
 
 
 LyXRC::LyXRC() 
@@ -153,6 +155,8 @@ LyXRC::LyXRC()
 
 
 void LyXRC::setDefaults() {
+       bind_file = "cua";
+       hasBindFile = false;
        ui_file = "default";
        // Get printer from the environment. If fail, use default "",
        // assuming that everything is set up correctly.
@@ -202,7 +206,7 @@ void LyXRC::setDefaults() {
        menu_font_name = "-*-helvetica-bold-r";
        popup_font_name = "-*-helvetica-medium-r";
        font_norm = "iso8859-1";
-       font_norm_type = OTHER_ENCODING;
+       font_norm_type = ISO_8859_1;
        font_norm_menu = "";
        override_x_deadkeys = true;
        autosave = 300;
@@ -215,6 +219,9 @@ void LyXRC::setDefaults() {
        exit_confirmation = true;
        display_shortcuts = true;
        // Spellchecker settings:
+#ifdef USE_PSPELL      
+       use_pspell = true;
+#endif
        isp_command = "ispell";
        isp_accept_compound = false;
        isp_use_input_encoding = false;
@@ -222,15 +229,17 @@ void LyXRC::setDefaults() {
        isp_use_pers_dict = false;
        isp_use_esc_chars = false;
        use_kbmap = false;
-       hasBindFile = false;
        rtl_support = false;
        auto_number = true;
        mark_foreign_language = true;
-       language_package = "\\usepackage{babel}";
        language_auto_begin = true;
        language_auto_end = true;
+       language_global_options = true;
+       language_use_babel = true;
+       language_package = "\\usepackage{babel}";
        language_command_begin = "\\selectlanguage{$$lang}";
        language_command_end = "\\selectlanguage{$$lang}";
+       language_command_local = "\\foreignlanguage{$$lang}{";
        default_language = "english";
        //
        new_ask_filename = false;
@@ -260,12 +269,14 @@ int LyXRC::ReadBindFile(string const & name)
        return result;
 }
 
+void LyXRC::readBindFileIfNeeded()
+{
+       if (!hasBindFile)
+               ReadBindFile(bind_file);
+}
 
 int LyXRC::read(string const & filename)
-{
-       // Default bindfile.
-       static string const bindFile("cua");
-       
+{      
        LyXLex lexrc(lyxrcTags, lyxrcCount);
        if (lyxerr.debugging(Debug::PARSER))
                lexrc.printTable(lyxerr);
@@ -273,7 +284,7 @@ int LyXRC::read(string const & filename)
        lexrc.setFile(filename);
        if (!lexrc.IsOK()) return -2;
        
-       lyxerr[Debug::INIT] << "Reading '" << filename << "'..." << endl;
+       lyxerr[Debug::LYXRC] << "Reading '" << filename << "'..." << endl;
        
        while (lexrc.IsOK()) {
                // By using two switches we take advantage of the compiler
@@ -306,13 +317,16 @@ int LyXRC::read(string const & filename)
                case RC_BINDFILE:                     // RVDK_PATCH_5
                        if (lexrc.next()) {
                                string tmp(lexrc.GetString());
-                               if (bind_file.empty()) {
-                                       // we only need the name of the first
-                                       // bind file since that (usually)
-                                       // includes several others.
+                               if (hasBindFile)
+                                       // We are already in the
+                                       // "actually read bind file"
+                                       // mode.
+                                       ReadBindFile(tmp);
+                               else
+                                       // We are still in the "just
+                                       // remember the name of the
+                                       // bind file" mode.
                                        bind_file = tmp;
-                               }
-                               ReadBindFile(tmp);
                        }
                        break;
                        
@@ -678,10 +692,8 @@ int LyXRC::read(string const & filename)
                        // we should not do an explicit binding before
                        // loading a bind file. So, in this case, load
                        // the default bind file.
-                       if (!hasBindFile) {
-                               bind_file = bindFile;
-                               ReadBindFile();
-                       }
+                       readBindFileIfNeeded();
+
                        // !!!chb, dynamic key binding...
                        int action, res = 0;
                        string seq, cmd;
@@ -701,15 +713,17 @@ int LyXRC::read(string const & filename)
                        }
                        
                        if ((action = lyxaction.LookupFunc(cmd))>= 0) {
-                               if (lyxerr.debugging(Debug::KBMAP)) {
+                               if (lyxerr.debugging(Debug::LYXRC)) {
                                        lyxerr << "RC_BIND: Sequence `"
                                               << seq << "' Command `"
                                               << cmd << "' Action `"
                                               << action << '\'' << endl;
                                }
                                res = toplevel_keymap->bind(seq, action);
-                               if (res != 0) {
+                               if (res != 0
+                                   && lyxerr.debugging(Debug::LYXRC)) {
                                        lexrc.printError(
+                                               "RC_BIND: "
                                                "Invalid key sequence `"
                                                + seq + '\''); 
                                }
@@ -734,25 +748,6 @@ int LyXRC::read(string const & filename)
                                cursor_follows_scrollbar = lexrc.GetBool();
                        break;
 
-#if 0
-               case RC_FAX_COMMAND:
-                       if (lexrc.next())
-                               fax_command = lexrc.GetString();
-                       break;
-               case RC_FAXPROGRAM:
-                       if (lexrc.next())
-                               fax_program = lexrc.GetString();
-                       break;
-               case RC_PHONEBOOK:
-                       if (lexrc.next()) {
-                               string s = lexrc.GetString();
-                               if (AbsolutePath(s))
-                                       phone_book = s;
-                               else
-                                       phone_book = user_lyxdir + s;
-                       }
-                       break;
-#endif
                case RC_ASCIIROFF_COMMAND:
                        if (lexrc.next())
                                ascii_roff_command = lexrc.GetString();
@@ -762,6 +757,12 @@ int LyXRC::read(string const & filename)
                                ascii_linelen = lexrc.GetInteger();
                        break;
                        // Spellchecker settings:
+#ifdef USE_PSPELL
+               case RC_USE_PSPELL:
+                       if (lexrc.next())
+                               use_pspell = lexrc.GetBool();
+                       break;
+#endif
                case RC_SPELL_COMMAND:
                        if (lexrc.next())
                                isp_command = lexrc.GetString();
@@ -822,6 +823,14 @@ int LyXRC::read(string const & filename)
                        if (lexrc.next())
                                language_auto_end = lexrc.GetBool();
                        break;
+               case RC_LANGUAGE_GLOBAL_OPTIONS:
+                       if (lexrc.next())
+                               language_global_options = lexrc.GetBool();
+                       break;
+               case RC_LANGUAGE_USE_BABEL:
+                       if (lexrc.next())
+                               language_use_babel = lexrc.GetBool();
+                       break;
                case RC_LANGUAGE_COMMAND_BEGIN:
                        if (lexrc.next())
                                language_command_begin = lexrc.GetString();
@@ -830,6 +839,10 @@ int LyXRC::read(string const & filename)
                        if (lexrc.next())
                                language_command_end = lexrc.GetString();
                        break;
+               case RC_LANGUAGE_COMMAND_LOCAL:
+                       if (lexrc.next())
+                               language_command_local = lexrc.GetString();
+                       break;
                case RC_RTL_SUPPORT:
                        if (lexrc.next())
                                rtl_support = lexrc.GetBool();
@@ -912,6 +925,10 @@ int LyXRC::read(string const & filename)
                }
        }
 
+       /// Update converters data-structures
+       converters.Update(formats);
+       converters.BuildGraph();
+
        return 0;
 }
 
@@ -940,7 +957,7 @@ void LyXRC::output(ostream & os) const
           << "###          LyX, The Document Processor\n"
           << "###\n"
           << "###          Copyright 1995 Matthias Ettrich\n"
-          << "###          Copyright 1995-2000 The LyX Team.\n"
+          << "###          Copyright 1995-2001 The LyX Team.\n"
           << "###\n"
           << "### ========================================================\n"
           << "\n"
@@ -1357,24 +1374,6 @@ void LyXRC::output(ostream & os) const
                        os << "\\backupdir_path \"" << backupdir_path << "\"\n";
                }
 
-#if 0
-               os << "\n#\n"
-                  << "# FAX SECTION #######################################\n"
-                  << "#\n\n";
-               
-       case RC_FAX_COMMAND:
-               if (fax_command != system_lyxrc.fax_command) {
-                       os << "\\fax_command \"" << fax_command << "\"\n";
-               }
-       case RC_PHONEBOOK:
-               if (phone_book != system_lyxrc.phone_book) {
-                       os << "\\phone_book \"" << phone_book << "\"\n";
-               }
-       case RC_FAXPROGRAM:
-               if (fax_program != system_lyxrc.fax_program) {
-                       os << "\\fax_program \"" << fax_program << "\"\n";
-               }
-#endif
                os << "\n#\n"
                   << "# ASCII EXPORT SECTION ##############################\n"
                   << "#\n\n";
@@ -1388,7 +1387,12 @@ void LyXRC::output(ostream & os) const
                os << "\n#\n"
                   << "# SPELLCHECKER SECTION ##############################\n"
                   << "#\n\n";
-
+#ifdef USE_PSPELL
+       case RC_USE_PSPELL:
+               if (use_pspell != system_lyxrc.use_pspell) {
+                       os << "\\use_pspell \"" << use_pspell << "\"\n";
+               }
+#endif
        case RC_SPELL_COMMAND:
                if (isp_command != system_lyxrc.isp_command) {
                        os << "\\spell_command \"" << isp_command << "\"\n";
@@ -1449,6 +1453,19 @@ void LyXRC::output(ostream & os) const
                        os << "\\language_package \"" << language_package
                           << "\"\n";
                }
+       case RC_LANGUAGE_GLOBAL_OPTIONS:
+               if (language_global_options
+                   != system_lyxrc.language_global_options) {
+                       os << "\\language_global_options \""
+                          << tostr(language_global_options)
+                          << "\"\n";
+               }
+       case RC_LANGUAGE_USE_BABEL:
+               if (language_use_babel != system_lyxrc.language_use_babel) {
+                       os << "\\language_use_babel \""
+                          << tostr(language_use_babel)
+                          << "\"\n";
+               }
        case RC_LANGUAGE_COMMAND_BEGIN:
                if (language_command_begin
                    != system_lyxrc.language_command_begin) {
@@ -1462,6 +1479,13 @@ void LyXRC::output(ostream & os) const
                        os << "\\language_command_end \"" << language_command_end
                           << "\"\n";
                }
+       case RC_LANGUAGE_COMMAND_LOCAL:
+               if (language_command_local
+                   != system_lyxrc.language_command_local) {
+                       os << "\\language_command_local \""
+                          << language_command_local
+                          << "\"\n";
+               }
        case RC_LANGUAGE_AUTO_BEGIN:
                if (language_auto_begin != system_lyxrc.language_auto_begin) {
                        os << "\\language_auto_begin " 
@@ -1584,6 +1608,8 @@ void LyXRC::set_font_norm_type()
                font_norm_type = ISO_8859_6_8;
        else if (font_norm == "iso8859-9")
                font_norm_type = ISO_8859_9;
+       else if (font_norm == "iso8859-15")
+               font_norm_type = ISO_8859_15;
        else
                font_norm_type = OTHER_ENCODING;
 }
@@ -1759,16 +1785,6 @@ string const LyXRC::getDescription(LyXRCTags tag)
                str = N_("Use this to set the correct mapping file for your keyboard. You'll need this if you for instance want to type German documents on an American keyboard.");
                break;
 
-#if 0
-       case RC_FAX_COMMAND:
-               break;
-               
-       case RC_PHONEBOOK:
-               break;
-               
-       case RC_FAXPROGRAM:
-               break;
-#endif 
        case RC_ASCIIROFF_COMMAND:
                str = N_("Use to define an external program to render tables in the ASCII output. E.g. \"groff -t -Tlatin1 $$FName\"  where $$FName is the input file. If \"none\" is specified, an internal routine is used.");
                break;
@@ -1861,6 +1877,14 @@ string const LyXRC::getDescription(LyXRCTags tag)
        case RC_LANGUAGE_PACKAGE:
                str = N_("The latex command for loading the language package. E.g. \"\\usepackage{babel}\", \"\\usepackage{omega}\".");
                break;
+
+       case RC_LANGUAGE_GLOBAL_OPTIONS:
+               str = N_("De-select if you don't want the language(s) used as an argument to \\documentclass.");
+               break;
+
+       case RC_LANGUAGE_USE_BABEL:
+               str = N_("De-select if you don't want babel to be used when the language of the document is the default language.");
+               break;
                
        case RC_LANGUAGE_AUTO_BEGIN:
                str = N_("Select if a language switching command is needed at the beginning of the document.");
@@ -1877,7 +1901,11 @@ string const LyXRC::getDescription(LyXRCTags tag)
        case RC_LANGUAGE_COMMAND_END:
                str = N_("The latex command for changing back to the language of the document.");
                break;
-               
+
+       case RC_LANGUAGE_COMMAND_LOCAL:
+               str = N_("The latex command for local changing of the language.");
+               break;
+
        case RC_DATE_INSERT_FORMAT:
                //xgettext:no-c-format
                str = N_("This accepts the normal strftime formats; see man strftime for full details. E.g.\"%A, %e. %B %Y\".");