]> git.lyx.org Git - features.git/commitdiff
merge in the class Path changes
authorLars Gullik Bjønnes <larsbj@gullik.org>
Wed, 13 Oct 1999 17:32:46 +0000 (17:32 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Wed, 13 Oct 1999 17:32:46 +0000 (17:32 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@196 a592a061-630c-0410-9148-cb99ea01b6c8

20 files changed:
ChangeLog
po/POTFILES.in
src/Chktex.C
src/LaTeX.C
src/LaTeXLog.C
src/Literate.C
src/LyXSendto.C
src/Makefile.am
src/buffer.C
src/lyx_cb.C
src/lyx_main.C
src/lyxrc.C
src/lyxvc.C
src/mathed/math_panel.h
src/mathed/math_symbols.C
src/pathstack.C [deleted file]
src/pathstack.h [deleted file]
src/support/Makefile.am
src/support/filetools.C
src/support/path.h [new file with mode: 0644]

index 4f7c730cf12f081df63a9164e61a9f2acf96443c..6dff72a6bc4c81815b5943d1bb41aa893b3be7b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 1999-10-13  Lars Gullik Bjønnes  <larsbj@lyx.org>
 
+       * 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.
 
index a6c943eb52564fae1851183e291f61ede148c48b..e2afa4cf4c0cb223fd11cd5938b38691ddb6ba3a 100644 (file)
@@ -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
index a9925def5d69eb211a88bff0c8f3a1cce786d10c..dc94696ace1b5a8317eee8d9a2b7a3c89ef74575 100644 (file)
@@ -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"
 
 /*
index 0c8318d91b32cc7bf0672b8b3d2b148bb966273e..b1758d2749634a7e49bd69b3d7dbd7da588a73d2 100644 (file)
@@ -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."
index f9d413637fa0d7b4387a990a927e50342f3e60a5..ac215a71f6eb9b61dcf59af247b900faa8943601 100644 (file)
@@ -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)
index 74339838ec15ee3d83f26c20b9baf2aae651af18..a91a40b26732eb94267d934a08551a8c29ff4774 100644 (file)
@@ -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"
index 4c987c636631fe1236e78baeaf6741def835e555..271c6a33be599e7b82474bac434d5a44dc6e382f 100644 (file)
@@ -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)
index 4fe62d45dc327263c4a119e52a30c362d3ad5fe6..30c8b0e46969e81126a9e4661355c1c7b4557803 100644 (file)
@@ -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 \
index c84f2bd4eb8ee6b6d1dcfbed713da90c1aae8817..6ac2a892f03fa0fc4f2bf3517f1304b4977a0242 100644 (file)
@@ -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;
 }
index 4e9e78d556dd2058619d9f566d9d0b2aab07405d..43a263404b14e28ddb4754d79b30d07aa8facbfd 100644 (file)
@@ -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."), 
index 6fb2df8d0e3138addead90d580faca25baa03d81..21e48e05265296b848d6a72484c14c866a757715 100644 (file)
@@ -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;
 }
 
index 8ab22566df45b31c35ea6c72171a7be3a1bbc65d..9791d88ff5f91c41583bbe72c70448fdfcfb787f 100644 (file)
@@ -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"
 
index 70f361c3be053a04daf732442823b3e79ae3c927..28d036d14bcb90bde497e78af72f6fc9495efd61 100644 (file)
@@ -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;
 }
index 3c34f3f6c78b3e182dcb4079649d6dec6cebe44c..c2a5456457490ab70addf0413ad032f39b5eb403 100644 (file)
@@ -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 {
   ///
index 133834774b5c51c5b2f3b2089a7cd04d43145807..47d31664f95f3a0383f040dc412b7645fd4f6cd7 100644 (file)
@@ -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 (file)
index 7788e0e..0000000
+++ /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 <config.h>
-#include <unistd.h>
-
-#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 (file)
index ffe8138..0000000
+++ /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
index fe0e8e717cdb1d31c9ca143ae52b02c818fb9479..45fa24ee8d5c6674b0c0697dafc74327e1ac1536 100644 (file)
@@ -17,6 +17,7 @@ libsupport_a_SOURCES = \
        lyxstring.C \
        lyxstring.h \
        lyxsum.C \
+       path.h \
        syscall.C \
        syscall.h \
        syscontr.C \
index ad1f61d745c89f0b192bbfc4562e273893276af6..bb8edb2e4b334744414e3faaea6a134a1893aa6d 100644 (file)
@@ -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 (file)
index 0000000..ad5a905
--- /dev/null
@@ -0,0 +1,55 @@
+// -*- C++ -*-
+#ifndef PATH_H
+#define PATH_H
+
+#include <unistd.h>
+#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