From: Lars Gullik Bjønnes Date: Wed, 13 Oct 1999 17:32:46 +0000 (+0000) Subject: merge in the class Path changes X-Git-Tag: 1.6.10~22615 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=535dd32c4ca49739583b37293e28db48ac1ecec3;p=features.git merge in the class Path changes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@196 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 4f7c730cf1..6dff72a6bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 1999-10-13 Lars Gullik Bjønnes + * src/LaTeXLog.C (ShowLatexLog): reordered som statements so that + Path would fit in more nicely. + + * all files that used to use pathstack: uses now Path instead. + This change was a lot easier than expected. + + * src/support/path.h: new file + + * src/support/Makefile.am (libsupport_a_SOURCES): added path.h + + * src/Makefile.am (lyx_SOURCES): removed pathstack.[Ch] + * src/support/lyxstring.C (getline): Default arg was given for para 3. removed. diff --git a/po/POTFILES.in b/po/POTFILES.in index a6c943eb52..e2afa4cf4c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -72,11 +72,11 @@ src/menus.C src/minibuffer.C src/minibuffer.h src/paragraph.C -src/pathstack.C src/print_form.C src/sp_form.C src/spellchecker.C src/support/filetools.C src/support/lyxlib.h +src/support/path.h src/text.C src/text2.C diff --git a/src/Chktex.C b/src/Chktex.C index a9925def5d..dc94696ace 100644 --- a/src/Chktex.C +++ b/src/Chktex.C @@ -27,7 +27,7 @@ #include "debug.h" #include "support/syscall.h" #include "support/syscontr.h" -#include "pathstack.h" +#include "support/path.h" #include "gettext.h" /* diff --git a/src/LaTeX.C b/src/LaTeX.C index 0c8318d91b..b1758d2749 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -28,7 +28,7 @@ #include "support/lyxlib.h" #include "support/syscall.h" #include "support/syscontr.h" -#include "pathstack.h" +#include "support/path.h" #include "bufferlist.h" #include "minibuffer.h" #include "gettext.h" @@ -682,7 +682,7 @@ void LaTeX::deplog(DepTable & head) // found in the same dir // as the .lyx file and // should be inserted. - PathPush(path); + Path p(path); if (FileInfo(foundfile).exist()) { lyxerr << "LyX Strange: this should actually never" " happen anymore, this it should be" @@ -691,10 +691,8 @@ void LaTeX::deplog(DepTable & head) lyxerr[Debug::LATEX] << "Same Directory file: " << foundfile << endl; head.insert(foundfile); - PathPop(); continue; } - PathPop(); lyxerr[Debug::LATEX] << "Not a file or we are unable to find it." diff --git a/src/LaTeXLog.C b/src/LaTeXLog.C index f9d413637f..ac215a71f6 100644 --- a/src/LaTeXLog.C +++ b/src/LaTeXLog.C @@ -8,7 +8,7 @@ #include "LString.h" #include "support/FileInfo.h" #include "support/filetools.h" -#include "pathstack.h" +#include "support/path.h" #include "lyxrc.h" #include "BufferView.h" #include "gettext.h" @@ -18,37 +18,39 @@ extern BufferView *current_view; void ShowLatexLog() { - string filename, fname, bname, path; - bool use_build = false; + string filename, fname, bname, path; + bool use_build = false; - filename = current_view->currentBuffer()->getFileName(); - if (!filename.empty()) { - fname = SpaceLess(ChangeExtension(filename, ".log", true)); - bname = SpaceLess(ChangeExtension(filename, lyxrc->literate_extension + ".out", true)); - path = OnlyPath(filename); - if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { - path = current_view->currentBuffer()->tmppath; + filename = current_view->currentBuffer()->getFileName(); + if (!filename.empty()) { + fname = SpaceLess(ChangeExtension(filename, ".log", true)); + bname = SpaceLess(ChangeExtension(filename, + lyxrc->literate_extension + ".out", true)); + path = OnlyPath(filename); + if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { + path = current_view->currentBuffer()->tmppath; + } + FileInfo f_fi(path + fname), b_fi(path + bname); + if (b_fi.exist()) + if (!f_fi.exist() + || f_fi.getModificationTime() < b_fi.getModificationTime()) + use_build = true; // If no Latex log or Build log is newer, show Build log + Path p(path); // path to LaTeX file + if (!fl_load_browser(fd_latex_log->browser_latexlog, + use_build ? bname.c_str() : fname.c_str())) + fl_add_browser_line(fd_latex_log->browser_latexlog, + _("Unable to show log file!")); + } else { + fl_add_browser_line(fd_latex_log->browser_latexlog, + _("NO LATEX LOG FILE!")); + } + if (fd_latex_log->LaTeXLog->visible) { + fl_raise_form(fd_latex_log->LaTeXLog); + } else { + fl_show_form(fd_latex_log->LaTeXLog, + FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER, + use_build ? _("Build Program Log") : _("LaTeX Log")); } - FileInfo f_fi(path + fname), b_fi(path + bname); - if (b_fi.exist()) - if ( ! f_fi.exist() - || f_fi.getModificationTime() < b_fi.getModificationTime()) - use_build = true; // If no Latex log or Build log is newer, show Build log - PathPush(path); // path to LaTeX file - } - if (!fl_load_browser(fd_latex_log->browser_latexlog, - (use_build)?bname.c_str():fname.c_str())) - fl_add_browser_line(fd_latex_log->browser_latexlog, _("NO LATEX LOG FILE!")); - if (fd_latex_log->LaTeXLog->visible) { - fl_raise_form(fd_latex_log->LaTeXLog); - } - else { - fl_show_form(fd_latex_log->LaTeXLog, - FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER, - (use_build)?_("Build Program Log"):_("LaTeX Log")); - } - if (!filename.empty()) - PathPop(); } void LatexLogClose(FL_OBJECT *, long) diff --git a/src/Literate.C b/src/Literate.C index 74339838ec..a91a40b267 100644 --- a/src/Literate.C +++ b/src/Literate.C @@ -26,7 +26,7 @@ #include "support/lyxlib.h" #include "support/syscall.h" #include "support/syscontr.h" -#include "pathstack.h" +#include "support/path.h" #include "bufferlist.h" #include "minibuffer.h" #include "gettext.h" diff --git a/src/LyXSendto.C b/src/LyXSendto.C index 4c987c6366..271c6a33be 100644 --- a/src/LyXSendto.C +++ b/src/LyXSendto.C @@ -6,7 +6,7 @@ #include "lyxrc.h" #include "LString.h" #include "support/filetools.h" -#include "pathstack.h" +#include "support/path.h" #include "buffer.h" #include "lyx_gui_misc.h" #include "support/syscall.h" @@ -82,7 +82,7 @@ void SendtoApplyCB(FL_OBJECT *, long) if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } - PathPush(path); + Path p(path); // save the .lyx file in tmp_dir if this filetype is requested if (fl_get_button(fd_form_sendto->radio_ftype_lyx)) buffer->writeFile(fname,true); @@ -94,7 +94,6 @@ void SendtoApplyCB(FL_OBJECT *, long) if (fl_get_button(fd_form_sendto->radio_ftype_ascii)) buffer->writeFileAscii(fname, lyxrc->ascii_linelen); Systemcalls one(Systemcalls::System, command); - PathPop(); } void SendtoCancelCB(FL_OBJECT *, long) diff --git a/src/Makefile.am b/src/Makefile.am index 4fe62d45dc..30c8b0e469 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -140,8 +140,6 @@ lyx_SOURCES = \ os2_defines.h \ os2_errortable.h \ paragraph.C \ - pathstack.C \ - pathstack.h \ print_form.C \ print_form.h \ screen.C \ diff --git a/src/buffer.C b/src/buffer.C index c84f2bd4eb..6ac2a892f0 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -63,7 +63,7 @@ #include "insets/insetspecialchar.h" #include "insets/figinset.h" #include "support/filetools.h" -#include "pathstack.h" +#include "support/path.h" #include "LaTeX.h" #include "Literate.h" #include "Chktex.h" @@ -3132,7 +3132,7 @@ int Buffer::runLaTeX() path = tmppath; } - PathPush(path); // path to LaTeX file + Path p(path); // path to LaTeX file users->getOwner()->getMiniBuffer()->Set(_("Running LaTeX...")); // Remove all error insets @@ -3179,7 +3179,6 @@ int Buffer::runLaTeX() users->updateScrollbar(); } AllowInput(); - PathPop(); // path to LaTeX file return latex.getNumErrors(); } @@ -3203,7 +3202,7 @@ int Buffer::runLiterate() path = tmppath; } - PathPush(path); // path to Literate file + Path p(path); // path to Literate file users->getOwner()->getMiniBuffer()->Set(_("Running Literate...")); // Remove all error insets @@ -3248,7 +3247,6 @@ int Buffer::runLiterate() users->updateScrollbar(); } AllowInput(); - PathPop(); // path to LaTeX file return literate.getNumErrors(); } @@ -3272,7 +3270,7 @@ int Buffer::buildProgram() path = tmppath; } - PathPush(path); // path to Literate file + Path p(path); // path to Literate file users->getOwner()->getMiniBuffer()->Set(_("Building Program...")); // Remove all error insets @@ -3316,7 +3314,6 @@ int Buffer::buildProgram() users->updateScrollbar(); } AllowInput(); - PathPop(); // path to LaTeX file return literate.getNumErrors(); } @@ -3340,7 +3337,7 @@ int Buffer::runChktex() path = tmppath; } - PathPush(path); // path to LaTeX file + Path p(path); // path to LaTeX file users->getOwner()->getMiniBuffer()->Set(_("Running chktex...")); // Remove all error insets @@ -3372,7 +3369,6 @@ int Buffer::runChktex() users->updateScrollbar(); } AllowInput(); - PathPop(); // path to LaTeX file return res; } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 4e9e78d556..43a263404b 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -42,7 +42,7 @@ #include "combox.h" #include "bufferlist.h" #include "support/filetools.h" -#include "pathstack.h" +#include "support/path.h" #include "filedlg.h" #include "lyx_gui_misc.h" #include "LyXView.h" // only because of form_main @@ -549,9 +549,8 @@ int MakeDVIOutput(Buffer *buffer) path = buffer->tmppath; } if (!buffer->isDviClean()) { - PathPush(path); + Path p(path); ret = MenuRunLaTeX(buffer); - PathPop(); } return ret; } @@ -581,7 +580,7 @@ bool RunScript(Buffer *buffer, bool wait, if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { path = buffer->tmppath; } - PathPush(path); + Path p(path); cmd = command + ' ' + SpaceLess(name); Systemcalls one; @@ -622,7 +621,6 @@ bool RunScript(Buffer *buffer, bool wait, result = one.startscript(wait ? Systemcalls::Wait : Systemcalls::DontWait, cmd); } - PathPop(); return (result==0); } @@ -706,10 +704,9 @@ bool MenuRunDvips(Buffer *buffer, bool wait=false) if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } - PathPush(path); + Path p(path); bool ret = RunScript(buffer, wait, command); AllowInput(); - PathPop(); return ret; } @@ -734,9 +731,8 @@ bool MenuPreviewPS(Buffer *buffer) if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } - PathPush(path); + Path p(path); bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps); - PathPop(); AllowInput(); return ret; } @@ -758,7 +754,7 @@ void MenuFax(Buffer *buffer) if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { path = buffer->tmppath; } - PathPush(path); + Path p(path); if (!lyxrc->fax_program.empty()) { string help2 = lyxrc->fax_program; subst(help2, "$$FName",ps); @@ -766,7 +762,6 @@ void MenuFax(Buffer *buffer) Systemcalls one(Systemcalls::System, help2); } else send_fax(ps,lyxrc->fax_command); - PathPop(); } @@ -824,11 +819,10 @@ bool MenuPreview(Buffer *buffer) if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } - PathPush(path); + Path p(path); // Run dvi-viewer string command = lyxrc->view_dvi_command + paper ; bool ret = RunScript(buffer, false, command); - PathPop(); return ret; } @@ -1254,7 +1248,7 @@ int RunLinuxDoc(int flag, string const & filename) if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { path = current_view->currentBuffer()->tmppath; } - PathPush (path); + Path p(path); if (flag != -1) { if (!current_view->available()) @@ -1300,7 +1294,6 @@ int RunLinuxDoc(int flag, string const & filename) break; } - PathPop(); AllowInput(); current_view->currentBuffer()->redraw(); @@ -1326,7 +1319,7 @@ int RunDocBook(int flag, string const & filename) if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { path = current_view->currentBuffer()->tmppath; } - PathPush (path); + Path p(path); if (!current_view->available()) return 0; @@ -1357,7 +1350,6 @@ int RunDocBook(int flag, string const & filename) break; } - PathPop(); AllowInput(); current_view->currentBuffer()->redraw(); @@ -3391,7 +3383,7 @@ void PrintApplyCB(FL_OBJECT *, long) if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } - PathPush(path); + Path p(path); bool result; if (!lyxrc->print_spool_command.empty() && @@ -3406,7 +3398,6 @@ void PrintApplyCB(FL_OBJECT *, long) } } else result = RunScript(buffer, false, command); - PathPop(); if (!result) WriteAlert(_("Error:"), @@ -3561,10 +3552,10 @@ void Reconfigure() minibuffer->Set(_("Running configure...")); // Run configure in user lyx directory - PathPush(user_lyxdir); + Path p(user_lyxdir); Systemcalls one(Systemcalls::System, AddName(system_lyxdir,"configure")); - PathPop(); + p.pop(); minibuffer->Set(_("Reloading configuration...")); lyxrc->Read(LibFileSearch(string(), "lyxrc.defaults")); WriteAlert(_("The system has been reconfigured."), diff --git a/src/lyx_main.C b/src/lyx_main.C index 6fb2df8d0e..21e48e0526 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -18,7 +18,7 @@ #include "lyx_gui.h" #include "lyx_gui_misc.h" #include "lyxrc.h" -#include "pathstack.h" +#include "support/path.h" #include "support/filetools.h" #include "bufferlist.h" #include "debug.h" @@ -411,9 +411,8 @@ void LyX::queryUserLyXDir() } // Run configure in user lyx directory - PathPush(user_lyxdir); + Path p(user_lyxdir); system(AddName(system_lyxdir,"configure").c_str()); - PathPop(); lyxerr << "LyX: " << _("Done!") << endl; } diff --git a/src/lyxrc.C b/src/lyxrc.C index 8ab22566df..9791d88ff5 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -22,7 +22,7 @@ #include "lyx_main.h" #include "intl.h" #include "tex-strings.h" -#include "pathstack.h" +#include "support/path.h" #include "support/filetools.h" #include "lyxtext.h" diff --git a/src/lyxvc.C b/src/lyxvc.C index 70f361c3be..28d036d14b 100644 --- a/src/lyxvc.C +++ b/src/lyxvc.C @@ -10,7 +10,7 @@ #include "lyx_gui_misc.h" #include "bufferlist.h" #include "support/syscall.h" -#include "pathstack.h" +#include "support/path.h" #include "support/filetools.h" #include "support/FileInfo.h" #include "gettext.h" @@ -385,8 +385,7 @@ int LyXVC::doVCCommand(string const & cmd) { lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl; Systemcalls one; - PathPush(_owner->filepath); + Path p(_owner->filepath); int ret = one.startscript(Systemcalls::System, cmd); - PathPop(); return ret; } diff --git a/src/mathed/math_panel.h b/src/mathed/math_panel.h index 3c34f3f6c7..c2a5456457 100644 --- a/src/mathed/math_panel.h +++ b/src/mathed/math_panel.h @@ -35,6 +35,10 @@ enum { /// typedef FL_OBJECT* FL_OBJECTP; +extern "C" { + int peek_event(FL_FORM *, void *); +} + /// Class to manage bitmap menu bars class BitmapMenu { /// diff --git a/src/mathed/math_symbols.C b/src/mathed/math_symbols.C index 133834774b..47d31664f9 100644 --- a/src/mathed/math_symbols.C +++ b/src/mathed/math_symbols.C @@ -232,6 +232,7 @@ int BitmapMenu::GetIndex(FL_OBJECT* ob) return -1; } +extern "C" { int peek_event(FL_FORM * /*form*/, void *xev) { if (BitmapMenu::active==0) @@ -257,6 +258,7 @@ int peek_event(FL_FORM * /*form*/, void *xev) } return 0; } +} static void math_cb(FL_OBJECT* ob, long data) { diff --git a/src/pathstack.C b/src/pathstack.C deleted file mode 100644 index 7788e0eb37..0000000000 --- a/src/pathstack.C +++ /dev/null @@ -1,86 +0,0 @@ -// lyx-stack.C : implementation of PathStack class -// this file is part of LyX, the High Level Word Processor -// copyright (C) 1995-1996, Matthias Ettrich and the LyX Team - -#include -#include - -#ifdef __GNUG__ -#pragma implementation "pathstack.h" -#endif - -#include "pathstack.h" -#include "support/filetools.h" -#include "debug.h" -#include "LString.h" -#include "gettext.h" - -// temporary hack -#include "lyx_gui_misc.h" - -// global path stack -PathStack lyxPathStack; - -// Standard constructor -PathStack::PathStack(string const & string) - : Path(string) -{ - Next = 0; -} - -// Destructor -PathStack::~PathStack() -{ - if (Next) - delete Next; -} - -// Changes to directory -int PathStack::PathPush(string const & Path) -{ - // checks path string validity - if (Path.empty()) return 1; - - PathStack *NewNode; - - // gets current directory and switch to new one - string CurrentPath = GetCWD(); - if ((CurrentPath.empty()) || chdir(Path.c_str())) { - WriteFSAlert(_("Error: Could not change to directory: "), - Path); - return 2; - } - - lyxerr.debug() << "PathPush: " << Path << endl; - // adds new node - NewNode = new PathStack(CurrentPath); - NewNode->Next = Next; - Next = NewNode; - return 0; -} - -// Goes back to previous directory -int PathStack::PathPop() -{ - // checks stack validity and extracts old node - PathStack *OldNode = Next; - if (!OldNode) { - WriteAlert (_("LyX Internal Error:"), _("Path Stack underflow.")); - return 1; - } - Next = OldNode->Next; - OldNode->Next = 0; - - // switches to old directory - int Result = 0; - if (chdir(OldNode->Path.c_str())) { - WriteFSAlert(_("Error: Could not change to directory: "), - Path); - Result = 2; - } - lyxerr.debug() << "PathPop: " << OldNode->Path << endl; - delete OldNode; - - return Result; -} - diff --git a/src/pathstack.h b/src/pathstack.h deleted file mode 100644 index ffe81380ef..0000000000 --- a/src/pathstack.h +++ /dev/null @@ -1,50 +0,0 @@ -// -*- C++ -*- -// lyx-stack.H : definition of PathStack class -// this file is part of LyX, the High Level Word Processor -// copyright (C) 1995-1996, Matthias Ettrich and the LyX Team - -#ifndef __LYX_STACK_H__ -#define __LYX_STACK_H__ - -#ifdef __GNUG__ -#pragma interface -#endif - -#include "LString.h" - -/// Path stack class definition -class PathStack { -public: - /// - PathStack() { - Next = 0; - } - /// - PathStack(string const & Path); - /// - ~PathStack(); - /// - int PathPush(string const & Path); - /// - int PathPop(); -private: - /// - string Path; - /// - PathStack *Next; -}; - -// global path stack -extern PathStack lyxPathStack; - -/// some global wrapper functions -inline int PathPush(string const & szPath) { - return lyxPathStack.PathPush(szPath); -} - -/// -inline int PathPop() { - return lyxPathStack.PathPop(); -} - -#endif diff --git a/src/support/Makefile.am b/src/support/Makefile.am index fe0e8e717c..45fa24ee8d 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -17,6 +17,7 @@ libsupport_a_SOURCES = \ lyxstring.C \ lyxstring.h \ lyxsum.C \ + path.h \ syscall.C \ syscall.h \ syscontr.C \ diff --git a/src/support/filetools.C b/src/support/filetools.C index ad1f61d745..bb8edb2e4b 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -25,7 +25,7 @@ #include "filetools.h" #include "lyx_gui_misc.h" #include "FileInfo.h" -#include "pathstack.h" // I know it's OS/2 specific (SMiyata) +#include "support/path.h" // I know it's OS/2 specific (SMiyata) #include "gettext.h" #include "LAssert.h" diff --git a/src/support/path.h b/src/support/path.h new file mode 100644 index 0000000000..ad5a905b40 --- /dev/null +++ b/src/support/path.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +#ifndef PATH_H +#define PATH_H + +#include +#include "LString.h" +#include "gettext.h" +#include "support/filetools.h" +#include "lyx_gui_misc.h" + +class Path { +public: + /// + Path(string const & path) + : popped_(false) + { + if (!path.empty()) { + pushedDir_ = GetCWD(); + if (pushedDir_.empty() || chdir(path.c_str())) { + WriteFSAlert(_("Error: Could not change to directory: "), + path); + } + } else { + popped_ = true; + } + } + /// + ~Path() + { + if (!popped_) pop(); + } + /// + int pop() + { + if (popped_) { + WriteFSAlert(_("Error: Dir already popped: "), + pushedDir_); + return 0; + } + if (chdir(pushedDir_.c_str())) { + WriteFSAlert( + _("Error: Could not change to directory: "), + pushedDir_); + } + popped_ = true; + return 0; + } +private: + /// + bool popped_; + /// + string pushedDir_; +}; + +#endif