]> git.lyx.org Git - lyx.git/blob - src/support/path.C
hopefully fix tex2lyx linking.
[lyx.git] / src / support / path.C
1 /**
2  * \file path.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Needed to prevent the definition of the unnamed_Path macro in the header file.
14 #define PATH_C
15
16 #include "support/path.h"
17 #include "support/lyxlib.h"
18
19
20 using std::string;
21
22
23 namespace lyx {
24 namespace support {
25
26 Path::Path(string const & path)
27         : popped_(false)
28 {
29         if (!path.empty()) {
30                 pushedDir_ = getcwd();
31
32                 if (pushedDir_.empty() || chdir(path)) {
33                         /* FIXME: throw */
34                 }
35         } else {
36                 popped_ = true;
37         }
38 }
39
40
41 Path::~Path()
42 {
43         if (!popped_) pop();
44 }
45
46
47 int Path::pop()
48 {
49         if (popped_) {
50                 // should throw an exception
51                 // throw logical_error();
52                 return 0;
53         }
54
55         if (chdir(pushedDir_)) {
56                 // should throw an exception
57                 // throw DirChangeError();
58         }
59         popped_ = true;
60
61         return 0;
62 }
63
64 } // namespace support
65 } // namespace lyx