Author: rgheck
Date: Sun Jan 16 21:28:43 2011
New Revision: 37233
URL: http://www.lyx.org/trac/changeset/37233

Log:
Conversion routines for preference files.

Modified:
   lyx-devel/trunk/lib/scripts/prefs2prefs_prefs.py
   lyx-devel/trunk/src/LyXRC.cpp
   lyx-devel/trunk/src/LyXRC.h
   lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp

Modified: lyx-devel/trunk/lib/scripts/prefs2prefs_prefs.py
==============================================================================
--- lyx-devel/trunk/lib/scripts/prefs2prefs_prefs.py    Sun Jan 16 20:55:03 
2011        (r37232)
+++ lyx-devel/trunk/lib/scripts/prefs2prefs_prefs.py    Sun Jan 16 21:28:43 
2011        (r37233)
@@ -29,7 +29,8 @@
   tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
         "\\plaintext_roff_command", "\\use_alt_language", 
         "\\use_escape_chars", "\\use_input_encoding",
-        "\\use_personal_dictionary", "\\use_pspell")
+        "\\use_personal_dictionary", "\\use_pspell",
+        "\\use_spell_lib")
   line = line.lstrip()
   for tag in tags:
     if line.startswith(tag):

Modified: lyx-devel/trunk/src/LyXRC.cpp
==============================================================================
--- lyx-devel/trunk/src/LyXRC.cpp       Sun Jan 16 20:55:03 2011        (r37232)
+++ lyx-devel/trunk/src/LyXRC.cpp       Sun Jan 16 21:28:43 2011        (r37233)
@@ -54,6 +54,8 @@
 
 namespace {
 
+static unsigned int const LYXRC_FILEFORMAT = 1;
+
 // when adding something to this array keep it sorted!
 LexerKeyword lyxrcTags[] = {
        { "\\accept_compound", LyXRC::RC_ACCEPT_COMPOUND },
@@ -97,7 +99,7 @@
        { "\\example_path", LyXRC::RC_EXAMPLEPATH },
        { "\\export_overwrite", LyXRC::RC_EXPORT_OVERWRITE },
        { "\\font_encoding", LyXRC::RC_FONT_ENCODING },
-       { "\\format", LyXRC::RC_FORMAT },
+       { "\\format", LyXRC::RC_FILEFORMAT },
        { "\\forward_search_dvi", LyXRC::RC_FORWARD_SEARCH_DVI },
        { "\\forward_search_pdf", LyXRC::RC_FORWARD_SEARCH_PDF },
        { "\\fullscreen_limit", LyXRC::RC_FULL_SCREEN_LIMIT },
@@ -137,9 +139,7 @@
        { "\\open_buffers_in_tabs", LyXRC::RC_OPEN_BUFFERS_IN_TABS },
        { "\\paragraph_markers", LyXRC::RC_PARAGRAPH_MARKERS },
        { "\\path_prefix", LyXRC::RC_PATH_PREFIX },
-       { "\\personal_dictionary", LyXRC::RC_PERS_DICT },
        { "\\plaintext_linelen", LyXRC::RC_PLAINTEXT_LINELEN },
-       { "\\plaintext_roff_command", LyXRC::RC_PLAINTEXT_ROFF_COMMAND },
        { "\\preview", LyXRC::RC_PREVIEW },
        { "\\preview_hashed_labels", LyXRC::RC_PREVIEW_HASHED_LABELS },
        { "\\preview_scale_factor", LyXRC::RC_PREVIEW_SCALE_FACTOR },
@@ -181,7 +181,6 @@
        { "\\single_close_tab_button", LyXRC::RC_SINGLE_CLOSE_TAB_BUTTON },
        { "\\single_instance", LyXRC::RC_SINGLE_INSTANCE },
        { "\\sort_layouts", LyXRC::RC_SORT_LAYOUTS },
-       { "\\spell_command", LyXRC::RC_SPELL_COMMAND },
        { "\\spellcheck_continuously", LyXRC::RC_SPELLCHECK_CONTINUOUSLY },
        { "\\spellcheck_notes", LyXRC::RC_SPELLCHECK_NOTES },
        { "\\spellchecker", LyXRC::RC_SPELLCHECKER },
@@ -192,18 +191,11 @@
        { "\\tex_expects_windows_paths", LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS },
        { "\\thesaurusdir_path", LyXRC::RC_THESAURUSDIRPATH },
        { "\\ui_file", LyXRC::RC_UIFILE },
-       { "\\use_alt_language", LyXRC::RC_USE_ALT_LANG },
        { "\\use_converter_cache", LyXRC::RC_USE_CONVERTER_CACHE },
-       { "\\use_escape_chars", LyXRC::RC_USE_ESC_CHARS },
-       { "\\use_input_encoding", LyXRC::RC_USE_INP_ENC },
        { "\\use_lastfilepos", LyXRC::RC_USELASTFILEPOS },
-       { "\\use_personal_dictionary", LyXRC::RC_USE_PERS_DICT },
        { "\\use_pixmap_cache", LyXRC::RC_USE_PIXMAP_CACHE },
        // compatibility with versions older than 1.4.0 only
-       { "\\use_pspell", LyXRC::RC_USE_SPELL_LIB },
        { "\\use_system_colors", LyXRC::RC_USE_SYSTEM_COLORS },
-       // compatibility with versions older than 1.4.0 only
-       { "\\use_tempdir", LyXRC::RC_USETEMPDIR },
        { "\\use_tooltip", LyXRC::RC_USE_TOOLTIP },
        { "\\user_email", LyXRC::RC_USER_EMAIL },
        { "\\user_name", LyXRC::RC_USER_NAME },
@@ -211,7 +203,8 @@
        // compatibility with versions older than 1.4.0 only
        { "\\viewer", LyXRC::RC_VIEWER},
        { "\\viewer_alternatives", LyXRC::RC_VIEWER_ALTERNATIVES },
-       { "\\visual_cursor" ,LyXRC::RC_VISUAL_CURSOR}
+       { "\\visual_cursor", LyXRC::RC_VISUAL_CURSOR },
+       { "format", LyXRC::RC_LYXRCFORMAT }
 };
 
 const int lyxrcCount = sizeof(lyxrcTags) / sizeof(lyxrcTags[0]);
@@ -384,42 +377,53 @@
 } // namespace anon
 
 
-int LyXRC::read(FileName const & filename)
+bool LyXRC::read(FileName const & filename)
 {
        Lexer lexrc(lyxrcTags);
-       if (lyxerr.debugging(Debug::PARSER))
-               lexrc.printTable(lyxerr);
-
        lexrc.setFile(filename);
-       if (!lexrc.isOK())
-               return -2;
-
        LYXERR(Debug::LYXRC, "Reading '" << filename << "'...");
-
-       return read(lexrc);
+       ReturnValues retval = read(lexrc);
+       if (retval != FormatMismatch)
+               return retval == ReadOK;
+
+       LYXERR(Debug::FILES, "Converting LyXRC file to " << LYXRC_FILEFORMAT);
+       FileName const tempfile = FileName::tempName("convert_lyxrc");
+       bool const success = prefs2prefs(filename, tempfile, false);
+       if (!success) {
+               LYXERR0 ("Unable to convert " << filename.absFileName() <<
+                       " to format " << LYXRC_FILEFORMAT);
+               return false;
+       }
+       Lexer lexrc2(lyxrcTags);
+       lexrc2.setFile(tempfile);
+       LYXERR(Debug::LYXRC, "Reading '" << tempfile << "'...");
+       retval = read(lexrc2);
+       tempfile.removeFile();
+       return retval == ReadOK;
 }
 
 
-int LyXRC::read(istream & is)
+// don't need to worry about conversion, because this is always
+// from an internal source
+bool LyXRC::read(istream & is)
 {
        Lexer lexrc(lyxrcTags);
-       if (lyxerr.debugging(Debug::PARSER))
-               lexrc.printTable(lyxerr);
-
        lexrc.setStream(is);
-       if (!lexrc.isOK())
-               return -2;
-
        LYXERR(Debug::LYXRC, "Reading istream...");
-
-       return read(lexrc);
+       return read(lexrc) == ReadOK;
 }
 
 
-int LyXRC::read(Lexer & lexrc)
+LyXRC::ReturnValues LyXRC::read(Lexer & lexrc)
 {
+       if (lyxerr.debugging(Debug::PARSER))
+               lexrc.printTable(lyxerr);
+
        if (!lexrc.isOK())
-               return -2;
+               return ReadError;
+
+       // format prior to 2.0 and introduction of format tag
+       unsigned int format = 0;
 
        while (lexrc.isOK()) {
                // By using two switches we take advantage of the compiler
@@ -440,6 +444,10 @@
                        break;
                }
                switch (static_cast<LyXRCTags>(le)) {
+               case RC_LYXRCFORMAT:
+                       if (lexrc.next())
+                               format = lexrc.getInteger();
+                       break;
                case RC_INPUT: // Include file
                        if (lexrc.next()) {
                                FileName const tmp =
@@ -1051,7 +1059,7 @@
                        formats.setViewer(format, command);
                        break;
                }
-               case RC_FORMAT: {
+               case RC_FILEFORMAT: {
                        string format, extension, prettyname, shortcut;
                        lexrc >> format >> extension >> prettyname >> shortcut;
                        string viewer, editor;
@@ -1248,32 +1256,21 @@
                        }
                        break;
 
-               // Obsoteted in 1.4.0
-               case RC_USETEMPDIR:
-               // Obsoleted in 2.0
-               case RC_SPELL_COMMAND:
-               case RC_PERS_DICT:
-               case RC_PLAINTEXT_ROFF_COMMAND: 
-               case RC_USE_ALT_LANG:
-               case RC_USE_ESC_CHARS:
-               case RC_USE_INP_ENC:
-               case RC_USE_PERS_DICT:
-               case RC_USE_SPELL_LIB:
-                       LYXERR(Debug::LYXRC, "Skipping obsolete tag `" 
-                              << lexrc.getString() << "'.");
-                       lexrc.next(true);
-                       break;
-
                case RC_LAST:
                        break; // this is just a dummy
                }
+
+               // This is triggered the first time through the loop unless
+               // we hit a format tag.
+               if (format != LYXRC_FILEFORMAT)
+                       return FormatMismatch;
        }
 
        /// Update converters data-structures
        theConverters().update(formats);
        theConverters().buildGraph();
 
-       return 0;
+       return ReadOK;
 }
 
 
@@ -1336,8 +1333,8 @@
        if (tag == RC_LAST)
                os << "# LyX " << lyx_version
                   << " generated this file. If you want to make your own\n"
-                  << "# modifications you should do them from inside LyX and 
save.\n"
-                  << "\n";
+                  << "# modifications you should do them from inside LyX and 
save.\n\n"
+                  << "Format " << LYXRC_FILEFORMAT << "\n\n";
 
        // Why the switch you might ask. It is a trick to ensure that all
        // the elements in the LyXRCTags enum are handled. As you can see
@@ -1348,6 +1345,7 @@
        case RC_LAST:
        case RC_INPUT:
                // input/include files are not done here
+       case RC_LYXRCFORMAT:
        case RC_BINDFILE:
                if (ignore_system_lyxrc ||
                    bind_file != system_lyxrc.bind_file) {
@@ -2349,13 +2347,6 @@
                }
                if (tag != RC_LAST)
                        break;
-       case RC_USETEMPDIR:
-               if (tag != RC_LAST)
-                       break;
-               // Ignore it
-       case RC_PLAINTEXT_ROFF_COMMAND: // Obsoleted in 2.0
-               if (tag != RC_LAST)
-                       break;
        case RC_PLAINTEXT_LINELEN:
                if (ignore_system_lyxrc ||
                    plaintext_linelen != system_lyxrc.plaintext_linelen) {
@@ -2394,11 +2385,6 @@
                   << "# SPELLCHECKER SECTION ##############################\n"
                   << "#\n\n";
 
-       case RC_SPELL_COMMAND:
-       case RC_USE_SPELL_LIB:
-               // Obsoleted in 2.0
-               if (tag != RC_LAST)
-                       break;
        case RC_ACCEPT_COMPOUND:
                if (ignore_system_lyxrc ||
                    spellchecker_accept_compound != 
system_lyxrc.spellchecker_accept_compound) {
@@ -2407,10 +2393,6 @@
                }
                if (tag != RC_LAST)
                        break;
-       case RC_USE_ALT_LANG:
-               // Obsoleted in 2.0
-               if (tag != RC_LAST)
-                       break;
        case RC_ALT_LANG:
                if (ignore_system_lyxrc ||
                    spellchecker_alt_lang != 
system_lyxrc.spellchecker_alt_lang) {
@@ -2419,9 +2401,6 @@
                }
                if (tag != RC_LAST)
                        break;
-       case RC_USE_ESC_CHARS:
-               if (tag != RC_LAST)
-                       break;
        case RC_ESC_CHARS:
                if (ignore_system_lyxrc ||
                    spellchecker_esc_chars != 
system_lyxrc.spellchecker_esc_chars) {
@@ -2429,10 +2408,6 @@
                }
                if (tag != RC_LAST)
                        break;
-       case RC_USE_PERS_DICT:
-               // obsoleted in 2.0
-               if (tag != RC_LAST)
-                       break;
        case RC_USE_SYSTEM_COLORS:
                if (ignore_system_lyxrc ||
                    use_system_colors != system_lyxrc.use_system_colors) {
@@ -2460,14 +2435,6 @@
                }
                if (tag != RC_LAST)
                        break;
-       case RC_PERS_DICT:
-               // obsoleted in 2.0
-               if (tag != RC_LAST)
-                       break;
-       case RC_USE_INP_ENC:
-               // obsoleted in 2.0
-               if (tag != RC_LAST)
-                       break;
 
                os << "\n#\n"
                   << "# LANGUAGE SUPPORT SECTION ##########################\n"
@@ -2689,7 +2656,7 @@
                   << "# FORMATS SECTION ##########################\n"
                   << "#\n\n";
 
-       case RC_FORMAT:
+       case RC_FILEFORMAT:
                // New/modified formats
                for (Formats::const_iterator cit = formats.begin();
                     cit != formats.end(); ++cit) {
@@ -2866,7 +2833,6 @@
        case LyXRC::RC_ACCEPT_COMPOUND:
        case LyXRC::RC_ALT_LANG:
        case LyXRC::RC_PLAINTEXT_LINELEN:
-       case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
        case LyXRC::RC_AUTOCORRECTION_MATH:
        case LyXRC::RC_AUTOREGIONDELETE:
        case LyXRC::RC_AUTORESET_OPTIONS:
@@ -2912,7 +2878,7 @@
        case LyXRC::RC_ESC_CHARS:
        case LyXRC::RC_EXAMPLEPATH:
        case LyXRC::RC_FONT_ENCODING:
-       case LyXRC::RC_FORMAT:
+       case LyXRC::RC_FILEFORMAT:
        case LyXRC::RC_GROUP_LAYOUTS:
        case LyXRC::RC_HUNSPELLDIR_PATH:
        case LyXRC::RC_INDEX_ALTERNATIVES:
@@ -2932,6 +2898,7 @@
        case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
        case LyXRC::RC_LANGUAGE_CUSTOM_PACKAGE:
        case LyXRC::RC_LANGUAGE_PACKAGE_SELECTION:
+       case LyXRC::RC_LYXRCFORMAT:
        case LyXRC::RC_MAC_DONTSWAP_CTRL_META:
        case LyXRC::RC_MAC_LIKE_WORD_MOVEMENT:
        case LyXRC::RC_MACRO_EDIT_STYLE:
@@ -2944,7 +2911,6 @@
                if (lyxrc_orig.path_prefix != lyxrc_new.path_prefix) {
                        prependEnvPath("PATH", lyxrc.path_prefix);
                }
-       case LyXRC::RC_PERS_DICT:
        case LyXRC::RC_PREVIEW:
        case LyXRC::RC_PREVIEW_HASHED_LABELS:
        case LyXRC::RC_PREVIEW_SCALE_FACTOR:
@@ -2983,7 +2949,6 @@
        case LyXRC::RC_SET_COLOR:
        case LyXRC::RC_SHOW_BANNER:
        case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
-       case LyXRC::RC_SPELL_COMMAND:
        case LyXRC::RC_SPELLCHECKER:
        case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
        case LyXRC::RC_SPELLCHECK_NOTES:
@@ -2999,16 +2964,10 @@
        case LyXRC::RC_UIFILE:
        case LyXRC::RC_USER_EMAIL:
        case LyXRC::RC_USER_NAME:
-       case LyXRC::RC_USETEMPDIR:
-       case LyXRC::RC_USE_ALT_LANG:
        case LyXRC::RC_USE_CONVERTER_CACHE:
-       case LyXRC::RC_USE_ESC_CHARS:
-       case LyXRC::RC_USE_INP_ENC:
-       case LyXRC::RC_USE_PERS_DICT:
        case LyXRC::RC_USE_SYSTEM_COLORS:
        case LyXRC::RC_USE_TOOLTIP:
        case LyXRC::RC_USE_PIXMAP_CACHE:
-       case LyXRC::RC_USE_SPELL_LIB:
        case LyXRC::RC_VIEWDVI_PAPEROPTION:
        case LyXRC::RC_SINGLE_CLOSE_TAB_BUTTON:
        case LyXRC::RC_SINGLE_INSTANCE:
@@ -3044,14 +3003,9 @@
                break;
 
        case RC_ALT_LANG:
-       case RC_USE_ALT_LANG:
                str = _("Specify an alternate language. The default is to use 
the language of the document.");
                break;
 
-       case RC_PLAINTEXT_ROFF_COMMAND:
-               str = _("Use to define an external program to render tables in 
plain text output. E.g. \"groff -t -Tlatin1 $$FName\" where $$FName is the 
input file. If \"\" is specified, an internal routine is used.");
-               break;
-
        case RC_PLAINTEXT_LINELEN:
                str = _("The maximum line length of exported plain 
text/LaTeX/SGML files. If set to 0, paragraphs are output in a single line; if 
the line length is > 0, paragraphs are separated by a blank line.");
                break;
@@ -3155,7 +3109,6 @@
                break;
 
        case RC_ESC_CHARS:
-       case RC_USE_ESC_CHARS:
                str = _("Specify additional chars that can be part of a word.");
                break;
 
@@ -3167,7 +3120,7 @@
                str = _("The font encoding used for the LaTeX2e fontenc 
package. T1 is highly recommended for non-English languages.");
                break;
 
-       case RC_FORMAT:
+       case RC_FILEFORMAT:
                break;
 
        case RC_INDEX_COMMAND:
@@ -3458,9 +3411,6 @@
        case RC_USER_NAME:
                break;
 
-       case RC_USETEMPDIR:
-               break;
-
        case RC_USE_USE_SYSTEM_COLORS:
                str = _("Enable use the system colors for some things like main 
window background and selection.");
                break;
@@ -3473,9 +3423,6 @@
                str = _("Enable the pixmap cache that might improve performance 
on Mac and Windows.");
                break;
 
-       case RC_USE_SPELL_LIB:
-               break;
-
        case RC_VIEWDVI_PAPEROPTION:
                _("Specify the paper command to DVI viewer (leave empty or use 
\"-paper\")");
                break;

Modified: lyx-devel/trunk/src/LyXRC.h
==============================================================================
--- lyx-devel/trunk/src/LyXRC.h Sun Jan 16 20:55:03 2011        (r37232)
+++ lyx-devel/trunk/src/LyXRC.h Sun Jan 16 21:28:43 2011        (r37233)
@@ -79,7 +79,7 @@
                RC_EXAMPLEPATH,
                RC_EXPORT_OVERWRITE,
                RC_FONT_ENCODING,
-               RC_FORMAT,
+               RC_FILEFORMAT,
                RC_FORWARD_SEARCH_DVI,
                RC_FORWARD_SEARCH_PDF,
                RC_FULL_SCREEN_LIMIT,
@@ -109,6 +109,7 @@
                RC_LANGUAGE_CUSTOM_PACKAGE,
                RC_LANGUAGE_PACKAGE_SELECTION,
                RC_LOADSESSION,
+               RC_LYXRCFORMAT,
                RC_MACRO_EDIT_STYLE,
                RC_MAC_DONTSWAP_CTRL_META,
                RC_MAC_LIKE_WORD_MOVEMENT,
@@ -120,9 +121,7 @@
                RC_OPEN_BUFFERS_IN_TABS,
                RC_PARAGRAPH_MARKERS,
                RC_PATH_PREFIX,
-               RC_PERS_DICT,
                RC_PLAINTEXT_LINELEN,
-               RC_PLAINTEXT_ROFF_COMMAND,
                RC_PREVIEW,
                RC_PREVIEW_HASHED_LABELS,
                RC_PREVIEW_SCALE_FACTOR,
@@ -164,7 +163,6 @@
                RC_SINGLE_CLOSE_TAB_BUTTON,
                RC_SINGLE_INSTANCE,
                RC_SORT_LAYOUTS,
-               RC_SPELL_COMMAND,
                RC_SPELLCHECK_CONTINUOUSLY,
                RC_SPELLCHECK_NOTES,
                RC_SPELLCHECKER,
@@ -178,16 +176,10 @@
                RC_USELASTFILEPOS,
                RC_USER_EMAIL,
                RC_USER_NAME,
-               RC_USETEMPDIR,
-               RC_USE_ALT_LANG,
                RC_USE_CONVERTER_CACHE,
-               RC_USE_ESC_CHARS,
-               RC_USE_INP_ENC,
-               RC_USE_PERS_DICT,
                RC_USE_SYSTEM_COLORS,
                RC_USE_TOOLTIP,
                RC_USE_PIXMAP_CACHE,
-               RC_USE_SPELL_LIB,
                RC_VIEWDVI_PAPEROPTION,
                RC_VIEWER,
                RC_VIEWER_ALTERNATIVES,
@@ -200,16 +192,24 @@
        ///
        void setDefaults();
        ///
-       int read(support::FileName const & filename);
+       bool read(support::FileName const & filename);
        ///
-       int read(std::istream &);
+       bool read(std::istream &);
 private:
+       enum ReturnValues {
+               ReadOK,
+               FileError,
+               ReadError,
+               FormatMismatch
+       };
+       ///
+       ReturnValues readWithoutConv(support::FileName const &);
        ///
-       int read(Lexer &);
+       ReturnValues read(Lexer &);
 public:
-       /// 
+       ///
        typedef std::set<std::string> CommandSet;
-       /// maps a format to a set of commands that can be used to 
+       /// maps a format to a set of commands that can be used to
        /// edit or view it.
        typedef std::map<std::string, CommandSet> Alternatives;
        ///
@@ -217,7 +217,7 @@
                   bool ignore_system_lyxrc) const;
        /// write rc. If a specific tag is given, only output that one.
        void write(std::ostream & os,
-                  bool ignore_system_lyxrc, 
+                  bool ignore_system_lyxrc,
                   std::string const & tag = std::string()) const;
        ///
        void print() const;

Modified: lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp        Sun Jan 16 
20:55:03 2011        (r37232)
+++ lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp        Sun Jan 16 
21:28:43 2011        (r37233)
@@ -1419,7 +1419,7 @@
                LyXRC const lyxrc_orig = lyxrc;
 
                istringstream ss(to_utf8(cmd.argument()));
-               bool const success = lyxrc.read(ss) == 0;
+               bool const success = lyxrc.read(ss);
 
                if (!success) {
                        lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"

Reply via email to