summaryrefslogtreecommitdiff
path: root/library/MiscUtils.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-05-04 19:47:18 +0400
committerAlexander Gavrilov2012-05-04 19:47:18 +0400
commitd4d6349f48d01b31f59f94238d6656e3b5d08508 (patch)
tree43e47bbb5bab970825ff217ddbc16e21a3711033 /library/MiscUtils.cpp
parent5afe2ca0020404d46ad3de840030a7b9e186b059 (diff)
downloaddfhack-d4d6349f48d01b31f59f94238d6656e3b5d08508.tar.gz
dfhack-d4d6349f48d01b31f59f94238d6656e3b5d08508.tar.bz2
dfhack-d4d6349f48d01b31f59f94238d6656e3b5d08508.tar.xz
Expose builtin commands to dfhack-run, and add lua script support.
Move builtin command implementation to Core methods, and fall back to hack/scripts/*.lua for otherwise unrecognized commands.
Diffstat (limited to 'library/MiscUtils.cpp')
-rw-r--r--library/MiscUtils.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp
index c0674686..65fa21e1 100644
--- a/library/MiscUtils.cpp
+++ b/library/MiscUtils.cpp
@@ -30,9 +30,12 @@ distribution.
#ifndef LINUX_BUILD
#include <Windows.h>
+ #include "wdirent.h"
#else
#include <sys/time.h>
#include <ctime>
+ #include <dirent.h>
+ #include <errno.h>
#endif
#include <ctype.h>
@@ -125,6 +128,34 @@ std::string toLower(const std::string &str)
return rv;
}
+int getdir(std::string dir, std::vector<std::string> &files)
+{
+ DIR *dp;
+ struct dirent *dirp;
+ if((dp = opendir(dir.c_str())) == NULL)
+ {
+ return errno;
+ }
+ while ((dirp = readdir(dp)) != NULL) {
+ files.push_back(std::string(dirp->d_name));
+ }
+ closedir(dp);
+ return 0;
+}
+
+bool hasEnding (std::string const &fullString, std::string const &ending)
+{
+ if (fullString.length() > ending.length())
+ {
+ return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
+ }
+ else
+ {
+ return false;
+ }
+}
+
+
df::general_ref *DFHack::findRef(std::vector<df::general_ref*> &vec, df::general_ref_type type)
{
for (int i = vec.size()-1; i >= 0; i--)