2002-05-30 02:24:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file path.C
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-05-30 02:24:33 +00:00
|
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-05-30 02:24:33 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2003-09-04 01:44:16 +00:00
|
|
|
|
// Needed to prevent the definition of the unnamed_Path macro in the header file.
|
|
|
|
|
#define PATH_C
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
#include "path.h"
|
2003-09-04 01:44:16 +00:00
|
|
|
|
#include "lyxlib.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace support {
|
|
|
|
|
|
2003-09-04 01:44:16 +00:00
|
|
|
|
Path::Path(string const & path)
|
|
|
|
|
: popped_(false)
|
|
|
|
|
{
|
|
|
|
|
if (!path.empty()) {
|
|
|
|
|
pushedDir_ = getcwd();
|
|
|
|
|
if (pushedDir_.empty() || chdir(path))
|
|
|
|
|
/* FIXME: throw */;
|
|
|
|
|
} else {
|
|
|
|
|
popped_ = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Path::~Path()
|
|
|
|
|
{
|
|
|
|
|
if (!popped_) pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
int Path::pop()
|
|
|
|
|
{
|
|
|
|
|
if (popped_) {
|
|
|
|
|
// should throw an exception
|
|
|
|
|
// throw logical_error();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-09-25 10:03:41 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
if (chdir(pushedDir_)) {
|
2000-04-04 00:19:15 +00:00
|
|
|
|
// should throw an exception
|
|
|
|
|
// throw DirChangeError();
|
|
|
|
|
}
|
|
|
|
|
popped_ = true;
|
2002-09-25 10:03:41 +00:00
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
|
} // namespace lyx
|