-#ifndef NEW_EXPORT
-int MakeLaTeXOutput(Buffer * buffer)
-{
- // Who cares?
- //if (!bv->text)
- // return 1;
- int ret = 0;
- string path = OnlyPath(buffer->fileName());
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
- path = buffer->tmppath;
- }
-
- Path p(path);
- ret = MenuRunLaTeX(buffer);
-
- return ret;
-}
-
-
-/* wait == false means don't wait for termination */
-/* wait == true means wait for termination */
-// The bool should be placed last on the argument line. (Lgb)
-// Returns false if we fail.
-bool RunScript(Buffer * buffer, bool wait,
- string const & command,
- string const & orgname = string(),
- bool need_shell = true)
-{
- string path;
- string cmd;
- string name = orgname;
- int result = 0;
-
- if (MakeLaTeXOutput(buffer) > 0)
- return false;
- /* get DVI-Filename */
- if (name.empty())
- name = ChangeExtension(buffer->getLatexName(), ".dvi");
-
- path = OnlyPath(name);
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
- path = buffer->tmppath;
- }
- Path p(path);
- // At this point we check whether the command contains the
- // filename parameter $$FName and if that's the case we
- // substitute the real file name otherwise the filename is
- // simply appended. rokrau 1/12/00
- cmd = command;
- string::size_type i;
- if ( (i=command.find("$$FName")) != string::npos)
- {
- cmd.replace(i,7,QuoteName(name));
- }
- else
- cmd = command + ' ' + QuoteName(name);
-
- Systemcalls one;
-
- if (need_shell) {
-#ifndef __EMX__
- if (!wait)
- cmd += " &";
-#else
- // OS/2 cmd.exe has another use for '&'
- if (!wait) {
- // 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"))
- cmd = "start /min/n " + cmd;
- else
- cmd += " &";
- }
-#endif
- // It seems that, if wait is false, we never get back
- // the return code of the command. This means that all
- // the code I added in PrintApplyCB is currently
- // useless...
- // CHECK What should we do here?
- ShowMessage(buffer, _("Executing command:"), cmd);
- result = one.startscript(Systemcalls::System, cmd);
- } else {
- ShowMessage(buffer, _("Executing command:"), cmd);
- result = one.startscript(wait ? Systemcalls::Wait
- : Systemcalls::DontWait, cmd);
- }
- return result == 0;
-}
-
-
-// Returns false if we fail
-bool CreatePostscript(Buffer * buffer, bool wait = false)
-{
- // Who cares?
- //if (!bv->text)
- // return false;
-
- ProhibitInput(current_view);
-
- // Generate dvi file
- if (MakeLaTeXOutput(buffer) > 0) {
- AllowInput(current_view);
- return false;
- }
- // Generate postscript file
- string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
- ".ps_tmp"));
-
- string paper;
-
- // Wrong type
- char real_papersize = buffer->params.papersize;
- if (real_papersize == BufferParams::PAPER_DEFAULT)
- real_papersize = lyxrc.default_papersize;
-
- 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 an empty value... */
- break;
- }
-
- // Make postscript file.
- string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
- command += QuoteName(psname);
- 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
- command += ' ';
- command += lyxrc.print_paper_dimension_flag + ' ';
- command += buffer->params.paperwidth + ',';
- command += buffer->params.paperheight;
- } else if (!paper.empty()
- && (real_papersize != BufferParams::PAPER_USLETTER ||
- buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
- // dvips won't accept -t letter -t landscape. In all other
- // cases, include the paper size explicitly.
- command += ' ';
- command += lyxrc.print_paper_flag + ' ' + paper;
- }
- if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
- command += ' ';
- command += lyxrc.print_landscape_flag;
- }
- // push directorypath, if necessary
- string path = OnlyPath(buffer->fileName());
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
- path = buffer->tmppath;
- }
- Path p(path);
- bool ret = RunScript(buffer, wait, command);
- AllowInput(current_view);
- return ret;
-}
-
-
-// Returns false if we fail
-//bool MenuPreviewPS(Buffer * buffer)
-bool PreviewPostscript(Buffer * buffer)
-{
- // Who cares?
- //if (!bv->text)
- // return false;
-
- // Generate postscript file
- if (!CreatePostscript(buffer, true)) {
- return false;
- }
-
- // Start postscript viewer
- ProhibitInput(current_view);
- string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
- ".ps_tmp"));
- // push directorypath, if necessary
- string path = OnlyPath(buffer->fileName());
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
- path = buffer->tmppath;
- }
- Path p(path);
- bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
- AllowInput(current_view);
- return ret;
-}
-#endif
-
-void MenuFax(Buffer * buffer)
-{
- // Who cares?
- //if (!bv->text)
- // return;
-
-#ifdef NEW_EXPORT
- // Generate postscript file
- if (!Exporter::Export(buffer, "ps", true))
- return;
-
- // Send fax
- string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
- ".ps"));
-#else
- // Generate postscript file
- if (!CreatePostscript(buffer, true)) {
- return;
- }
-
- // Send fax
- string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
- ".ps_tmp"));
-#endif
- string path = OnlyPath (buffer->fileName());
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
- path = buffer->tmppath;
- }
- Path p(path);
- if (!lyxrc.fax_program.empty()) {
- string help2 = subst(lyxrc.fax_program, "$$FName", ps);
- help2 += " &";
- Systemcalls one(Systemcalls::System, help2);
- } else
- send_fax(ps, lyxrc.fax_command);
-}
-
-
-#ifndef NEW_EXPORT
-// Returns false if we fail
-bool PreviewDVI(Buffer * buffer)
-{
- // Who cares?
- //if (!bv->text)
- // return false;
-
- string paper = lyxrc.view_dvi_paper_option;
- if (!paper.empty()) {
- // wrong type
- char real_papersize = buffer->params.papersize;
- if (real_papersize == BufferParams::PAPER_DEFAULT)
- real_papersize = lyxrc.default_papersize;
-
- switch (real_papersize) {
- case BufferParams::PAPER_USLETTER:
- paper += " us";
- 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 the empty value */
- break;
- }
- if (real_papersize==' ') {
- // if (paper.empty()) {
- if (buffer->params.orientation
- == BufferParams::ORIENTATION_LANDSCAPE)
- // we HAVE to give a size when the page is in
- // landscape, so use USletter.
- paper = " -paper usr";
- } else {
- // paper = " -paper " + paper;
- if (buffer->params.orientation
- == BufferParams::ORIENTATION_LANDSCAPE)
- paper+= 'r';
- }
- }
- // push directorypath, if necessary
- string path = OnlyPath(buffer->fileName());
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
- path = buffer->tmppath;
- }
- Path p(path);
- // Run dvi-viewer
- string command = lyxrc.view_dvi_command + " " + paper;
- bool ret = RunScript(buffer, false, command);
- return ret;
-}
-
-
-bool AskOverwrite(Buffer * buffer, string const & s)
-{
- if (lyxrc.use_gui) {
- // be friendly if there is a gui
- FileInfo fi(s);
- if (fi.readable() &&
- !AskQuestion(_("File already exists:"),
- MakeDisplayPath(s, 50),
- _("Do you want to overwrite the file?"))) {
- ShowMessage(buffer, _("Canceled"));
- return false;
- }
- }
- return true;
-}
-
-
-void MenuMakeLaTeX(Buffer * buffer)
-{
- // Why care about this?
- //if (!bv->text)
- // return;
-
- // Get LaTeX-Filename
- string s = buffer->getLatexName(false);
-
- if (!AskOverwrite(buffer, s))
- return;
-
- if (buffer->isDocBook())
- ShowMessage(buffer, _("DocBook does not have a latex backend"));
- else {
- if (buffer->isLinuxDoc())
- RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
- else
- buffer->makeLaTeXFile(s, string(), true);
- ShowMessage(buffer, _("Nice LaTeX file saved as"),
- MakeDisplayPath(s));
- }
-}
-
-
-void MenuMakeLinuxDoc(Buffer * buffer)
-{
- // Who cares?
- //if (!bv->text) return;
-
- if (!buffer->isLinuxDoc()) {
- WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
- return;
- }
-
- // Get LinuxDoc-Filename
- string s = ChangeExtension(buffer->fileName(), ".sgml");
-
- if (!AskOverwrite(buffer, s))
- return;
-
- ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
- MakeDisplayPath(s),"'...");
-
- buffer->makeLinuxDocFile(s, true);
- buffer->redraw();
- ShowMessage(buffer, _("LinuxDoc SGML file save as"),
- MakeDisplayPath(s));
-}
-
-
-void MenuMakeDocBook(Buffer * buffer)
-{
- // Who cares?
- //if (!bv->text) return;
-
- if (!buffer->isDocBook()) {
- WriteAlert(_("Error!"),
- _("Document class must be docbook."));
- return;
- }
-
- // Get DocBook-Filename
- string s = ChangeExtension(buffer->fileName(), ".sgml");
-
- if (!AskOverwrite(buffer, s))
- return;
-
- ShowMessage(buffer, _("Building DocBook SGML file `"),
- MakeDisplayPath(s), "'...");
-
- buffer->makeDocBookFile(s, true);
- buffer->redraw();
- ShowMessage(buffer, _("DocBook SGML file save as"),
- MakeDisplayPath(s));
-}
-
-
-void MenuMakeAscii(Buffer * buffer)
-{
- // Who cares?
- //if (!bv->text) return;
-
- /* get LaTeX-Filename */
- string s = ChangeExtension (buffer->fileName(), ".txt");
-
-
- if (!AskOverwrite(buffer, s))
- return;
-
- buffer->writeFileAscii(s, lyxrc.ascii_linelen);
-
- ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
-}
-
-
-void MenuMakeHTML(Buffer * buffer)
-{
- // First, create LaTeX file
- MenuMakeLaTeX(buffer);
-
- // And now, run the converter
- string file = buffer->fileName();
- Path path(OnlyPath(file));
- // the tex file name has to be correct for
- // latex, but the html file name can be
- // anything.
- string result = ChangeExtension(file, ".html");
- string infile = buffer->getLatexName(false);
- string tmp = lyxrc.html_command;
- tmp = subst(tmp, "$$FName", infile);
- tmp = subst(tmp, "$$OutName", result);
- Systemcalls one;
- int res = one.startscript(Systemcalls::System, tmp);
- if (res == 0) {
- ShowMessage(buffer, _("Document exported as HTML to file `")
- + MakeDisplayPath(result) +'\'');
- } else {
- ShowMessage(buffer, _("Unable to convert to HTML the file `")
- + MakeDisplayPath(infile)
- + '\'');
- }
-
-}
-
-
-void MenuMakeHTML_LinuxDoc(Buffer * buffer)
-{
- // First, create LinuxDoc file
- MenuMakeLinuxDoc(buffer);
-
- // And now, run the converter
- string file = buffer->fileName();
-
- string result = ChangeExtension(file, ".html");
- string infile = ChangeExtension(file, ".sgml");
- string tmp = lyxrc.linuxdoc_to_html_command;
- tmp = subst(tmp, "$$FName", infile);
- tmp = subst(tmp, "$$OutName", result);
- Systemcalls one;
- int res = one.startscript(Systemcalls::System, tmp);
- if (res == 0) {
- ShowMessage(buffer,_("Document exported as HTML to file `")
- + MakeDisplayPath(result) +'\'');
- } else {
- ShowMessage(buffer,_("Unable to convert to HTML the file `")
- + MakeDisplayPath(infile)
- + '\'');
- }
-
-}
-
-void MenuMakeHTML_DocBook(Buffer * buffer)
-{
- // First, create LaTeX file
- MenuMakeDocBook(buffer);
-
- // And now, run the converter
- string file = buffer->fileName();
- string result = ChangeExtension(file, ".html");
- string infile = ChangeExtension(file, ".sgml");
- string tmp = lyxrc.docbook_to_html_command;
- tmp = subst(tmp, "$$FName", infile);
- tmp = subst(tmp, "$$OutName", result);
- Systemcalls one;
- int res = one.startscript(Systemcalls::System, tmp);
- if (res == 0) {
- ShowMessage(buffer,_("Document exported as HTML to file `")
- + MakeDisplayPath(result) +'\'');
- } else {
- ShowMessage(buffer,_("Unable to convert to HTML the file `")
- + MakeDisplayPath(infile)
- + '\'');
- }
-
-}
-
-
-void MenuExport(Buffer * buffer, string const & extyp)
-{
- // latex
- if (extyp == "latex") {
- // make sure that this buffer is not linuxdoc
- MenuMakeLaTeX(buffer);
- }
- // linuxdoc
- else if (extyp == "linuxdoc") {
- // make sure that this buffer is not latex
- MenuMakeLinuxDoc(buffer);
- }
- // docbook
- else if (extyp == "docbook") {
- // make sure that this buffer is not latex or linuxdoc
- MenuMakeDocBook(buffer);
- }
- // dvi
- else if (extyp == "dvi") {
- // Run LaTeX as "Update dvi..." Bernhard.
- // We want the dvi in the current directory. This
- // is achieved by temporarily disabling use of
- // temp directory. As a side-effect, we get
- // *.log and *.aux files also. (Asger)
- bool flag = lyxrc.use_tempdir;
- lyxrc.use_tempdir = false;
- MenuRunLaTeX(buffer);
- lyxrc.use_tempdir = flag;
- }
- // postscript
- else if (extyp == "postscript") {
- // Start Print-dialog. Not as good as dvi... Bernhard.
- //should start lyxview->getDialogs()->showPrint();
- // to get same as before
- // MenuPrint(buffer);
- // Since the MenuPrint is a pop-up, we can't use
- // the same trick as above. (Asger)
- // MISSING: Move of ps-file :-(
- // And MenuPrint should not be used for this at all...
- }
- // ascii
- else if (extyp == "ascii") {
- MenuMakeAscii(buffer);
- }
- else if (extyp == "custom") {
- MenuSendto();
- }
- // HTML
- else if (extyp == "html") {
- if (buffer->isLinuxDoc())
- MenuMakeHTML_LinuxDoc(buffer);
- else if (buffer->isDocBook())
- MenuMakeHTML_DocBook(buffer);
- else
- MenuMakeHTML(buffer);
- }
- else {
- ShowMessage(buffer, _("Unknown export type: ") + extyp);
- }
-}
-#endif
-