]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
include sys/time.h
[lyx.git] / src / lyx_main.C
index 2befa6620eec5e2976a77dba695a271c8968bd76..65bd38cb65ab16655c503d6ab51701075069a380 100644 (file)
@@ -9,10 +9,6 @@
 #include <config.h>
 #include <version.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "lyx_main.h"
 
 #include "support/filetools.h"
@@ -42,6 +38,7 @@
 #include "frontends/Alert.h"
 #include "frontends/lyx_gui.h"
 
+#include "BoostFormat.h"
 #include <boost/function.hpp>
 
 #include <cstdlib>
@@ -91,7 +88,7 @@ LyX::LyX(int & argc, char * argv[])
        // if this should not be in this file, please also remove
        // #include "graphics/GraphicsTypes.h" at the top -- Rob Lahaye.
        grfx::setDisplayTranslator();
-       
+
        if (want_gui) {
                lyx_gui::parse_init(argc, argv);
        }
@@ -100,9 +97,15 @@ LyX::LyX(int & argc, char * argv[])
        // other than documents
        for (int argi = 1; argi < argc ; ++argi) {
                if (argv[argi][0] == '-') {
+#if USE_BOOST_FORMAT
+                       lyxerr << boost::format(_("Wrong command line option `%1$s'. Exiting."))
+                               % argv[argi]
+                              << endl;
+#else
                        lyxerr << _("Wrong command line option `")
-                              << argv[argi]
-                              << _("'. Exiting.") << endl;
+                              << argv[argi] << _("'. Exiting.")
+                              << endl;
+#endif
                        exit(1);
                }
        }
@@ -129,7 +132,7 @@ LyX::LyX(int & argc, char * argv[])
        // Execute batch commands if available
        if (!batch_command.empty()) {
                lyxerr[Debug::INIT] << "About to handle -x '"
-                      << batch_command << "'" << endl;
+                      << batch_command << '\'' << endl;
 
                Buffer * last_loaded = 0;
 
@@ -287,8 +290,8 @@ void LyX::init(bool gui)
                FileInfo file(fullbinpath, true);
                followlink = file.isLink();
                if (followlink) {
-                       lyxerr << " directory " << fullbinpath
-                              << " is a link" << endl;
+                       lyxerr[Debug::INIT] << " directory " << fullbinpath
+                                           << " is a link" << endl;
                        string link;
                        if (LyXReadLink(fullbinpath, link, true)) {
                                fullbinpath = link;
@@ -354,9 +357,16 @@ void LyX::init(bool gui)
                                        << "Giving up." << endl;
                                exit(1);
                        }
-                       lyxerr << _("Using built-in default ")
-                              << LYX_DIR << _(" but expect problems.")
+#if USE_BOOST_FORMAT
+                       lyxerr << boost::format(_("Using built-in default %1$s"
+                                                 " but expect problems."))
+                               % static_cast<char *>(LYX_DIR)
+                              << endl;
+#else
+                       lyxerr << _("Using built-in default ") << LYX_DIR
+                              << _(" but expect problems.")
                               << endl;
+#endif
                } else {
                        lyxerr << _("Expect problems.") << endl;
                }
@@ -433,7 +443,7 @@ void LyX::init(bool gui)
        // If there is a preferences file we read that instead
        // of the old lyxrc file.
        if (!readRcFile("preferences"))
-           readRcFile("lyxrc");
+               readRcFile("lyxrc");
 
        readEncodingsFile("encodings");
        readLanguagesFile("languages");
@@ -449,11 +459,6 @@ void LyX::init(bool gui)
        // Read menus
        readUIFile(lyxrc.ui_file);
 
-       // Bind the X dead keys to the corresponding LyX functions if
-       // necessary.
-       if (lyxrc.override_x_deadkeys)
-               deadKeyBindings(toplevel_keymap.get());
-
        if (lyxerr.debugging(Debug::LYXRC)) {
                lyxrc.print();
        }
@@ -577,13 +582,13 @@ void LyX::queryUserLyXDir(bool explicit_userdir)
        FileInfo fileInfo(user_lyxdir);
        if (fileInfo.isOK() && fileInfo.isDir()) {
                first_start = false;
-               Path p(user_lyxdir);
                FileInfo script(configure_script);
-               FileInfo defaults("lyxrc.defaults");
-               if (!defaults.isOK()
-                   || defaults.getModificationTime() < script.getModificationTime()) {
+               FileInfo defaults(AddName(user_lyxdir, "lyxrc.defaults"));
+               if (defaults.isOK() && script.isOK()
+                   && defaults.getModificationTime() < script.getModificationTime()) {
                        lyxerr << _("LyX: reconfiguring user directory")
                               << endl;
+                       Path p(user_lyxdir);
                        ::system(configure_script.c_str());
                        lyxerr << "LyX: " << _("Done!") << endl;
                }
@@ -604,14 +609,29 @@ void LyX::queryUserLyXDir(bool explicit_userdir)
                return;
        }
 
+#if USE_BOOST_FORMAT
+       lyxerr << boost::format(_("LyX: Creating directory %1$s"
+                                 " and running configure..."))
+               % user_lyxdir
+              << endl;
+#else
        lyxerr << _("LyX: Creating directory ") << user_lyxdir
-              << _(" and running configure...") << endl;
+              << _(" and running configure...")
+              << endl;
+#endif
 
        if (!createDirectory(user_lyxdir, 0755)) {
                // Failed, let's use $HOME instead.
                user_lyxdir = GetEnvPath("HOME");
-               lyxerr << _("Failed. Will use ") << user_lyxdir
-                      << _(" instead.") << endl;
+#if USE_BOOST_FORMAT
+               lyxerr << boost::format(_("Failed. Will use %1$s instead."))
+                       % user_lyxdir
+                      << endl;
+#else
+               lyxerr << _("Failed. Will use ") << user_lyxdir <<
+                       _(" instead.")
+                      << endl;
+#endif
                return;
        }
 
@@ -631,9 +651,15 @@ bool LyX::readRcFile(string const & name)
                lyxerr[Debug::INIT] << "Found " << name
                                    << " in " << lyxrc_path << endl;
                if (lyxrc.read(lyxrc_path) < 0) {
+#if USE_BOOST_FORMAT
                        Alert::alert(_("LyX Warning!"),
-                                  _("Error while reading ") + lyxrc_path + ".",
+                                  boost::io::str(boost::format(_("Error while reading %1$s.")) % lyxrc_path),
                                   _("Using built-in defaults."));
+#else
+                       Alert::alert(_("LyX Warning!"),
+                                  _("Error while reading ") + lyxrc_path,
+                                  _("Using built-in defaults."));
+#endif
                        return false;
                }
                return true;
@@ -736,7 +762,7 @@ bool is_gui = true;
 string batch;
 
 /// return the the number of arguments consumed
-typedef boost::function<int, string const &, string const &> cmd_helper;
+typedef boost::function<int(string const &, string const &)> cmd_helper;
 
 int parse_dbg(string const & arg, string const &)
 {
@@ -745,7 +771,14 @@ int parse_dbg(string const & arg, string const &)
                Debug::showTags(lyxerr);
                exit(0);
        }
+#if USE_BOOST_FORMAT
+       lyxerr << boost::format(_("Setting debug level to %1$s"))
+               % arg
+              << endl;
+#else
        lyxerr << _("Setting debug level to ") << arg << endl;
+#endif
+
        lyxerr.level(Debug::value(arg));
        Debug::showLevel(lyxerr, lyxerr.level());
        return 1;
@@ -844,7 +877,7 @@ int parse_import(string const & type, string const & file)
                exit(1);
        }
 
-       batch = "buffer-import " + type + " " + file;
+       batch = "buffer-import " + type + ' ' + file;
        return 2;
 }