2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
#include "Liason.h"
|
2000-08-11 14:42:20 +00:00
|
|
|
#include "LyXView.h"
|
2000-06-12 11:55:12 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "PrinterParams.h"
|
|
|
|
#include "lyx_gui_misc.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/path.h"
|
2000-08-30 03:40:51 +00:00
|
|
|
#include "exporter.h"
|
2000-09-05 13:16:19 +00:00
|
|
|
#include "converter.h"
|
2000-08-11 14:42:20 +00:00
|
|
|
#include "minibuffer.h"
|
2000-09-05 13:16:19 +00:00
|
|
|
#include "support/syscall.h"
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
extern LyXRC lyxrc;
|
2000-09-05 13:16:19 +00:00
|
|
|
#ifndef NEW_EXPORT
|
2000-06-12 11:55:12 +00:00
|
|
|
extern bool RunScript(Buffer * buffer, bool wait, string const & command,
|
|
|
|
string const & orgname = string(), bool need_shell=true);
|
2000-09-05 13:16:19 +00:00
|
|
|
#endif
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
#ifdef CXX_WORKING_NAMESPACES
|
|
|
|
namespace Liason
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PrinterParams getPrinterParams(Buffer * buffer)
|
|
|
|
{
|
|
|
|
return PrinterParams(PrinterParams::PRINTER,
|
|
|
|
lyxrc.printer,
|
|
|
|
ChangeExtension(buffer->fileName(),
|
|
|
|
lyxrc.print_file_extension));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool printBuffer(Buffer * buffer, PrinterParams const & pp)
|
|
|
|
{
|
2000-09-05 13:16:19 +00:00
|
|
|
#ifndef NEW_EXPORT
|
2000-06-12 11:55:12 +00:00
|
|
|
bool result(false);
|
2000-09-05 13:16:19 +00:00
|
|
|
#endif
|
2000-06-12 11:55:12 +00:00
|
|
|
string command(lyxrc.print_command + ' ');
|
|
|
|
|
|
|
|
if (pp.target == PrinterParams::PRINTER
|
|
|
|
&& lyxrc.print_adapt_output // dvips wants a printer name
|
|
|
|
&& !pp.printer_name.empty()) {// printer name given
|
|
|
|
command += lyxrc.print_to_printer
|
|
|
|
+ pp.printer_name
|
|
|
|
+ ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pp.which_pages) {
|
|
|
|
case PrinterParams::EVEN:
|
|
|
|
command += lyxrc.print_evenpage_flag + ' ';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PrinterParams::ODD:
|
|
|
|
command += lyxrc.print_oddpage_flag + ' ';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// only option left is print all of them
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pp.from_page.empty()) {
|
|
|
|
command += lyxrc.print_pagerange_flag + ' ';
|
|
|
|
command += pp.from_page;
|
|
|
|
if (pp.to_page) {
|
|
|
|
// we have a range "from-to"
|
|
|
|
command += '-';
|
|
|
|
command += tostr(pp.to_page);
|
|
|
|
}
|
|
|
|
command += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pp.reverse_order) {
|
|
|
|
command += lyxrc.print_reverse_flag + ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 < pp.count_copies) {
|
|
|
|
if (pp.unsorted_copies) {
|
|
|
|
command += lyxrc.print_copies_flag;
|
|
|
|
} else {
|
|
|
|
command += lyxrc.print_collcopies_flag;
|
|
|
|
}
|
|
|
|
command += ' ';
|
|
|
|
command += tostr(pp.count_copies);
|
|
|
|
command += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lyxrc.print_extra_options.empty()) {
|
|
|
|
command += lyxrc.print_extra_options + ' ';
|
|
|
|
}
|
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
command += Converter::dvips_options(buffer) + ' ';
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
#ifdef NEW_EXPORT
|
|
|
|
if (!Exporter::Export(buffer, "dvi", true))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Push directory path.
|
|
|
|
string path = OnlyPath(buffer->fileName());
|
|
|
|
if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
|
|
|
|
path = buffer->tmppath;
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
2000-09-05 13:16:19 +00:00
|
|
|
Path p(path);
|
|
|
|
|
|
|
|
// there are three cases here:
|
|
|
|
// 1. we print to a file
|
|
|
|
// 2. we print direct to a printer
|
|
|
|
// 3. we print using a spool command (print to file first)
|
|
|
|
Systemcalls one;
|
|
|
|
int res = 0;
|
|
|
|
string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
|
|
|
|
switch (pp.target) {
|
|
|
|
case PrinterParams::PRINTER:
|
|
|
|
if (!lyxrc.print_spool_command.empty()) {
|
|
|
|
// case 3
|
|
|
|
string psname = ChangeExtension(dviname, ".ps");
|
|
|
|
command += lyxrc.print_to_file
|
|
|
|
+ QuoteName(psname) + ' ';
|
|
|
|
command += QuoteName(dviname);
|
|
|
|
string command2 = lyxrc.print_spool_command + ' ';
|
|
|
|
if (!pp.printer_name.empty())
|
|
|
|
command2 += lyxrc.print_spool_printerprefix
|
|
|
|
+ pp.printer_name + ' ';
|
|
|
|
command2 += QuoteName(psname);
|
|
|
|
// First run dvips.
|
|
|
|
// If successful, then spool command
|
|
|
|
lyxerr << "command1 = " << command << endl;
|
|
|
|
lyxerr << "command2 = " << command2 << endl;
|
|
|
|
res = one.startscript(Systemcalls::System, command);
|
|
|
|
if (res == 0)
|
|
|
|
res = one.startscript(Systemcalls::SystemDontWait,
|
|
|
|
command2);
|
|
|
|
} else
|
|
|
|
// case 2
|
|
|
|
res = one.startscript(Systemcalls::SystemDontWait, command);
|
|
|
|
break;
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
case PrinterParams::FILE:
|
|
|
|
// case 1
|
|
|
|
command += lyxrc.print_to_file
|
|
|
|
+ QuoteName(MakeAbsPath(pp.file_name, path));
|
|
|
|
command += ' ' + QuoteName(dviname);
|
|
|
|
lyxerr << "command1 = " << command << endl;
|
|
|
|
res = one.startscript(Systemcalls::SystemDontWait, command);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res == 0;
|
|
|
|
#else
|
2000-06-12 11:55:12 +00:00
|
|
|
// Push directory path if necessary.
|
|
|
|
// PS file should go where the source file is unless it's a
|
|
|
|
// read-only directory in which case we write it to tmpdir.
|
|
|
|
// All temporary files go in tmpdir (like spool files).
|
|
|
|
string path = OnlyPath(buffer->fileName());
|
|
|
|
if ((pp.target != PrinterParams::FILE
|
|
|
|
&& lyxrc.use_tempdir)
|
|
|
|
|| (IsDirWriteable(path) < 1)) {
|
|
|
|
path = buffer->tmppath;
|
|
|
|
}
|
|
|
|
Path p(path);
|
|
|
|
|
|
|
|
// there are three cases here:
|
|
|
|
// 1. we print to a file
|
|
|
|
// 2. we print direct to a printer
|
|
|
|
// 3. we print using a spool command (print to file first)
|
|
|
|
switch (pp.target) {
|
|
|
|
case PrinterParams::PRINTER:
|
|
|
|
if (!lyxrc.print_spool_command.empty()) {
|
|
|
|
// case 3
|
|
|
|
command += lyxrc.print_to_file
|
|
|
|
+ QuoteName(pp.file_name);
|
|
|
|
string command2 = lyxrc.print_spool_command
|
|
|
|
+ ' ';
|
|
|
|
if (!pp.printer_name.empty()) {
|
|
|
|
command2 += lyxrc.print_spool_printerprefix
|
|
|
|
+ pp.printer_name;
|
|
|
|
}
|
|
|
|
// First run dvips.
|
|
|
|
// If successful, then spool command
|
|
|
|
if (result = RunScript(buffer, true, command)) {
|
|
|
|
result = RunScript(buffer, false,
|
|
|
|
command2,
|
|
|
|
QuoteName(pp.file_name));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// case 2
|
|
|
|
result = RunScript(buffer, false, command);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PrinterParams::FILE:
|
|
|
|
// case 1
|
|
|
|
command += lyxrc.print_to_file
|
|
|
|
+ QuoteName(MakeAbsPath(pp.file_name, path));
|
|
|
|
result = RunScript(buffer, false, command);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
2000-09-05 13:16:19 +00:00
|
|
|
#endif
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
|
|
|
|
2000-08-11 14:42:20 +00:00
|
|
|
void setMinibuffer(LyXView * lv, char const * msg)
|
|
|
|
{
|
|
|
|
lv->getMiniBuffer()->Set(msg);
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
#ifdef CXX_WORKING_NAMESPACES
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|