From b121ac47c6c578ae9e2e3e073222e73859603edc Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Mon, 19 Apr 2010 23:53:23 +0000 Subject: [PATCH] Introduce a switch for overwriting files during a batch export. Using "-f all", or simply "-f", all files are silently overwritten. Using "-f main", only the main file is overwritten. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34224 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 5 ++++- src/LyX.cpp | 28 ++++++++++++++++++++++++++++ src/LyX.h | 7 +++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index b0688cb318..1d52a823b5 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -3377,7 +3377,8 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir, vector const files = runparams.exportdata->externalFiles(format); string const dest = onlyPath(result_file); - CopyStatus status = SUCCESS; + CopyStatus status = !use_gui && force_overwrite == ALL_FILES ? FORCE + : SUCCESS; vector::const_iterator it = files.begin(); vector::const_iterator const en = files.end(); @@ -3392,6 +3393,8 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir, message(_("Document export cancelled.")); } else if (tmp_result_file.exists()) { // Finally copy the main file + if (!use_gui && force_overwrite != NO_FILES) + status = FORCE; status = copyFile(format, tmp_result_file, FileName(result_file), result_file, status == FORCE); diff --git a/src/LyX.cpp b/src/LyX.cpp index 7fa0916417..15ef92eff0 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -88,6 +88,13 @@ namespace os = support::os; bool use_gui = true; + +// Tell what files can be silently overwritten during batch export. +// Possible values are: NO_FILES, MAIN_FILE, ALL_FILES. + +overwrite_files force_overwrite = NO_FILES; + + namespace { // Filled with the command line arguments "foo" of "-sysdir foo" or @@ -1000,6 +1007,11 @@ int parse_help(string const &, string const &, string &) "\t-i [--import] fmt file.xxx\n" " where fmt is the import format of choice\n" " and file.xxx is the file to be imported.\n" + "\t-f [--force-overwrite] what\n" + " where what is either `all' or `main'.\n" + " Using `all', all files are overwritten during\n" + " a batch export, otherwise only the main file will be.\n" + " Anything else is equivalent to `all', but is not consumed.\n" "\t-batch execute commands without launching GUI and exit.\n" "\t-version summarize version and build info\n" "Check the LyX man page for more details.")) << endl; @@ -1102,6 +1114,20 @@ int parse_batch(string const &, string const &, string &) } +int parse_force(string const & arg, string const &, string &) +{ + if (arg == "all") { + force_overwrite = ALL_FILES; + return 1; + } else if (arg == "main") { + force_overwrite = MAIN_FILE; + return 1; + } + force_overwrite = ALL_FILES; + return 0; +} + + } // namespace anon @@ -1124,6 +1150,8 @@ void LyX::easyParse(int & argc, char * argv[]) cmdmap["--import"] = parse_import; cmdmap["-geometry"] = parse_geometry; cmdmap["-batch"] = parse_batch; + cmdmap["-f"] = parse_force; + cmdmap["--force-overwrite"] = parse_force; for (int i = 1; i < argc; ++i) { map::const_iterator it diff --git a/src/LyX.h b/src/LyX.h index 238fe38de0..dd98a370a5 100644 --- a/src/LyX.h +++ b/src/LyX.h @@ -34,7 +34,14 @@ class ServerSocket; class Session; class SpellChecker; +enum overwrite_files { + NO_FILES, + MAIN_FILE, + ALL_FILES +}; + extern bool use_gui; +extern overwrite_files force_overwrite; namespace frontend { class Application; -- 2.39.2