From 2edea049bdd8ea29ee3e205490b26de692fbb5d9 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 19 Dec 2010 00:11:34 -0500 Subject: [PATCH] allow subdirectories in Lua-specified paths separated by ":" --- Engine.cc | 39 +++++++++++++++++++++++++++++++++++++++ Engine.h | 1 + anaglym.h | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Engine.cc b/Engine.cc index e5dcf86..0844443 100644 --- a/Engine.cc +++ b/Engine.cc @@ -65,6 +65,23 @@ static void normalize(dVector3 vec) } } +static vector split(const string & str, char delim) +{ + vector 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 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) diff --git a/Engine.h b/Engine.h index fef5ccb..973f1d4 100644 --- a/Engine.h +++ b/Engine.h @@ -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; diff --git a/anaglym.h b/anaglym.h index b89d8df..7611439 100644 --- a/anaglym.h +++ b/anaglym.h @@ -2,6 +2,6 @@ #ifndef ANAGLYM_H #define ANAGLYM_H -#define FILENAME_SAFE_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-." +#define FILENAME_SAFE_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.:" #endif