home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / path.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  907b  |  60 lines

  1. // -*- C++ -*-
  2. #ifndef __PATH_H__
  3. #define __PATH_H__
  4.  
  5. //#ifdef __GNUG__
  6. //#pragma interface
  7. //#endif
  8.  
  9. #include <unistd.h>
  10. #include "LString.h"
  11. #include "gettext.h"
  12. #include "filetools.h"
  13. #include "lyx_gui_misc.h"
  14.  
  15. class Path {
  16. public:
  17.     ///
  18.     Path(LString const & path)
  19.         : popped_(false)
  20.     {
  21.         if (!path.empty()) { 
  22.             pushedDir_ = GetCWD();
  23.             if (pushedDir_.empty() || chdir(path.c_str())) {
  24.                 WriteFSAlert(_("Error: Could not change to directory: "), 
  25.                          path);
  26.             }
  27.         } else {
  28.             popped_ = true;
  29.         }
  30.     }
  31.     ///
  32.     ~Path()
  33.     {
  34.         if (!popped_) pop();
  35.     }
  36.     ///
  37.     int pop()
  38.     {
  39.         if (popped_) {
  40.             WriteFSAlert(_("Error: Dir already popped: "),
  41.                      pushedDir_);
  42.             return 0;
  43.         }
  44.         if (chdir(pushedDir_.c_str())) {
  45.             WriteFSAlert(
  46.                 _("Error: Could not change to directory: "), 
  47.                 pushedDir_);
  48.         }
  49.         popped_ = true;
  50.         return 0;
  51.     }
  52.     
  53. protected:
  54. private:
  55.     bool popped_;
  56.     LString pushedDir_;
  57. };
  58.  
  59. #endif
  60.