+2002-05-30 John Levon <moz@compsoc.man.ac.uk>
+
+ * buffer.h:
+ * buffer.C:
+ * lyx_main.C: fix a crash on bad command line,
+ and give a useful exit status on error
+
+ * lyxfunc.C (doImport): allow -i lyx to work
+
2002-03-30 André Pönitz <poenitz@gmx.net>
* lyxfunc.C: mathed font changes
}
-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;
/** 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 *);
lyxerr << _("Wrong command line option `")
<< argv[argi]
<< _("'. Exiting.") << endl;
- exit(0);
+ exit(1);
}
}
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
lyxerr << _("List of supported debug flags:")
<< endl;
Debug::showTags(lyxerr);
- exit(0);
+ exit(1);
}
}
// Check for "-sysdir"
} else {
lyxerr << _("Missing directory for -sysdir switch!")
<< endl;
- exit(0);
+ exit(1);
}
}
// Check for "-userdir"
} else {
lyxerr << _("Missing directory for -userdir switch!")
<< endl;
- exit(0);
+ exit(1);
}
}
// Check for --help or -help
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") {
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") {
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) {
}
-// checks for running without gui are missing.
void LyXFunc::doImport(string const & argument)
{
string format;
string filename = split(argument, format, ' ');
+
lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
<< " file: " << filename << endl;
-
- if (filename.empty()) { // need user interaction
+
+ // need user interaction
+ if (filename.empty()) {
string initpath = lyxrc.document_path;
if (owner->view()->available()) {
owner->message(_("Canceled."));
}
- // still no filename? abort
if (filename.empty())
return;
string const lyxfile = ChangeExtension(filename, ".lyx");
// Check if the document already is open
- if (bufferlist.exists(lyxfile)) {
+ if (lyxrc.use_gui && bufferlist.exists(lyxfile)) {
switch (Alert::askConfirmation(_("Document is already open:"),
MakeDisplayPath(lyxfile, 50),
_("Do you want to close that document now?\n"
"('No' will just switch to the open version)")))
{
- case 1: // Yes: close the document
- if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
+ case 1:
// If close is canceled, we cancel here too.
+ if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
return;
break;
- case 2: // No: switch to the open document
+ case 2:
owner->view()->buffer(bufferlist.getBuffer(lyxfile));
return;
- case 3: // Cancel: Do nothing
+ case 3:
owner->message(_("Canceled."));
return;
}
}
- // Check if a LyX document by the same root exists in filesystem
- FileInfo const f(lyxfile, true);
- if (f.exist() && !Alert::askQuestion(_("A document by the name"),
- MakeDisplayPath(lyxfile),
- _("already exists. Overwrite?"))) {
- owner->message(_("Canceled"));
- return;
+ // if the file exists already, and we didn't do
+ // -i lyx thefile.lyx, warn
+ if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
+ if (!Alert::askQuestion(_("A document by the name"),
+ MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) {
+ owner->message(_("Canceled"));
+ return;
+ }
}
- // filename should be valid now
Importer::Import(owner, filename, format);
}