ControlPrint.cpp

LyXFunc.cpp
  Quote file paths in printer dialog
  Fix bug 3915: http://bugzilla.lyx.org/show_bug.cgi?id=3915
  (patch from Jürgen and JMarc)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18934 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2007-06-28 21:21:05 +00:00
parent 6e3ecc8a2f
commit e729c5ffee
2 changed files with 17 additions and 14 deletions

View File

@ -989,21 +989,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_BUFFER_PRINT: { case LFUN_BUFFER_PRINT: {
BOOST_ASSERT(lyx_view_ && lyx_view_->buffer()); BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
string target; // FIXME: cmd.getArg() might fail if one of the arguments
string target_name; // contains double quotes
string command = split(split(argument, target, ' '), string target = cmd.getArg(0);
target_name, ' '); string target_name = cmd.getArg(1);
string command = cmd.getArg(2);
if (target.empty() if (target.empty()
|| target_name.empty() || target_name.empty()
|| command.empty()) { || command.empty()) {
lyxerr << "Unable to parse \"" lyxerr << "Unable to parse \""
<< argument << '"' << std::endl; << argument << '"' << endl;
break; break;
} }
if (target != "printer" && target != "file") { if (target != "printer" && target != "file") {
lyxerr << "Unrecognized target \"" lyxerr << "Unrecognized target \""
<< target << '"' << std::endl; << target << '"' << endl;
break; break;
} }
@ -1035,13 +1036,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// case 3: print using a spool // case 3: print using a spool
string const psname = string const psname =
changeExtension(dviname,".ps"); changeExtension(dviname,".ps");
command += lyxrc.print_to_file command += ' ' + lyxrc.print_to_file
+ quoteName(psname) + quoteName(psname)
+ ' ' + ' '
+ quoteName(dviname); + quoteName(dviname);
string command2 = string command2 =
lyxrc.print_spool_command +' '; lyxrc.print_spool_command + ' ';
if (target_name != "default") { if (target_name != "default") {
command2 += lyxrc.print_spool_printerprefix command2 += lyxrc.print_spool_printerprefix
+ target_name + target_name
@ -1061,7 +1062,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} else { } else {
// case 2: print directly to a printer // case 2: print directly to a printer
if (target_name != "default") if (target_name != "default")
command += lyxrc.print_to_printer + target_name + ' '; command += ' ' + lyxrc.print_to_printer + target_name + ' ';
res = one.startscript( res = one.startscript(
Systemcall::DontWait, Systemcall::DontWait,
command + quoteName(dviname)); command + quoteName(dviname));
@ -1069,7 +1070,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} else { } else {
// case 1: print to a file // case 1: print to a file
FileName const filename(makeAbsPath(target_name, path)); FileName const filename(makeAbsPath(target_name,
lyx_view_->buffer()->filePath()));
FileName const dvifile(makeAbsPath(dviname, path));
if (fs::exists(filename.toFilesystemEncoding())) { if (fs::exists(filename.toFilesystemEncoding())) {
docstring text = bformat( docstring text = bformat(
_("The file %1$s already exists.\n\n" _("The file %1$s already exists.\n\n"
@ -1079,10 +1082,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0) text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
break; break;
} }
command += lyxrc.print_to_file command += ' ' + lyxrc.print_to_file
+ quoteName(filename.toFilesystemEncoding()) + quoteName(filename.toFilesystemEncoding())
+ ' ' + ' '
+ quoteName(dviname); + quoteName(dvifile.toFilesystemEncoding());
res = one.startscript(Systemcall::DontWait, res = one.startscript(Systemcall::DontWait,
command); command);
} }

View File

@ -129,7 +129,7 @@ void ControlPrint::dispatchParams()
command += lyxrc.print_extra_options + ' '; command += lyxrc.print_extra_options + ' ';
} }
command += kernel().buffer().params().dvips_options() + ' '; command += kernel().buffer().params().dvips_options();
string const target = (pp.target == PrinterParams::PRINTER) ? string const target = (pp.target == PrinterParams::PRINTER) ?
"printer" : "file"; "printer" : "file";
@ -138,7 +138,7 @@ void ControlPrint::dispatchParams()
(pp.printer_name.empty() ? "default" : pp.printer_name) : (pp.printer_name.empty() ? "default" : pp.printer_name) :
pp.file_name; pp.file_name;
string const data = target + " " + target_name + " " + command; string const data = target + " \"" + target_name + "\" \"" + command + '"';
kernel().dispatch(FuncRequest(getLfun(), data)); kernel().dispatch(FuncRequest(getLfun(), data));
} }