1999-10-13 17:32:46 +00:00
|
|
|
// -*- 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"
|
1999-11-01 04:22:28 +00:00
|
|
|
#include "lyxlib.h"
|
1999-10-13 17:32:46 +00:00
|
|
|
|
|
|
|
class Path {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
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())) {
|
1999-10-13 17:32:46 +00:00
|
|
|
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;
|
|
|
|
}
|
1999-11-01 04:22:28 +00:00
|
|
|
if (lyx::chdir(pushedDir_.c_str())) {
|
1999-10-13 17:32:46 +00:00
|
|
|
WriteFSAlert(
|
|
|
|
_("Error: Could not change to directory: "),
|
|
|
|
pushedDir_);
|
|
|
|
}
|
|
|
|
popped_ = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
#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
|