+ case LFUN_EXPORT_CUSTOM: {
+ string format_name;
+ string command = split(argument, format_name, ' ');
+ Format const * format = formats.getFormat(format_name);
+ if (!format) {
+ lyxerr << "Format \"" << format_name
+ << "\" not recognized!"
+ << std::endl;
+ break;
+ }
+
+ Buffer * buffer = owner->buffer();
+
+ // The name of the file created by the conversion process
+ string filename;
+
+ // Output to filename
+ if (format->name() == "lyx") {
+ string const latexname =
+ buffer->getLatexName(false);
+ filename = ChangeExtension(latexname,
+ format->extension());
+ filename = AddName(buffer->temppath(), filename);
+
+ if (!buffer->writeFile(filename))
+ break;
+
+ } else {
+ Exporter::Export(buffer, format_name, true,
+ filename);
+ }
+
+ // Substitute $$FName for filename
+ if (!contains(command, "$$FName"))
+ command = "( " + command + " ) < $$FName";
+ command = subst(command, "$$FName", filename);
+
+ // Execute the command in the background
+ Systemcall call;
+ call.startscript(Systemcall::DontWait, command);
+ break;
+ }
+
+ case LFUN_PRINT: {
+ string target;
+ string target_name;
+ string command = split(split(argument, target, ' '),
+ target_name, ' ');
+
+ if (target.empty()
+ || target_name.empty()
+ || command.empty()) {
+ lyxerr << "Unable to parse \""
+ << argument << '"' << std::endl;
+ break;
+ }
+ if (target != "printer" && target != "file") {
+ lyxerr << "Unrecognized target \""
+ << target << '"' << std::endl;
+ break;
+ }
+
+ Buffer * buffer = owner->buffer();
+
+ if (!Exporter::Export(buffer, "dvi", true)) {
+ showPrintError(buffer->fileName());
+ break;
+ }
+
+ // Push directory path.
+ string const path = buffer->temppath();
+ Path p(path);
+
+ // there are three cases here:
+ // 1. we print to a file
+ // 2. we print directly to a printer
+ // 3. we print using a spool command (print to file first)
+ Systemcall one;
+ int res = 0;
+ string const dviname =
+ ChangeExtension(buffer->getLatexName(true),
+ "dvi");
+
+ if (target == "printer") {
+ if (!lyxrc.print_spool_command.empty()) {
+ // case 3: print using a spool
+ string const psname =
+ ChangeExtension(dviname,".ps");
+ command += lyxrc.print_to_file
+ + QuoteName(psname)
+ + ' '
+ + QuoteName(dviname);
+
+ string command2 =
+ lyxrc.print_spool_command +' ';
+ if (target_name != "default") {
+ command2 += lyxrc.print_spool_printerprefix
+ + target_name
+ + ' ';
+ }
+ command2 += QuoteName(psname);
+ // First run dvips.
+ // If successful, then spool command
+ res = one.startscript(
+ Systemcall::Wait,
+ command);
+
+ if (res == 0)
+ res = one.startscript(
+ Systemcall::DontWait,
+ command2);
+ } else {
+ // case 2: print directly to a printer
+ res = one.startscript(
+ Systemcall::DontWait,
+ command + QuoteName(dviname));
+ }
+
+ } else {
+ // case 1: print to a file
+ command += lyxrc.print_to_file
+ + QuoteName(MakeAbsPath(target_name,
+ path))
+ + ' '
+ + QuoteName(dviname);
+ res = one.startscript(Systemcall::DontWait,
+ command);
+ }
+
+ if (res != 0)
+ showPrintError(buffer->fileName());
+ break;
+ }
+