Commit 72e67080 by maarten

herverkaveling

git-svn-id: svn+ssh://gitlab/srv/svn-repos/pdb-redo/trunk@428 a1961a4f-ab94-4bcc-80e8-33b5a54de466
parent aaf25de2
......@@ -59,6 +59,11 @@ std::vector<std::string> wordWrap(const std::string& text, unsigned int width);
uint32_t get_terminal_width();
// --------------------------------------------------------------------
// Path of the current executable
std::string get_executable_path();
// --------------------------------------------------------------------
// some manipulators to write coloured text to terminals
enum StringColour {
......
......@@ -391,6 +391,21 @@ uint32_t get_terminal_width()
{
return TERM_WIDTH;
}
// I don't have a windows machine to test the following code, please accept my apologies in case it fails...
string GetExecutablePath()
{
WCHAR buffer[4096];
DWORD n = ::GetModuleFileNameW(nullptr, buffer, sizeof(buffer) / sizeof(WCHAR));
if (n == 0)
throw runtime_error("could not get exe path");
wstring ws(buffer);
return string(ws.begin(), ws.end());
}
#else
uint32_t get_terminal_width()
{
......@@ -398,6 +413,15 @@ uint32_t get_terminal_width()
ioctl(0, TIOCGWINSZ, &w);
return w.ws_col;
}
string get_executable_path()
{
char path[PATH_MAX] = "";
if (readlink("/proc/self/exe", path, sizeof(path)) == -1)
throw runtime_error("could not get exe path "s + strerror(errno));
return { path };
}
#endif
// --------------------------------------------------------------------
......
......@@ -13,7 +13,11 @@
#include "cif++/Cif++.h"
#include "cif++/Point.h"
#include "cif++/Compound.h"
#include "cif++/CifUtils.h"
#if defined(USE_RSRC)
#include "cif++/mrsrc.h"
#endif
using namespace std;
namespace ba = boost::algorithm;
......@@ -80,6 +84,7 @@ class IsomerDB
IsomerDB::IsomerDB()
{
#if defined(USE_RSRC)
mrsrc::rsrc isomers("isomers.txt");
// mrsrc::rsrc isomers("isomers-with-sugar.xml");
if (not isomers)
......@@ -91,6 +96,17 @@ IsomerDB::IsomerDB()
} buffer(const_cast<char*>(isomers.data()), isomers.size());
istream is(&buffer);
#else
cerr << "resource support was not compiled in, falling back to a local file" << endl;
fs::path isomersFile = "isomers.txt";
if (not fs::exists(isomersFile))
isomersFile = fs::path(cif::get_executable_path()).parent_path() / "isomers.txt";
fs::ifstream is(isomersFile);
if (not is.is_open())
throw runtime_error("Could not open the file isomers.txt");
#endif
string line;
while (getline(is, line))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment