allow subdirectories in Lua-specified paths separated by ":"

This commit is contained in:
Josh Holtrop 2010-12-19 00:11:34 -05:00
parent 66b0bd3da5
commit 2edea049bd
3 changed files with 41 additions and 1 deletions

View File

@ -65,6 +65,23 @@ static void normalize(dVector3 vec)
}
}
static vector<string> split(const string & str, char delim)
{
vector<string> ret;
ssize_t begin = 0, pos;
int len = str.length();
while ((pos = str.find(delim)) != string::npos && begin < len)
{
ret.push_back(string(str, begin, pos - begin));
begin = pos + 1;
}
if (begin < len)
{
ret.push_back(string(str, begin));
}
return ret;
}
#define DEBUG_GL_ERROR
#ifdef DEBUG_GL_ERROR
#define checkGLError() checkGLErrorLine(__FUNCTION__, __LINE__)
@ -222,6 +239,28 @@ void Engine::checkForAllHandlerFunctions()
checkForFunction("mouse_motion_event", mouse_motion);
}
bool Engine::validatePath(string & path)
{
if (path.find_first_not_of(FILENAME_SAFE_CHARS) != string::npos)
return false;
if (path[0] == ':')
return false;
vector<string> parts = split(path, ':');
path = "";
bool multiple = false;
for (int i = 0, sz = parts.size(); i < sz; i++)
{
if (parts[i].find_first_not_of(".") != string::npos)
{
if (multiple)
path += "/";
path += parts[i];
multiple = true;
}
}
return true;
}
void Engine::reportErrors(int status)
{
if (status != 0)

View File

@ -274,6 +274,7 @@ class Engine
m_av.setCursorVisible(
m_engine_cursor_visible || m_script_cursor_visible);
}
bool validatePath(std::string & path);
AV & m_av;
bool m_engine_cursor_visible;

View File

@ -2,6 +2,6 @@
#ifndef ANAGLYM_H
#define ANAGLYM_H
#define FILENAME_SAFE_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-."
#define FILENAME_SAFE_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.:"
#endif