From 34a0fdb9d69fe67e14afcabfb83f6e5642f94752 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 22:07:45 +0200 Subject: [PATCH] reorganize lua script dir defs --- client/cmdscript.c | 4 ++-- client/scripting.c | 26 +++++++++++++------------- client/scripting.h | 2 -- include/common.h | 4 ++++ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 8a748b8ab..889259922 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -33,7 +33,7 @@ static int CmdHelp(const char *Cmd); */ static int CmdScriptList(const char *Cmd) { (void)Cmd; // Cmd is not used so far - return searchAndList(LUA_SCRIPTS_DIRECTORY, ".lua"); + return searchAndList(LUA_SCRIPTS_SUBDIR, ".lua"); } /** @@ -66,7 +66,7 @@ static int CmdScriptRun(const char *Cmd) { int arg_len = 0; sscanf(Cmd, "%127s%n %255[^\n\r]%n", script_name, &name_len, arguments, &arg_len); - char *script_path = searchFile(LUA_SCRIPTS_DIRECTORY, ".lua", script_name); + char *script_path = searchFile(LUA_SCRIPTS_SUBDIR, ".lua", script_name); if (script_path == NULL) { PrintAndLogEx(FAILED, "Error - can't find script %s", script_name); return PM3_EFILE; diff --git a/client/scripting.c b/client/scripting.c index 664b0080f..dc3051207 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1136,48 +1136,48 @@ int set_pm3_libraries(lua_State *L) { const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { // from the ./luascripts/ directory - char scripts_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char scripts_path[strlen(exec_path) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, exec_path); - strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_SCRIPTS_SUBDIR); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the ./lualib/ directory - char libraries_path[strlen(exec_path) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char libraries_path[strlen(exec_path) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, exec_path); - strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_SUBDIR); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } char *user_path = getenv("HOME"); if (user_path != NULL) { // from the ~/.proxmark3/luascripts/ directory - char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, user_path); strcat(scripts_path, PM3_USER_DIRECTORY); - strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_SCRIPTS_SUBDIR); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the ~/.proxmark3/lualib/ directory - char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, user_path); strcat(libraries_path, PM3_USER_DIRECTORY); - strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_SUBDIR); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { + if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_SUBDIR) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { // from the /usr/local/share/proxmark3/luascripts/ directory - char scripts_path[strlen(PM3_SHARE_PATH) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char scripts_path[strlen(PM3_SHARE_PATH) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, PM3_SHARE_PATH); - strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_SCRIPTS_SUBDIR); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the /usr/local/share/proxmark3/lualib/ directory - char libraries_path[strlen(PM3_SHARE_PATH) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char libraries_path[strlen(PM3_SHARE_PATH) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, PM3_SHARE_PATH); - strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_SUBDIR); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } diff --git a/client/scripting.h b/client/scripting.h index 1a7b5a7e3..b23ce3a9a 100644 --- a/client/scripting.h +++ b/client/scripting.h @@ -14,8 +14,6 @@ //#include //#include -#define LUA_LIBRARIES_DIRECTORY "lualibs/" -#define LUA_SCRIPTS_DIRECTORY "luascripts/" #define LUA_LIBRARIES_WILDCARD "?.lua" /** diff --git a/include/common.h b/include/common.h index fc1d688f0..580170b31 100644 --- a/include/common.h +++ b/include/common.h @@ -26,6 +26,10 @@ // PM3_USER_DIRECTORY will be expanded as if with a "~" upfront, e.g. ~/.proxmark3/ #define PM3_USER_DIRECTORY "/.proxmark3/" +// PM3 subdirectories: +#define LUA_LIBRARIES_SUBDIR "lualibs/" +#define LUA_SCRIPTS_SUBDIR "luascripts/" + #define PACKED __attribute__((packed)) // debug