]> git.lyx.org Git - lyx.git/blobdiff - src/LyX.cpp
Update tex2lyx tests.
[lyx.git] / src / LyX.cpp
index d81c90f6ff95c8061a785162e9b8ec79f44d6c2f..259aeb6657e69ead89a024bef9e3d77bc7b14de2 100644 (file)
 #include "support/Messages.h"
 #include "support/os.h"
 #include "support/Package.h"
-
-#include "support/bind.h"
-#include <boost/scoped_ptr.hpp>
+#include "support/unique_ptr.h"
 
 #include <algorithm>
-#include <iostream>
 #include <csignal>
+#include <iostream>
+#include <functional>
 #include <map>
 #include <stdlib.h>
 #include <string>
@@ -93,6 +92,19 @@ namespace os = support::os;
 bool use_gui = true;
 
 
+// Report on the terminal about spawned commands. The default is false
+// and can be changed with the option -v (--verbose).
+
+bool verbose = false;
+
+
+// Do not treat the "missing glyphs" warning of fontspec as an error message.
+// The default is false and can be changed with the option
+// --ignore-error-message missing_glyphs
+// This is used in automated testing.
+bool ignore_missing_glyphs = false;
+
+
 // We default to open documents in an already running instance, provided that
 // the lyxpipe has been setup. This can be overridden either on the command
 // line or through preference settings.
@@ -150,13 +162,13 @@ struct LyX::Impl {
        ///
        CmdDef toplevel_cmddef_;
        ///
-       boost::scoped_ptr<Server> lyx_server_;
+       unique_ptr<Server> lyx_server_;
        ///
-       boost::scoped_ptr<ServerSocket> lyx_socket_;
+       unique_ptr<ServerSocket> lyx_socket_;
        ///
-       boost::scoped_ptr<frontend::Application> application_;
+       unique_ptr<frontend::Application> application_;
        /// lyx session, containing lastfiles, lastfilepos, and lastopened
-       boost::scoped_ptr<Session> session_;
+       unique_ptr<Session> session_;
 
        /// Files to load at start.
        vector<string> files_to_load_;
@@ -229,7 +241,6 @@ LyX::~LyX()
 {
        delete pimpl_;
        singleton_ = 0;
-       WordList::cleanupWordLists();
 }
 
 
@@ -472,21 +483,51 @@ int LyX::execWithoutGui(int & argc, char * argv[])
                return exit_status;
        }
 
-       // this is correct, since return values are inverted.
-       exit_status = !loadFiles();
+       // Used to keep track of which buffers were explicitly loaded by user request.
+       // This is necessary because master and child document buffers are loaded, even 
+       // if they were not named on the command line. We do not want to dispatch to
+       // those.
+       vector<Buffer *> command_line_buffers;
+
+       // Load the files specified on the command line
+       vector<string>::const_iterator it = pimpl_->files_to_load_.begin();
+       vector<string>::const_iterator end = pimpl_->files_to_load_.end();
+       for (; it != end; ++it) {
+               // get absolute path of file and add ".lyx" to the filename if necessary
+               FileName fname = fileSearch(string(), os::internal_path(*it), "lyx",
+                                                                                                                               may_not_exist);
+
+               if (fname.empty())
+                       continue;
+
+               Buffer * buf = pimpl_->buffer_list_.newBuffer(fname.absFileName());
+               LYXERR(Debug::FILES, "Loading " << fname);
+               if (buf && buf->loadLyXFile() == Buffer::ReadSuccess) {
+                       ErrorList const & el = buf->errorList("Parse");
+                       for(ErrorItem const & e : el)
+                               printError(e);
+                       command_line_buffers.push_back(buf);
+               } else {
+                       if (buf)
+                               pimpl_->buffer_list_.release(buf);
+                       docstring const error_message =
+                                       bformat(_("LyX failed to load the following file: %1$s"),
+                                                                       from_utf8(fname.absFileName()));
+                       lyxerr << to_utf8(error_message) << endl;
+                       exit_status = 1; // failed
+               }
+       }
 
-       if (pimpl_->batch_commands.empty() || pimpl_->buffer_list_.empty()) {
+       if (exit_status || pimpl_->batch_commands.empty() || pimpl_->buffer_list_.empty()) {
                prepareExit();
                return exit_status;
        }
 
-       BufferList::iterator begin = pimpl_->buffer_list_.begin();
-
+       // Iterate through the buffers that were specified on the command line
        bool final_success = false;
-       for (BufferList::iterator I = begin; I != pimpl_->buffer_list_.end(); ++I) {
-               Buffer * buf = *I;
-               if (buf != buf->masterBuffer())
-                       continue;
+       vector<Buffer *>::iterator buf_it = command_line_buffers.begin();
+       for (; buf_it != command_line_buffers.end(); ++buf_it) {
+               Buffer * buf = *buf_it;
                vector<string>::const_iterator bcit  = pimpl_->batch_commands.begin();
                vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
                DispatchResult dr;
@@ -501,42 +542,6 @@ int LyX::execWithoutGui(int & argc, char * argv[])
 }
 
 
-bool LyX::loadFiles()
-{
-       LATTEST(!use_gui);
-       bool success = true;
-       vector<string>::const_iterator it = pimpl_->files_to_load_.begin();
-       vector<string>::const_iterator end = pimpl_->files_to_load_.end();
-
-       for (; it != end; ++it) {
-               // get absolute path of file and add ".lyx" to
-               // the filename if necessary
-               FileName fname = fileSearch(string(), os::internal_path(*it), "lyx",
-                       may_not_exist);
-
-               if (fname.empty())
-                       continue;
-
-               Buffer * buf = pimpl_->buffer_list_.newBuffer(fname.absFileName());
-               if (buf->loadLyXFile() == Buffer::ReadSuccess) {
-                       ErrorList const & el = buf->errorList("Parse");
-                       if (!el.empty())
-                               for_each(el.begin(), el.end(),
-                               bind(&LyX::printError, this, _1));
-               }
-               else {
-                       pimpl_->buffer_list_.release(buf);
-                       docstring const error_message =
-                               bformat(_("LyX failed to load the following file: %1$s"),
-                               from_utf8(fname.absFileName()));
-                       lyxerr << to_utf8(error_message) << endl;
-                       success = false;
-               }
-       }
-       return success;
-}
-
-
 void execBatchCommands()
 {
        LAPPERR(singleton_);
@@ -832,7 +837,7 @@ bool LyX::init()
 #endif
 
        lyxrc.tempdir_path = package().temp_dir().absFileName();
-       lyxrc.document_path = package().document_dir().absFileName();
+       lyxrc.document_path = ".";
 
        if (lyxrc.example_path.empty()) {
                lyxrc.example_path = addPath(package().system_support().absFileName(),
@@ -1115,7 +1120,7 @@ bool LyX::readEncodingsFile(string const & enc_name,
 namespace {
 
 /// return the the number of arguments consumed
-typedef boost::function<int(string const &, string const &, string &)> cmd_helper;
+typedef function<int(string const &, string const &, string &)> cmd_helper;
 
 int parse_dbg(string const & arg, string const &, string &)
 {
@@ -1163,11 +1168,17 @@ int parse_help(string const &, string const &, string &)
                  "                  specifying whether all files, main file only, or no files,\n"
                  "                  respectively, are to be overwritten during a batch export.\n"
                  "                  Anything else is equivalent to `all', but is not consumed.\n"
+                 "\t--ignore-error-message which\n"
+                 "                  allows you to ignore specific LaTeX error messages.\n"
+                 "                  Do not use for final documents! Currently supported values:\n"
+                  "                  * missing_glyphs: Fontspec `missing glyphs' error.\n"
                  "\t-n [--no-remote]\n"
                  "                  open documents in a new instance\n"
                  "\t-r [--remote]\n"
                  "                  open documents in an already running instance\n"
                  "                  (a working lyxpipe is needed)\n"
+                 "\t-v [--verbose]\n"
+                 "                  report on terminal about spawned commands.\n"
                  "\t-batch    execute commands without launching GUI and exit.\n"
                  "\t-version  summarize version and build info\n"
                               "Check the LyX man page for more details.")) << endl;
@@ -1302,6 +1313,23 @@ int parse_remote(string const &, string const &, string &)
 }
 
 
+int parse_verbose(string const &, string const &, string &)
+{
+       verbose = true;
+       return 0;
+}
+
+
+int parse_ignore_error_message(string const & arg1, string const &, string &)
+{
+       if (arg1 == "missing_glyphs") {
+               ignore_missing_glyphs = true;
+               return 1;
+       }
+       return 0;
+}
+
+
 int parse_force(string const & arg, string const &, string &)
 {
        if (arg == "all") {
@@ -1349,6 +1377,9 @@ void LyX::easyParse(int & argc, char * argv[])
        cmdmap["--no-remote"] = parse_noremote;
        cmdmap["-r"] = parse_remote;
        cmdmap["--remote"] = parse_remote;
+       cmdmap["-v"] = parse_verbose;
+       cmdmap["--verbose"] = parse_verbose;
+       cmdmap["--ignore-error-message"] = parse_ignore_error_message;
 
        for (int i = 1; i < argc; ++i) {
                map<string, cmd_helper>::const_iterator it
@@ -1421,7 +1452,7 @@ Server & theServer()
        // FIXME: this should not be use_gui dependent
        LWARNIF(use_gui);
        LAPPERR(singleton_);
-       return *singleton_->pimpl_->lyx_server_.get();
+       return *singleton_->pimpl_->lyx_server_;
 }
 
 
@@ -1430,7 +1461,7 @@ ServerSocket & theServerSocket()
        // FIXME: this should not be use_gui dependent
        LWARNIF(use_gui);
        LAPPERR(singleton_);
-       return *singleton_->pimpl_->lyx_socket_.get();
+       return *singleton_->pimpl_->lyx_socket_;
 }