From 8d2394b02c30aa6c4b99e04de3e9b46bf57d529a Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Fri, 18 Jul 2003 07:25:16 +0000 Subject: [PATCH] fix crash reported by Kayvan + ws git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7311 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++++ src/converter.C | 2 +- src/lyx_main.C | 28 ++++++++++++++++------------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index be4be662dd..dd6a846295 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-07-18 Alfredo Braunstein + + * lyx_main.C: fix a crash in batch mode if no files specified + * converter.C: ws + 2003-07-17 Alfredo Braunstein * format.[Ch] (papersize): moved to BufferParams diff --git a/src/converter.C b/src/converter.C index e585ed64e8..482059b7c1 100644 --- a/src/converter.C +++ b/src/converter.C @@ -602,7 +602,7 @@ Converters::getReachableTo(string const & target, bool clear_visited) vector const Converters::getReachable(string const & from, bool only_viewable, - bool clear_visited) + bool clear_visited) { vector const & reachables = G_.getReachable(formats.getNumber(from), diff --git a/src/lyx_main.C b/src/lyx_main.C index 5b51452750..2a6b9b84cc 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -142,6 +142,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; @@ -155,25 +156,28 @@ LyX::LyX(int & argc, char * argv[]) // the filename if necessary string s = FileSearch(string(), *it, "lyx"); if (s.empty()) { - s = *it; + last_loaded = newFile(*it, ""); + } else { + last_loaded = bufferlist.newBuffer(s, false); + last_loaded->error.connect(boost::bind(&LyX::printError, this, _1)); + if (!loadLyXFile(last_loaded, s)) { + bufferlist.release(last_loaded); + last_loaded = newFile(*it, string()); + } } - - last_loaded = bufferlist.newBuffer(s, false); - last_loaded->error.connect(boost::bind(&LyX::printError, this, _1)); - loadLyXFile(last_loaded, s); } - files.clear(); - bool success = false; // try to dispatch to last loaded buffer first - bool const dispatched = last_loaded->dispatch(batch_command, &success); + if (last_loaded) + last_loaded->dispatch(batch_command, &success); + else + lyxerr << _("Batch command specified but no " + "file loaded. Exiting.") << endl; - if (dispatched) { - QuitLyX(); - exit(!success); - } + QuitLyX(); + exit(!success); } lyx_gui::start(batch_command, files);