Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/host/path_translate.c')
-rw-r--r--src/host/path_translate.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/host/path_translate.c b/src/host/path_translate.c
new file mode 100644
index 0000000..8996b37
--- /dev/null
+++ b/src/host/path_translate.c
@@ -0,0 +1,61 @@
+/**
+ * \file path_translate.c
+ * \brief Translates between path separators.
+ * \author Copyright (c) 2002-2013 Jason Perkins and the Premake project
+ */
+
+#include "premake.h"
+#include <string.h>
+
+
+void do_translate(char* value, const char sep)
+{
+ char* ch;
+ for (ch = value; *ch != '\0'; ++ch) {
+ if (*ch == '/' || *ch == '\\') {
+ *ch = sep;
+ }
+ }
+}
+
+
+static void translate(char* result, const char* value, const char sep)
+{
+ strcpy(result, value);
+ do_translate(result, sep);
+}
+
+
+int path_translate(lua_State* L)
+{
+ const char* sep;
+ char buffer[0x4000];
+
+ if (lua_gettop(L) == 1) {
+ sep = "\\";
+ }
+ else {
+ sep = luaL_checkstring(L, 2);
+ }
+
+ if (lua_istable(L, 1)) {
+ int i = 0;
+ lua_newtable(L);
+ lua_pushnil(L);
+ while (lua_next(L, 1)) {
+ const char* value = luaL_checkstring(L, 4);
+ translate(buffer, value, sep[0]);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, buffer);
+ lua_rawseti(L, -3, ++i);
+ }
+ return 1;
+ }
+ else {
+ const char* value = luaL_checkstring(L, 1);
+ translate(buffer, value, sep[0]);
+ lua_pushstring(L, buffer);
+ return 1;
+ }
+}