+ // 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
+ }
+ }