From 83882f6d92b2ce51a7c0b05fe28df9dfbd8e1143 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Tue, 5 Sep 2000 13:16:19 +0000 Subject: [PATCH] export patch from Dekel git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1001 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 29 +++++++ lib/configure | 167 +++++++++++++++++++++++++---------- lib/configure.m4 | 65 ++++++++------ lib/ui/default.ui | 22 ++--- src/LyXAction.C | 5 ++ src/converter.C | 188 +++++++++++++++++++++++++++------------- src/converter.h | 13 ++- src/encoding.C | 2 +- src/exporter.C | 41 ++++----- src/frontends/Liason.C | 118 +++++++++++++------------ src/lyxrc.C | 4 - src/support/Makefile.am | 2 + src/support/copy.C | 15 ++++ src/support/lyxlib.h | 8 ++ src/support/rename.C | 10 +++ src/support/syscall.C | 24 +++++ src/support/syscall.h | 1 + 17 files changed, 483 insertions(+), 231 deletions(-) create mode 100644 src/support/copy.C create mode 100644 src/support/rename.C diff --git a/ChangeLog b/ChangeLog index eec202f974..91cf5cd842 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2000-09-04 Dekel Tsur + + * src/converter.C (add_options): New function. + (SetViewer): Change $$FName into '$$FName'. + (View): Add options when running xdvi + (Add): Change $$FName into '$$FName'. Same for $$BaseName/$$OutName. + (Convert): The 3rd parameter is now the desired filename. Converts + calls to lyx::rename if necessary. + Add options when running dvips. + (dvi_papersize,dvips_options): New methods. + + * src/exporter.C (Export): Use getLatexName() instead of fileName(). + + * src/frontends/Liason.C (printBuffer): Removed duplicate code by + using a call to Converter::dvips_options. + Fixed to work with nex export code. + + * src/support/copy.C + * src/support/rename.C: New files + + * src/support/syscall.h + * src/support/syscall.C: Added Starttype SystemDontWait. + + * lib/ui/default.ui: Changed to work with new export code + + * lib/configure.m4: Changed to work with new export code + + * src/encoding.C: Changed latex name for iso8859_7 encoding. + 2000-09-04 Angus Leeming + * src/frontends/xforms/Menubar_pimpl.C: added two using directives diff --git a/lib/configure b/lib/configure index 0ce81b5bff..8c8081660b 100755 --- a/lib/configure +++ b/lib/configure @@ -335,7 +335,7 @@ fi # Search for a program to preview pdf echo $ac_n "checking for a PDF preview""... $ac_c" echo "$ac_t""(xpdf acroread gv ghostview)" -PDFVIEWER= +PDF_VIEWER= for ac_prog in xpdf acroread gv ghostview do # Extract the first word of "$ac_prog", so it can be a program name with args. @@ -346,33 +346,33 @@ if test -n "$ac_word"; then for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -x $ac_dir/$ac_word; then - PDFVIEWER="$ac_prog" + PDF_VIEWER="$ac_prog" break fi done IFS="$ac_save_ifs" - if test -n "$PDFVIEWER"; then + if test -n "$PDF_VIEWER"; then ac_result=yes else ac_result=no fi echo "$ac_t""$ac_result" - test -n "$PDFVIEWER" && break + test -n "$PDF_VIEWER" && break fi done -if test -z "$PDFVIEWER" ; then - PDFVIEWER=none +if test -z "$PDF_VIEWER" ; then + PDF_VIEWER=none fi -# Search for a program to convert pdf to ps -echo $ac_n "checking for a PDF to PS converter""... $ac_c" -echo "$ac_t""(pdf2ps pdftops)" -PDFPS= -for ac_prog in pdf2ps pdftops +# Search something to preview dvi +echo $ac_n "checking for a DVI previewer""... $ac_c" +echo "$ac_t""(xdvi)" +DVI_VIEWER= +for ac_prog in xdvi do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog ; ac_word=$2 @@ -382,32 +382,105 @@ if test -n "$ac_word"; then for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -x $ac_dir/$ac_word; then - PDFPS="$ac_prog" + DVI_VIEWER="$ac_prog" break fi done IFS="$ac_save_ifs" - if test -n "$PDFPS"; then + if test -n "$DVI_VIEWER"; then ac_result=yes else ac_result=no fi echo "$ac_t""$ac_result" - test -n "$PDFPS" && break + test -n "$DVI_VIEWER" && break fi done -if test -z "$PDFPS" ; then - PDFPS=none +if test -z "$DVI_VIEWER" ; then + DVI_VIEWER=none fi +# Search something to preview html +echo $ac_n "checking for a HTML previewer""... $ac_c" +echo "$ac_t""(netscape)" +HTML_VIEWER= +for ac_prog in netscape +do +# Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog ; ac_word=$2 +if test -n "$ac_word"; then + echo $ac_n "+checking for \"$ac_word\"""... $ac_c" + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + for ac_dir in $PATH; do + test -z "$ac_dir" && ac_dir=. + if test -x $ac_dir/$ac_word; then + HTML_VIEWER="$ac_prog" + break + fi + done + IFS="$ac_save_ifs" + + if test -n "$HTML_VIEWER"; then + ac_result=yes + else + ac_result=no + fi + + echo "$ac_t""$ac_result" + test -n "$HTML_VIEWER" && break +fi +done + +if test -z "$HTML_VIEWER" ; then + HTML_VIEWER=none +fi + + +# Search for a program to convert ps to pdf +echo $ac_n "checking for a PS to PDF converter""... $ac_c" +echo "$ac_t""(ps2pdf)" +ps_to_pdf_command= +for ac_prog in ps2pdf +do +# Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog ; ac_word=$2 +if test -n "$ac_word"; then + echo $ac_n "+checking for \"$ac_word\"""... $ac_c" + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + for ac_dir in $PATH; do + test -z "$ac_dir" && ac_dir=. + if test -x $ac_dir/$ac_word; then + ps_to_pdf_command="$ac_prog" + break + fi + done + IFS="$ac_save_ifs" + + if test -n "$ps_to_pdf_command"; then + ac_result=yes + else + ac_result=no + fi + + echo "$ac_t""$ac_result" + test -n "$ps_to_pdf_command" && break +fi +done + +if test -z "$ps_to_pdf_command" ; then + ps_to_pdf_command=none +fi + +test $ps_to_pdf_command = "ps2pdf" && ps_to_pdf_command="ps2pdf \$\$FName" + # Search for a program to convert dvi to ps echo $ac_n "checking for a DVI to PS converter""... $ac_c" echo "$ac_t""(dvips)" -DVIPS= +dvi_to_ps_command= for ac_prog in dvips do # Extract the first word of "$ac_prog", so it can be a program name with args. @@ -418,27 +491,28 @@ if test -n "$ac_word"; then for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -x $ac_dir/$ac_word; then - DVIPS="$ac_prog" + dvi_to_ps_command="$ac_prog" break fi done IFS="$ac_save_ifs" - if test -n "$DVIPS"; then + if test -n "$dvi_to_ps_command"; then ac_result=yes else ac_result=no fi echo "$ac_t""$ac_result" - test -n "$DVIPS" && break + test -n "$dvi_to_ps_command" && break fi done -if test -z "$DVIPS" ; then - DVIPS=none +if test -z "$dvi_to_ps_command" ; then + dvi_to_ps_command=none fi +test $dvi_to_ps_command = "dvips" && dvi_to_ps_command="dvips -o \$\$OutName \$\$FName" # Search a *roff program (used to translate tables in ASCII export) echo $ac_n "checking for a *roff formatter""... $ac_c" @@ -641,8 +715,8 @@ fi case $LINUXDOC in sgml2lyx) - linuxdoc_to_latex_command="sgml2latex" - linuxdoc_to_html_command="sgml2html '\$\$FName'" + linuxdoc_to_latex_command="sgml2latex \$\$FName" + linuxdoc_to_html_command="sgml2html \$\$FName" linuxdoc_to_lyx_command="sgml2lyx";; none) linuxdoc_to_latex_command="none" @@ -693,11 +767,11 @@ fi case $DOCBOOK in sgmltools) - docbook_to_dvi_command="sgmltools -b dvi" - docbook_to_html_command="sgmltools -b html '\$\$FName'";; + docbook_to_dvi_command="sgmltools -b dvi \$\$FName" + docbook_to_html_command="sgmltools -b html \$\$FName";; db2dvi) - docbook_to_dvi_command="db2dvi" - docbook_to_html_command="db2html '\$\$FName'";; + docbook_to_dvi_command="db2dvi \$\$FName" + docbook_to_html_command="db2html \$\$FName";; none) docbook_to_dvi_command="none" docbook_to_html_command="none";; @@ -781,10 +855,11 @@ if test -z "$TOHTML" ; then TOHTML=none fi +latex_to_html_command = $TOHTML case $TOHTML in - tth) html_command="tth -t < '\$\$FName' > '\$\$OutName'";; - latex2html) html_command="latex2html -no_subdir -split 0 -show_section_numbers '\$\$FName'";; - hevea) html_command="hevea -s '\$\$FName'";; + tth) latex_to_html_command="tth -t < \$\$FName > \$\$OutName";; + latex2html) latex_to_html_command="latex2html -no_subdir -split 0 -show_section_numbers \$\$FName";; + hevea) latex_to_html_command="hevea -s \$\$FName";; esac #### Explore the LaTeX configuration @@ -870,27 +945,31 @@ cat >lyxrc.defaults <lyxrc.defaults < -#include -#include -#include +#include // sort() #include "converter.h" #include "lyxrc.h" #include "support/syscall.h" #include "support/path.h" -#include "debug.h" #include "buffer.h" - #include "bufferview_funcs.h" #include "LaTeX.h" #include "LyXView.h" #include "minibuffer.h" #include "lyx_gui_misc.h" -#include "lyx_cb.h" +#include "lyx_cb.h" // ShowMessage() using std::map; using std::vector; using std::queue; using std::pair; using std::sort; -using std::stack; using std::endl; ////////////////////////////////////////////////////////////////////////////// @@ -46,6 +41,14 @@ using std::endl; map Formats::formats; vector Converter::commands; +inline +string add_options(string const & command, string const & options) +{ + string head; + string tail = split(command, head, ' '); + return head + ' ' + options + ' ' + tail; +} + ////////////////////////////////////////////////////////////////////////////// Format::Format(string const & n) @@ -83,17 +86,17 @@ void Formats::Add(string const & name) void Formats::SetViewer(string const & name, string const & command) { + + string command2 = subst(command, "$$FName", "'$$FName'"); + if (!contains(command,"$$FName")) + command2 += " '$$FName'"; + Add(name); - Format * f = GetFormat(name); - if (!f->viewer.empty()) - lyxerr << "Error: a viewer for " << name - << " is already defined!" << endl; - else - f->viewer = command; + GetFormat(name)->viewer = command2; } -bool Formats::View(string const & filename) +bool Formats::View(Buffer * buffer, string const & filename) { string extension = GetExtension(filename); Format * format = GetFormat(extension); @@ -105,30 +108,24 @@ bool Formats::View(string const & filename) } string command = format->viewer; + + if (extension == "dvi" && + !lyxrc.view_dvi_paper_option.empty()) { + string options = lyxrc.view_dvi_paper_option; + options += " " + Converter::dvi_papersize(buffer); + if (buffer->params.orientation + == BufferParams::ORIENTATION_LANDSCAPE) + options += 'r'; + command = add_options(command, options); + } + + string command2 = subst(command, "$$FName", OnlyFilename(filename)); + lyxerr << "Executing command: " << command2 << endl; + ShowMessage(buffer, _("Executing command:"), command2); + command = subst(command, "$$FName", filename); -#ifndef __EMX__ - command += " &"; -#else - // OS/2 cmd.exe has another use for '&' - // This is not NLS safe, but it's OK, I think. - string sh = OnlyFilename(GetEnvPath("EMXSHELL")); - if (sh.empty()) { - // COMSPEC is set, unless user unsets - sh = OnlyFilename(GetEnvPath("COMSPEC")); - if (sh.empty()) - sh = "cmd.exe"; - } - sh = lowercase(sh); - if (contains(sh, "cmd.exe") - || contains(sh, "4os2.exe")) - command = "start /min/n " + command; - else - command += " &"; -#endif - lyxerr << "Executing command: " << command << endl; - //ShowMessage(buffer, _("Executing command:"), command); Systemcalls one; - int res = one.startscript(Systemcalls::System, command); + int res = one.startscript(Systemcalls::SystemDontWait, command); if (res) { WriteAlert(_("Can not view file"), @@ -149,6 +146,7 @@ Format * Formats::GetFormat(string const & name) return 0; } + string const Formats::PrettyName(string const & name) { string format; @@ -162,20 +160,26 @@ string const Formats::PrettyName(string const & name) ////////////////////////////////////////////////////////////////////////////// + void Converter::Add(string const & from, string const & to, string const & command, string const & flags) { - for (vector::const_iterator cit = commands.begin(); - cit != commands.end(); ++cit) - if ((*cit).from == from && (*cit).to == to) { - lyxerr << "Error: Convertor from " << from - << " to " << to - << " already exists!" << endl; - return; - } + if (command == "none") + return; + bool original_dir = flags == "origdir"; - commands.push_back(Command(from, to, command, original_dir)); + string command2 = + subst(command, "$$FName", "'$$FName'"); + command2 = subst(command2, "$$BaseName", "'$$BaseName'"); + command2 = subst(command2, "$$OutName", "'$$OutName'"); + for (vector::iterator it = commands.begin(); + it != commands.end(); ++it) + if ((*it).from == from && (*it).to == to) { + *it = Command(from, to, command2, original_dir); + return; + } + commands.push_back(Command(from, to, command2, original_dir)); Formats::Add(from); Formats::Add(to); ++Formats::GetFormat(to)->in_degree; @@ -232,15 +236,16 @@ Converter::GetReachable(string const & from, bool only_viewable) } -bool Converter::convert(Buffer * buffer, string const & from_file, - string const & to_format) - +bool Converter::Convert(Buffer * buffer, string const & from_file, + string const & to_file, string const & using_format) { - string format; - string using_format = SplitFormat(to_format, format); string from_format = GetExtension(from_file); - if (from_format == format) - return true; + string to_format = GetExtension(to_file); + if (from_format == to_format) + if (from_file != to_file) + return lyx::rename(from_file.c_str(), to_file.c_str()); + else + return true; queue< vector::iterator > Q; for (vector::iterator it = commands.begin(); @@ -262,7 +267,7 @@ bool Converter::convert(Buffer * buffer, string const & from_file, vector::iterator it; while (!Q.empty()) { it = Q.front(); - if ((*it).to == format && + if ((*it).to == to_format && (using_format.empty() || using_format == (*it).from)) { found = true; break; @@ -285,19 +290,18 @@ bool Converter::convert(Buffer * buffer, string const & from_file, return false; } - stack< vector::iterator > S; + vector< vector::iterator > S; while (it != commands.end()) { - S.push(it); + S.push_back(it); it = (*it).previous; } - //Path p(OnlyPath(buffer->fileName())); Path p(OnlyPath(from_file)); string basename = ChangeExtension(from_file, ""); - while (!S.empty()) { - it = S.top(); - S.pop(); + for (vector< vector::iterator >::reverse_iterator rit = + S.rbegin(); rit != S.rend(); ++rit) { + it = *rit; lyxerr << "Converting from " << (*it).from << " to " << (*it).to << endl; @@ -316,6 +320,11 @@ bool Converter::convert(Buffer * buffer, string const & from_file, command = subst(command, "$$FName", infile); command = subst(command, "$$BaseName", basename); command = subst(command, "$$OutName", outfile); + + if ((*it).from == "dvi" && (*it).to == "ps") + command = add_options(command, + dvips_options(buffer)); + lyxerr << "Calling " << command << endl; ShowMessage(buffer, _("Executing command:"), command); @@ -335,6 +344,14 @@ bool Converter::convert(Buffer * buffer, string const & from_file, } } + string result_file = ChangeExtension(from_file, to_format); + if (result_file != to_file) + if ((*it).from == "tex" && + ( (*it).to == "dvi" || (*it).to == "pdf") ) + return lyx::copy(result_file.c_str(), to_file.c_str()); + else + return lyx::rename(result_file.c_str(), to_file.c_str()); + return true; } @@ -408,3 +425,56 @@ bool Converter::runLaTeX(Buffer * buffer, string const & command) } + +string Converter::dvi_papersize(Buffer * buffer) +{ + char real_papersize = buffer->params.papersize; + if (real_papersize == BufferParams::PAPER_DEFAULT) + real_papersize = lyxrc.default_papersize; + + switch (real_papersize) { + case BufferParams::PAPER_A3PAPER: + return "a3"; + case BufferParams::PAPER_A4PAPER: + return "a4"; + case BufferParams::PAPER_A5PAPER: + return "a5"; + case BufferParams::PAPER_B5PAPER: + return "b5"; + case BufferParams::PAPER_EXECUTIVEPAPER: + return "foolscap"; + case BufferParams::PAPER_LEGALPAPER: + return "legal"; + case BufferParams::PAPER_USLETTER: + default: + return "us"; + } +} + + +string Converter::dvips_options(Buffer * buffer) +{ + string result; + if (buffer->params.use_geometry + && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM + && !lyxrc.print_paper_dimension_flag.empty() + && !buffer->params.paperwidth.empty() + && !buffer->params.paperheight.empty()) { + // using a custom papersize + result = lyxrc.print_paper_dimension_flag; + result += ' ' + buffer->params.paperwidth; + result += ',' + buffer->params.paperheight; + } else { + string paper_option = dvi_papersize(buffer); + if (paper_option != "letter" || + buffer->params.orientation != BufferParams::ORIENTATION_LANDSCAPE) { + // dvips won't accept -t letter -t landscape. In all other + // cases, include the paper size explicitly. + result = lyxrc.print_paper_flag; + result += ' ' + paper_option; + } + } + if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) + result += ' ' + lyxrc.print_landscape_flag; + return result; +} diff --git a/src/converter.h b/src/converter.h index 3300b6ffcd..dc151dba05 100644 --- a/src/converter.h +++ b/src/converter.h @@ -70,7 +70,7 @@ public: void SetViewer(string const & name, string const & command); /// static - bool View(string const & filename); + bool View(Buffer * buffer, string const & filename); /// static Format * GetFormat(string const & name); @@ -97,11 +97,16 @@ public: bool only_viewable = false); /// static - bool convert(Buffer * buffer, string const & from_file, - string const & to_format); + bool Convert(Buffer * buffer, string const & from_file, + string const & to_file, string const & using_format); + static + string const SplitFormat(string const & str, string & format); + /// + static + string dvi_papersize(Buffer * buffer); /// static - string const SplitFormat(string const & str, string & format); + string dvips_options(Buffer * buffer); private: /// static diff --git a/src/encoding.C b/src/encoding.C index 1c7066a772..f8350dd1db 100644 --- a/src/encoding.C +++ b/src/encoding.C @@ -462,7 +462,7 @@ Encoding iso8859_2("latin2",tab_iso8859_2); Encoding iso8859_3("latin3",tab_iso8859_3); Encoding iso8859_4("latin4",tab_iso8859_4); Encoding iso8859_6("unknown",tab_iso8859_6_16); -Encoding iso8859_7("unknown",tab_iso8859_7); +Encoding iso8859_7("iso-8859-7",tab_iso8859_7); Encoding iso8859_9("latin5",tab_iso8859_9); Encoding cp1255("cp1255",tab_cp1255); Encoding koi8("koi8-r",tab_koi8); diff --git a/src/exporter.C b/src/exporter.C index a7847ffbb6..419ae57380 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -14,15 +14,11 @@ #pragma implementation #endif -#include -#include - #include "exporter.h" #include "converter.h" - #include "buffer.h" -#include "lyx_cb.h" -#include "support/path.h" +#include "lyx_cb.h" //ShowMessage() +#include "support/filetools.h" using std::vector; using std::pair; @@ -33,39 +29,34 @@ bool Exporter::Export(Buffer * buffer, string const & format0, string format; string using_format = Converter::SplitFormat(format0, format); - string filename = buffer->fileName(); string backend_format = BufferExtension(buffer); bool only_backend = backend_format == format; - //string file = buffer->getLatexName(true); - string file = filename; + string filename = buffer->getLatexName(false); if (!buffer->tmppath.empty()) - file = AddName(buffer->tmppath, file); - file = ChangeExtension(file, backend_format); + filename = AddName(buffer->tmppath, filename); + filename = ChangeExtension(filename, backend_format); if (buffer->isLinuxDoc()) - buffer->makeLinuxDocFile(file, only_backend); + buffer->makeLinuxDocFile(filename, only_backend); else if (only_backend) - buffer->makeLaTeXFile(file, string(), true); + buffer->makeLaTeXFile(filename, string(), true); else - buffer->makeLaTeXFile(file, buffer->filepath, false); + buffer->makeLaTeXFile(filename, buffer->filepath, false); - bool return_value = Converter::convert(buffer, file, format0); - if (!return_value) - return false; + string outfile = (put_in_tempdir) + ? ChangeExtension(filename, format) + : ChangeExtension(buffer->getLatexName(false), format); - if (!put_in_tempdir) { - file = ChangeExtension(file, format); - string outfile = ChangeExtension(filename, format); - if (file != outfile) - rename(file.c_str(), outfile.c_str()); + if (!Converter::Convert(buffer, filename, outfile, using_format)) + return false; + if (!put_in_tempdir) ShowMessage(buffer, _("Document exported as ") + Formats::PrettyName(format) + _(" to file `") + MakeDisplayPath(outfile) +'\''); - } return true; } @@ -78,11 +69,11 @@ bool Exporter::Preview(Buffer * buffer, string const & format0) string format; Converter::SplitFormat(format0, format); - string filename = buffer->fileName(); + string filename = buffer->getLatexName(false); if (!buffer->tmppath.empty()) filename = AddName(buffer->tmppath, filename); filename = ChangeExtension(filename, format); - return Formats::View(filename); + return Formats::View(buffer, filename); } diff --git a/src/frontends/Liason.C b/src/frontends/Liason.C index 35c1513158..570bb24239 100644 --- a/src/frontends/Liason.C +++ b/src/frontends/Liason.C @@ -25,12 +25,15 @@ #include "support/filetools.h" #include "support/path.h" #include "exporter.h" +#include "converter.h" #include "minibuffer.h" +#include "support/syscall.h" extern LyXRC lyxrc; +#ifndef NEW_EXPORT extern bool RunScript(Buffer * buffer, bool wait, string const & command, string const & orgname = string(), bool need_shell=true); - +#endif #ifdef CXX_WORKING_NAMESPACES namespace Liason @@ -48,7 +51,9 @@ PrinterParams getPrinterParams(Buffer * buffer) bool printBuffer(Buffer * buffer, PrinterParams const & pp) { +#ifndef NEW_EXPORT bool result(false); +#endif string command(lyxrc.print_command + ' '); if (pp.target == PrinterParams::PRINTER @@ -88,12 +93,6 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) command += lyxrc.print_reverse_flag + ' '; } - BufferParams params(buffer->params); - if (params.orientation - == BufferParams::ORIENTATION_LANDSCAPE) { - command += lyxrc.print_landscape_flag + ' '; - } - if (1 < pp.count_copies) { if (pp.unsorted_copies) { command += lyxrc.print_copies_flag; @@ -109,57 +108,63 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) command += lyxrc.print_extra_options + ' '; } - char real_papersize = params.papersize; - if (real_papersize == BufferParams::PAPER_DEFAULT) { - real_papersize = lyxrc.default_papersize; - } + command += Converter::dvips_options(buffer) + ' '; - if (params.use_geometry - && params.papersize2 == BufferParams::VM_PAPER_CUSTOM - && !lyxrc.print_paper_dimension_flag.empty() - && !params.paperwidth.empty() - && !params.paperheight.empty()) { - // using a custom papersize - command += lyxrc.print_paper_dimension_flag + ' '; - command += params.paperwidth + ','; - command += params.paperheight + ' '; - } else if (!lyxrc.print_paper_flag.empty() - && (real_papersize != BufferParams::PAPER_USLETTER - || params.orientation - == BufferParams::ORIENTATION_PORTRAIT)) { - // There's a problem with US Letter + landscape - string paper; - switch (real_papersize) { - case BufferParams::PAPER_USLETTER: - paper = "letter"; - break; - case BufferParams::PAPER_A3PAPER: - paper = "a3"; - break; - case BufferParams::PAPER_A4PAPER: - paper = "a4"; - break; - case BufferParams::PAPER_A5PAPER: - paper = "a5"; - break; - case BufferParams::PAPER_B5PAPER: - paper = "b5"; - break; - case BufferParams::PAPER_EXECUTIVEPAPER: - paper = "foolscap"; - break; - case BufferParams::PAPER_LEGALPAPER: - paper = "legal"; - break; - default: /* If nothing else fits, keep empty value */ - break; - } - if (!paper.empty()) { - command += lyxrc.print_paper_flag + ' '; - command += paper + ' '; - } +#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; } + 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; + 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 // 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. @@ -172,7 +177,6 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) } Path p(path); -#ifndef NEW_EXPORT // there are three cases here: // 1. we print to a file // 2. we print direct to a printer @@ -209,8 +213,8 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) result = RunScript(buffer, false, command); break; } -#endif return result; +#endif } void setMinibuffer(LyXView * lv, char const * msg) diff --git a/src/lyxrc.C b/src/lyxrc.C index 8a50c1cdb7..65e42de925 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -1122,9 +1122,6 @@ int LyXRC::read(string const & filename) command = lexrc.GetString(); if (lexrc.next()) flags = lexrc.GetString(); - command = subst(command, "$$FName", "'$$FName'"); - command = subst(command, "$$BaseName", "'$$BaseName'"); - command = subst(command, "$$OutName", "'$$OutName'"); Converter::Add(from, to, command, flags); break; } @@ -1135,7 +1132,6 @@ int LyXRC::read(string const & filename) format = lexrc.GetString(); if (lexrc.next()) command = lexrc.GetString(); - command = subst(command, "$$FName", "'$$FName'"); Formats::SetViewer(format, command); break; } diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 2bc70a97f7..cf52922815 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -33,6 +33,7 @@ libsupport_la_SOURCES = \ abort.C \ block.h \ chdir.C \ + copy.C \ date.C \ filetools.C \ filetools.h \ @@ -50,6 +51,7 @@ libsupport_la_SOURCES = \ path.C \ path.h \ putenv.C \ + rename.C \ $(REGEX) syscall.C \ syscall.h \ syscontr.C \ diff --git a/src/support/copy.C b/src/support/copy.C new file mode 100644 index 0000000000..ed1fa9ea45 --- /dev/null +++ b/src/support/copy.C @@ -0,0 +1,15 @@ +#include + +#include + +#include "support/lyxlib.h" +#include "LString.h" +#include "support/syscall.h" +#include "support/filetools.h" + +bool lyx::copy(char const * from, char const * to) +{ + string command = "cp " + QuoteName(from) + " " + QuoteName(to); + return Systemcalls().startscript(Systemcalls::System, + command) == 0; +} diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index cfde2af5ba..b14fe84dd5 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -26,6 +26,10 @@ namespace lyx { char * getcwd(char * buffer, size_t size); /// int chdir(char const * name); + /// Returns false it it fails + bool rename(char const * from, char const * to); + /// Returns false it it fails + bool copy(char const * from, char const * to); /// generates a checksum unsigned long sum(char const * file); /// returns a date string (not used currently) @@ -48,6 +52,10 @@ struct lyx { static char * getcwd(char * buffer, size_t size); /// static int chdir(char const * name); + /// Returns false it it fails + static bool rename(char const * from, char const * to); + /// Returns false it it fails + static bool copy(char const * from, char const * to); /// generates a checksum static unsigned long sum(char const * file); /// returns a date string (not used currently) diff --git a/src/support/rename.C b/src/support/rename.C new file mode 100644 index 0000000000..3f93246791 --- /dev/null +++ b/src/support/rename.C @@ -0,0 +1,10 @@ +#include + +#include + +#include "support/lyxlib.h" + +bool lyx::rename(char const * from, char const * to) +{ + return ::rename(from, to) != -1; +} diff --git a/src/support/syscall.C b/src/support/syscall.C index 8086ab73b2..3630103758 100644 --- a/src/support/syscall.C +++ b/src/support/syscall.C @@ -50,6 +50,7 @@ int Systemcalls::startscript() { retval = 0; switch (start) { case System: + case SystemDontWait: retval = system(command.c_str()); callback(); break; @@ -193,6 +194,29 @@ int Systemcalls::startscript(Starttype how, string const & what, cbk = cback; pid = static_cast(0); // yet no child retval = 0; + + if (how == SystemDontWait) { +#ifndef __EMX__ + command += " &"; +#else + // OS/2 cmd.exe has another use for '&' + // This is not NLS safe, but it's OK, I think. + string sh = OnlyFilename(GetEnvPath("EMXSHELL")); + if (sh.empty()) { + // COMSPEC is set, unless user unsets + sh = OnlyFilename(GetEnvPath("COMSPEC")); + if (sh.empty()) + sh = "cmd.exe"; + } + sh = lowercase(sh); + if (contains(sh, "cmd.exe") + || contains(sh, "4os2.exe")) + command = "start /min/n " + command; + else + command += " &"; +#endif + } + return startscript(); } diff --git a/src/support/syscall.h b/src/support/syscall.h index 11c28fc58d..0668dd5351 100644 --- a/src/support/syscall.h +++ b/src/support/syscall.h @@ -32,6 +32,7 @@ public: /// enum Starttype { System, // Uses system() which uses /bin/sh + SystemDontWait, // Uses system() which uses /bin/sh Wait, // Uses fork() and execvp() DontWait // Uses fork() and execvp() }; -- 2.39.5