1999-10-13 17:32:46 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
#ifndef PATH_H
|
|
|
|
#define PATH_H
|
|
|
|
|
|
|
|
#include "LString.h"
|
2000-08-07 20:58:24 +00:00
|
|
|
#include "filetools.h"
|
1999-11-01 04:22:28 +00:00
|
|
|
#include "lyxlib.h"
|
2000-08-07 20:58:24 +00:00
|
|
|
#include "utility.hpp"
|
1999-10-13 17:32:46 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
///
|
2000-08-07 20:58:24 +00:00
|
|
|
class Path : public noncopyable {
|
1999-10-13 17:32:46 +00:00
|
|
|
public:
|
|
|
|
///
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
1999-10-13 17:32:46 +00:00
|
|
|
Path(string const & path)
|
|
|
|
: popped_(false)
|
|
|
|
{
|
|
|
|
if (!path.empty()) {
|
|
|
|
pushedDir_ = GetCWD();
|
1999-11-01 04:22:28 +00:00
|
|
|
if (pushedDir_.empty() || lyx::chdir(path.c_str())) {
|
2000-04-04 00:19:15 +00:00
|
|
|
// should throw an exception
|
|
|
|
// throw DirChangeError();
|
|
|
|
// The use of WriteFSAlert makes this
|
|
|
|
// impossible to inline.
|
|
|
|
//WriteFSAlert(_("Error: Could not change to directory: "),
|
|
|
|
// path);
|
1999-10-13 17:32:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
popped_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
///
|
|
|
|
~Path()
|
|
|
|
{
|
|
|
|
if (!popped_) pop();
|
|
|
|
}
|
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
int pop();
|
1999-10-13 17:32:46 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
bool popped_;
|
|
|
|
///
|
|
|
|
string pushedDir_;
|
|
|
|
};
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
// To avoid the wrong usage:
|
|
|
|
// Path("/tmp"); // wrong
|
|
|
|
// Path p("/tmp"); // right
|
|
|
|
// we add this macro:
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-01-13 16:28:54 +00:00
|
|
|
#define Path(x) unnamed_Path;
|
|
|
|
// Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
|
|
|
|
|
1999-10-13 17:32:46 +00:00
|
|
|
#endif
|