From 136367d229413ff982dab1068a99a42edc04bca0 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 3 Dec 1999 13:51:01 +0000 Subject: [PATCH] Nuked the SpaceLess function. Read ChangeLog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@349 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 31 +++++++++++++++++++++-- src/LaTeXLog.C | 9 ++++--- src/LyXSendto.C | 4 +-- src/buffer.C | 14 ++++++----- src/buffer.h | 6 +++++ src/lyx_cb.C | 22 ++++++++--------- src/lyxfunc.C | 54 +++++++++++++++++++++-------------------- src/support/filetools.C | 15 +++++++++++- src/support/filetools.h | 7 ++++-- 9 files changed, 107 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c23cd21a8..76772473b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,31 @@ -1999-12-01 Jean-Marc Lasgouttes +1999-12-03 Jean-Marc Lasgouttes + + * src/lyxfunc.C (getStatus): do not query current font if no + buffer exists. + + * src/lyx_cb.C (RunScript): use QuoteName + (MenuRunDvips): ditto + (PrintApplyCB): ditto + + * src/support/filetools.[Ch] (QuoteName): new function. Add quotes + around argument, so that it works well with the current shell. + Does not work properly with OS/2 shells currently. + + * src/LaTeXLog.C (ShowLatexLog): use Buffer::getLatexName + * src/LyXSendto.C (SendtoApplyCB): ditto + * src/lyxfunc.C (Dispatch): ditto + * src/buffer.C (runLaTeX): ditto + (runLiterate): ditto + (buildProgram): ditto + (runChktex): ditto + * src/lyx_cb.C (RunScript): ditto + (MenuMakeLaTeX): ditto + + * src/buffer.h (getLatexName): new method + + * src/support/filetools.C (MakeLatexName): renamed from SpaceLess + +1999-12-02 Jean-Marc Lasgouttes * images/sqrt.xpm: change name of the sqrt icon to sqrt_xpm. * src/mathed/math_panel.C (mathed_get_pixmap_from_icon): ditto @@ -11,7 +38,7 @@ few "using". * src/bmtable.C (fl_set_bmtable_data): add a const_cast. - + 1999-12-01 Lars Gullik Bjønnes * src/mathed/formula.C (LocalDispatch): fix small whitspace bug diff --git a/src/LaTeXLog.C b/src/LaTeXLog.C index fcb3acca8c..19d3c255a2 100644 --- a/src/LaTeXLog.C +++ b/src/LaTeXLog.C @@ -22,11 +22,12 @@ void ShowLatexLog() bool use_build = false; static int ow = -1, oh; - filename = current_view->buffer()->getFileName(); + filename = current_view->buffer()->getLatexName(); if (!filename.empty()) { - fname = SpaceLess(ChangeExtension(filename, ".log", true)); - bname = SpaceLess(ChangeExtension(filename, - lyxrc->literate_extension + ".out", true)); + fname = ChangeExtension(filename, ".log", true); + bname = ChangeExtension(filename, + lyxrc->literate_extension + ".out", + true); path = OnlyPath(filename); if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { path = current_view->buffer()->tmppath; diff --git a/src/LyXSendto.C b/src/LyXSendto.C index e71baf3e23..57c30c97d4 100644 --- a/src/LyXSendto.C +++ b/src/LyXSendto.C @@ -78,8 +78,8 @@ void SendtoApplyCB(FL_OBJECT *, long) return; } } - string fname = SpaceLess(ChangeExtension(buffer->getFileName(), - ftypeext, true)); + + string fname = ChangeExtension(buffer->getLatexName(), ftypeext, true); if (!contains(command, "$$FName")) command = "( " + command + " ) <$$FName"; command = subst(command, "$$FName", fname); diff --git a/src/buffer.C b/src/buffer.C index a0225b5199..d044911f9c 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -3161,7 +3161,7 @@ int Buffer::runLaTeX() ProhibitInput(); // get LaTeX-Filename - string name = SpaceLess(ChangeExtension (filename, ".tex", true)); + string name = getLatexName(); string path = OnlyPath(filename); @@ -3224,9 +3224,10 @@ int Buffer::runLiterate() ProhibitInput(); // get LaTeX-Filename - string name = SpaceLess(ChangeExtension (filename, ".tex", true)); + string name = getLatexName(); // get Literate-Filename - string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true)); + string lit_name = ChangeExtension (getLatexName(), + lyxrc->literate_extension, true); string path = OnlyPath(filename); @@ -3292,9 +3293,10 @@ int Buffer::buildProgram() ProhibitInput(); // get LaTeX-Filename - string name = SpaceLess(ChangeExtension (filename, ".tex", true)); + string name = getLatexName(); // get Literate-Filename - string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true)); + string lit_name = ChangeExtension(getLatexName(), + lyxrc->literate_extension, true); string path = OnlyPath(filename); @@ -3362,7 +3364,7 @@ int Buffer::runChktex() ProhibitInput(); // get LaTeX-Filename - string name = SpaceLess(ChangeExtension (filename, ".tex", true)); + string name = getLatexName(); string path = OnlyPath(filename); string org_path = path; diff --git a/src/buffer.h b/src/buffer.h index 932fb61731..03dea1ae29 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -32,6 +32,7 @@ #include "bufferparams.h" #include "texrow.h" #include "lyxtext.h" +#include "support/filetools.h" class LyXRC; class TeXErrors; @@ -231,6 +232,11 @@ public: /// string getFileName() const { return filename; } + /// A transformed version of the file name, adequate for LaTeX + string getLatexName() const { + return ChangeExtension(MakeLatexName(filename), ".tex", true); + } + /// Change name of buffer. Updates "read-only" flag. void setFileName(string const & newfile); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 17dc46664a..9e0882f2bb 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -557,7 +557,7 @@ bool RunScript(Buffer * buffer, bool wait, return false; /* get DVI-Filename */ if (name.empty()) - name = ChangeExtension(buffer->getFileName(), + name = ChangeExtension(buffer->getLatexName(), ".dvi", true); path = OnlyPath(name); @@ -566,7 +566,8 @@ bool RunScript(Buffer * buffer, bool wait, } Path p(path); - cmd = command + ' ' + SpaceLess(name); + cmd = command + ' ' + QuoteName(name); + Systemcalls one; if (need_shell) { @@ -624,7 +625,7 @@ bool MenuRunDvips(Buffer * buffer, bool wait = false) return false; } // Generate postscript file - string ps = ChangeExtension (buffer->getFileName(), + string psname = ChangeExtension (buffer->getFileName(), ".ps_tmp", true); string paper; @@ -661,7 +662,7 @@ bool MenuRunDvips(Buffer * buffer, bool wait = false) // Make postscript file. string command = "dvips " + lyxrc->print_to_file + ' '; - command += SpaceLess(ps); + command += QuoteName(psname); if (buffer->params.use_geometry && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM && !lyxrc->print_paper_dimension_flag.empty() @@ -815,9 +816,7 @@ void MenuMakeLaTeX(Buffer * buffer) { if (buffer->text) { // Get LaTeX-Filename - string s = SpaceLess(ChangeExtension( - buffer->getFileName(), - ".tex", false)); + string s = buffer->getLatexName(); FileInfo fi(s); if (fi.readable() && @@ -3314,7 +3313,7 @@ extern "C" void PrintApplyCB(FL_OBJECT *, long) if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) orientationflag = lyxrc->print_landscape_flag + ' '; - string ps_file = SpaceLess(fl_get_input(fd_form_print->input_file)); + string ps_file = fl_get_input(fd_form_print->input_file); string printer = strip(fl_get_input(fd_form_print->input_printer)); string printerflag; @@ -3378,12 +3377,11 @@ extern "C" void PrintApplyCB(FL_OBJECT *, long) command += " " + lyxrc->print_paper_flag + " " + paper + " "; } if (fl_get_button(fd_form_print->radio_file)) - command += lyxrc->print_to_file + '\"' - + MakeAbsPath(ps_file, path) - + '\"'; + command += lyxrc->print_to_file + + QuoteName(MakeAbsPath(ps_file, path)); else if (!lyxrc->print_spool_command.empty()) command += lyxrc->print_to_file - + '\"' + ps_file + '\"'; + + QuoteName(ps_file); // push directorypath, if necessary if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 86d7345070..b18ceb47f9 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -398,30 +398,32 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const if (disable) flag |= LyXFunc::Disabled; - func_status box = LyXFunc::ToggleOff; - LyXFont font = buf->text->real_current_font; - switch (action) { - case LFUN_EMPH: - if (font.emph() == LyXFont::ON) - box = LyXFunc::ToggleOn; - break; - case LFUN_NOUN: - if (font.noun() == LyXFont::ON) - box = LyXFunc::ToggleOn; - break; - case LFUN_BOLD: - if (font.series() == LyXFont::BOLD_SERIES) - box = LyXFunc::ToggleOn; - break; - case LFUN_TEX: - if (font.latex() == LyXFont::ON) - box = LyXFunc::ToggleOn; - break; - default: - box = LyXFunc::OK; - break; + if (buf) { + func_status box = LyXFunc::ToggleOff; + LyXFont font = buf->text->real_current_font; + switch (action) { + case LFUN_EMPH: + if (font.emph() == LyXFont::ON) + box = LyXFunc::ToggleOn; + break; + case LFUN_NOUN: + if (font.noun() == LyXFont::ON) + box = LyXFunc::ToggleOn; + break; + case LFUN_BOLD: + if (font.series() == LyXFont::BOLD_SERIES) + box = LyXFunc::ToggleOn; + break; + case LFUN_TEX: + if (font.latex() == LyXFont::ON) + box = LyXFunc::ToggleOn; + break; + default: + box = LyXFunc::OK; + break; + } + flag |= box; } - flag |= box; return flag; @@ -801,9 +803,9 @@ string LyXFunc::Dispatch(int ac, // latex, but the html file name can be // anything. string result = ChangeExtension(file, ".html", false); - file = ChangeExtension(SpaceLess(file), ".tex", false); + string infile = owner->buffer()->getLatexName(); string tmp = lyxrc->html_command; - tmp = subst(tmp, "$$FName", file); + tmp = subst(tmp, "$$FName", infile); tmp = subst(tmp, "$$OutName", result); Systemcalls one; int res = one.startscript(Systemcalls::System, tmp); @@ -812,7 +814,7 @@ string LyXFunc::Dispatch(int ac, + MakeDisplayPath(result) +'\''); } else { setErrorMessage(N_("Unable to convert to HTML the file `") - + MakeDisplayPath(file) + + MakeDisplayPath(infile) + '\''); } } diff --git a/src/support/filetools.C b/src/support/filetools.C index e29bbcdd02..28268b7258 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -26,6 +26,7 @@ using std::pair; #endif #include "filetools.h" +#include "LSubstring.h" #include "lyx_gui_misc.h" #include "FileInfo.h" #include "support/path.h" // I know it's OS/2 specific (SMiyata) @@ -70,7 +71,7 @@ bool IsSGMLFilename(string const & filename) // Substitutes spaces with underscores in filename (and path) -string SpaceLess(string const & file) +string MakeLatexName(string const & file) { string name = OnlyFilename(file); string path = OnlyPath(file); @@ -91,6 +92,18 @@ string SpaceLess(string const & file) return AddName(path, name); } +// Substitutes spaces with underscores in filename (and path) +string QuoteName(string const & name) +{ +#ifdef WITH_WARNINGS +#warning Add proper emx support here! +#endif + string qname = name; + while (qname.find("'") != string::npos) + LSubstring(qname,"'") = "\\'"; + return '\'' + qname + '\''; +} + /// Returns an unique name to be used as a temporary file. string TmpFileName(string const & dir, string const & mask) diff --git a/src/support/filetools.h b/src/support/filetools.h index 84ec94a9e3..72752f1a15 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -208,8 +208,11 @@ bool PutEnv(string const & envstr); /// bool PutEnvPath(string const & envstr); -/// Substitutes spaces with underscores in filename (and path) -string SpaceLess(string const & file); +/// Substitutes active latex characters with underscores in filename +string MakeLatexName(string const & file); + +/// Put the name in quotes suitable for the current shell +string QuoteName(string const & file); /** Returns an unique name to be used as a temporary file. If given, 'mask' should the prefix to the temporary file, the rest of the