The below fixes a crash, fixes the no-exit-status bug for a variety of things, and improves behaviour. OK for 1.2 brunch and trunk ?
btw, ./lyx -i latex blah.tex -e lyx blah.lyx still does nothing whilst claiming to succeed for me. regards john Index: src/buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.341 diff -u -r1.341 buffer.C --- src/buffer.C 29 May 2002 14:32:09 -0000 1.341 +++ src/buffer.C 29 May 2002 23:49:13 -0000 @@ -3893,24 +3893,28 @@ } -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; Index: src/buffer.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v retrieving revision 1.98 diff -u -r1.98 buffer.h --- src/buffer.h 26 May 2002 19:40:17 -0000 1.98 +++ src/buffer.h 29 May 2002 23:49:14 -0000 @@ -76,10 +76,10 @@ /** 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 *); Index: src/lyx_main.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_main.C,v retrieving revision 1.106 diff -u -r1.106 lyx_main.C --- src/lyx_main.C 23 May 2002 12:08:35 -0000 1.106 +++ src/lyx_main.C 29 May 2002 23:49:17 -0000 @@ -102,7 +102,7 @@ lyxerr << _("Wrong command line option `") << argv[argi] << _("'. Exiting.") << endl; - exit(0); + exit(1); } } @@ -154,15 +154,16 @@ 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 @@ lyxerr << _("List of supported debug flags:") << endl; Debug::showTags(lyxerr); - exit(0); + exit(1); } } // Check for "-sysdir" @@ -846,7 +847,7 @@ } else { lyxerr << _("Missing directory for -sysdir switch!") << endl; - exit(0); + exit(1); } } // Check for "-userdir" @@ -857,7 +858,7 @@ } else { lyxerr << _("Missing directory for -userdir switch!") << endl; - exit(0); + exit(1); } } // Check for --help or -help @@ -870,6 +871,7 @@ 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 @@ 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 @@ 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) {