From 40b6956a22e4cf957259efe88c7a39f919aea3c6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 19:53:23 +0200 Subject: [PATCH] script list: print dir tree --- client/cmdscript.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 9fdc3c0af..90cd65532 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -56,18 +56,21 @@ static bool endsWith(const char *base, const char *str) { return (blen >= slen) && (0 == strcmp(base + blen - slen, str)); } -static int scriptlist(const char *path) { +static int scriptlist(const char *path, bool last) { struct dirent **namelist; int n; n = scandir(path, &namelist, NULL, alphasort); if (n == -1) { + PrintAndLogEx(NORMAL, "%s── %s => NOT FOUND", last ? "└" : "├", path); return PM3_EFILE; } + PrintAndLogEx(NORMAL, "%s── %s", last ? "└" : "├", path); for (uint16_t i = 0; i < n; i++) { - if (str_ends_with(namelist[i]->d_name, ".lua")) - PrintAndLogEx(NORMAL, "%-21s", namelist[i]->d_name); + if (str_ends_with(namelist[i]->d_name, ".lua")) { + PrintAndLogEx(NORMAL, "%s   %s── %-21s", last ? " ":"│", i == n-1 ? "└" : "├", namelist[i]->d_name); + } free(namelist[i]); } free(namelist); @@ -86,7 +89,7 @@ static int CmdScriptList(const char *Cmd) { 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); - scriptlist(script_directory_path); + scriptlist(script_directory_path, false); } char *userpath = getenv("HOME"); if (userpath != NULL) { @@ -94,13 +97,13 @@ static int CmdScriptList(const char *Cmd) { strcpy(script_directory_path, userpath); strcat(script_directory_path, PM3_USER_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - scriptlist(script_directory_path); + scriptlist(script_directory_path, false); } { char script_directory_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; strcpy(script_directory_path, PM3_SYSTEM_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - scriptlist(script_directory_path); + scriptlist(script_directory_path, true); } return 0; }