X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/5def0b3c74fc3a20e7651c00436b49dde352e304..fb26bb5436efe7d07919c6903cf4b0784e134a18:/client/cmdscript.c

diff --git a/client/cmdscript.c b/client/cmdscript.c
index e9ec5871..760d74e1 100644
--- a/client/cmdscript.c
+++ b/client/cmdscript.c
@@ -30,7 +30,6 @@
 #include <lualib.h>
 #include <lauxlib.h>
 
-
 static int CmdHelp(const char *Cmd);
 static int CmdList(const char *Cmd);
 static int CmdRun(const char *Cmd);
@@ -64,7 +63,7 @@ int str_ends_with(const char * str, const char * suffix) {
  */
 int CmdHelp(const char * Cmd)
 {
-    PrintAndLog("This is a feature to run Lua-scripts. You can place lua-scripts within the ´client/scripts/´ folder.");
+    PrintAndLog("This is a feature to run Lua-scripts. You can place lua-scripts within the scripts/-folder. ");
     return 0;
 }
 
@@ -72,26 +71,32 @@ int CmdHelp(const char * Cmd)
 * Generate list of available commands, what it does is 
 * generate a file listing of the script-directory for files
 * ending with .lua
+*
 */
 int CmdList(const char *Cmd)
 {
     DIR *dp;
     struct dirent *ep;
-    dp = opendir ("./scripts/");
+	char script_directory_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + 1];
+	strcpy(script_directory_path, get_my_executable_directory());
+	strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY);
+    dp = opendir(script_directory_path);
 
     if (dp != NULL)
     {
-        while ((ep = readdir (dp)) != NULL)
-        {
-            if(str_ends_with(ep->d_name, ".lua"))
-                PrintAndLog("%-21s %s", ep->d_name, "A script file");
-        }
-        (void) closedir (dp);
+	while ((ep = readdir (dp)) != NULL)
+	{
+		if(str_ends_with(ep->d_name, ".lua"))
+			PrintAndLog("%-21s %s", ep->d_name, "A script file");
+	}
+	(void) closedir (dp);
     }
     else
         PrintAndLog ("Couldn't open the scripts-directory");
     return 0;
 }
+
+
 /**
  * Finds a matching script-file
  * @brief CmdScript
@@ -149,14 +154,19 @@ int CmdRun(const char *Cmd)
         suffix = ".lua";
     }
 
-    char buf[256];
-    snprintf(buf, sizeof buf, "./scripts/%s%s", script_name, suffix);
+	char script_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1];
+	strcpy(script_path, get_my_executable_directory());
+	strcat(script_path, LUA_SCRIPTS_DIRECTORY);
+	strcat(script_path, script_name);
+	strcat(script_path, suffix);
+
+    printf("--- Executing: %s%s, args '%s'\n", script_name, suffix, arguments);
+
 
-    printf("--- Executing: %s, args'%s'\n", buf, arguments);
 
     // run the Lua script
 
-    int error = luaL_loadfile(lua_state, buf);
+    int error = luaL_loadfile(lua_state, script_path);
     if(!error)
     {
         lua_pushstring(lua_state, arguments);