From 030e2e9765a1f499871b438f322c36003c05ba96 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 30 May 2002 20:25:58 +0000 Subject: [PATCH] Fix bug 55 and a crash with "./lyx -i latex" git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH-1_2_X@4304 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 7 +++++++ src/buffer.C | 14 +++++++++----- src/buffer.h | 4 ++-- src/lyx_main.C | 36 ++++++++++++++++++++++++------------ 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 840b3bdfb9..2c6aae4c1b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2002-05-30 John Levon + + * lyx_main.C: + * buffer.h: + * buffer.C: fix command line crash and give useful + exit status on some errors + 2002-05-24 Juergen Vigna * undo_funcs.C (textHandleUndo): fix the cursor selection after diff --git a/src/buffer.C b/src/buffer.C index 0f8d2601f0..6075470655 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -3883,24 +3883,28 @@ void Buffer::markDepClean(string const & name) } -bool Buffer::dispatch(string const & command) +bool Buffer::dispatch(string const & command, bool * result) { // Split command string into command and argument string cmd; string line = frontStrip(command); string const arg = strip(frontStrip(split(line, cmd, ' '))); - return dispatch(lyxaction.LookupFunc(cmd), arg); + return dispatch(lyxaction.LookupFunc(cmd), arg, result); } -bool Buffer::dispatch(int action, string const & argument) +bool Buffer::dispatch(int action, string const & argument, bool * result) { bool dispatched = true; + switch (action) { - case LFUN_EXPORT: - Exporter::Export(this, argument, false); + case LFUN_EXPORT: { + bool const tmp = Exporter::Export(this, argument, false); + if (result) + *result = tmp; break; + } default: dispatched = false; diff --git a/src/buffer.h b/src/buffer.h index f18e03e6f8..da4f4131c1 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -73,10 +73,10 @@ public: /** High-level interface to buffer functionality. This function parses a command string and executes it */ - bool dispatch(string const & command); + bool dispatch(string const & command, bool * result = 0); /// Maybe we know the function already by number... - bool dispatch(int ac, string const & argument); + bool dispatch(int ac, string const & argument, bool * result = 0); /// void resizeInsets(BufferView *); diff --git a/src/lyx_main.C b/src/lyx_main.C index 7f8e5bb0ba..8061a2e6b7 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -102,7 +102,7 @@ LyX::LyX(int * argc, char * argv[]) lyxerr << _("Wrong command line option `") << argv[argi] << _("'. Exiting.") << endl; - exit(0); + exit(1); } } @@ -154,15 +154,16 @@ LyX::LyX(int * argc, char * argv[]) if (!last_loaded) last_loaded = bufferlist.newFile("tmpfile", string()); + bool success = false; + // try to dispatch to last loaded buffer first - bool dispatched = last_loaded->dispatch(batch_command); + bool dispatched = last_loaded->dispatch(batch_command, &success); // if this was successful, return. // Maybe we could do something more clever than aborting... if (dispatched) { - lyxerr << "We are done!" << endl; QuitLyX(); - return; + exit(!success); } // otherwise, let the GUI handle the batch command @@ -835,7 +836,7 @@ bool LyX::easyParse(int * argc, char * argv[]) lyxerr << _("List of supported debug flags:") << endl; Debug::showTags(lyxerr); - exit(0); + exit(1); } } // Check for "-sysdir" @@ -846,7 +847,7 @@ bool LyX::easyParse(int * argc, char * argv[]) } else { lyxerr << _("Missing directory for -sysdir switch!") << endl; - exit(0); + exit(1); } } // Check for "-userdir" @@ -857,7 +858,7 @@ bool LyX::easyParse(int * argc, char * argv[]) } else { lyxerr << _("Missing directory for -userdir switch!") << endl; - exit(0); + exit(1); } } // Check for --help or -help @@ -870,6 +871,7 @@ bool LyX::easyParse(int * argc, char * argv[]) commandLineVersionInfo(); exit(0); } + // FIXME: why is this commented out ? // Check for "-nw": No XWindows as for emacs this should // give a LyX that could be used in a terminal window. //else if (arg == "-nw") { @@ -886,7 +888,8 @@ bool LyX::easyParse(int * argc, char * argv[]) lyxerr << _("Missing command string after -x switch!") << endl; // Argh. Setting gui to false segfaults.. - //gui = false; + // FIXME: when ? how ? + // gui = false; } else if (arg == "-e" || arg == "--export") { @@ -895,25 +898,34 @@ bool LyX::easyParse(int * argc, char * argv[]) removeargs = 2; batch_command = "buffer-export " + type; gui = false; - } else + } else { lyxerr << _("Missing file type [eg latex, " "ps...] after ") << arg << _(" switch!") << endl; + exit(1); + } } else if (arg == "-i" || arg == "--import") { if (i + 1 < *argc) { - string const type(argv[i+1]); + if (!argv[i+2]) { + lyxerr << _("Missing filename for --import") << endl; + exit(1); + } + string const file(argv[i+2]); + string const type(argv[i+1]); removeargs = 3; - + batch_command = "buffer-import " + type + " " + file; lyxerr << "batch_command: " << batch_command << endl; - } else + } else { lyxerr << _("Missing type [eg latex, " "ps...] after ") << arg << _(" switch!") << endl; + exit(1); + } } if (removeargs > 0) {