From c8a5b8049c7bdbceb9dfff9fe19847c513b7f882 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 21 Jan 2015 23:47:49 +0100 Subject: [PATCH] Implement Pl and Plj commands to list project files --- libr/core/cmd_project.c | 6 +++++- libr/core/project.c | 47 ++++++++++++++++++++++++++++++++++++++++- libr/include/r_core.h | 1 + 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/libr/core/cmd_project.c b/libr/core/cmd_project.c index f1757db79a..605c588050 100644 --- a/libr/core/cmd_project.c +++ b/libr/core/cmd_project.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2013 - pancake */ +/* radare - LGPL - Copyright 2009-2015 - pancake */ static int cmd_project(void *data, const char *input) { RCore *core = (RCore *)data; @@ -11,6 +11,9 @@ static int cmd_project(void *data, const char *input) { // if (r_file_is_regular (file)) r_core_project_open (core, file); break; + case 'l': + r_core_project_list (core, input[1]); + break; case 's': r_core_project_save (core, file); r_config_set (core->config, "file.project", file); @@ -25,6 +28,7 @@ static int cmd_project(void *data, const char *input) { "Po", " [file]", "open project", "Ps", " [file]", "save project", "Pi", " [file]", "show project information", + "Pl", "", "list all projects", "NOTE:", "", "See 'e file.project'", "NOTE:", "", "project files are stored in ~/.config/radare2/projects", NULL}; diff --git a/libr/core/project.c b/libr/core/project.c index 5379ebead4..6d86d6998e 100644 --- a/libr/core/project.c +++ b/libr/core/project.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2010-2014 - pancake */ +/* radare - LGPL - Copyright 2010-2015 - pancake */ #include #include @@ -24,6 +24,51 @@ static int r_core_project_init(RCore *core) { return ret; } +static int r_core_is_project(RCore *core, const char *name) { + int ret = 0; + if (name && *name && *name!='.') { + char *path = r_core_project_file (core, name); + path = r_str_concat (path, ".d"); + if (r_file_is_directory (path)) + ret = 1; + free (path); + } + return ret; +} + +R_API int r_core_project_list(RCore *core, int mode) { + RListIter *iter; + RList *list; + int isfirst = 1; + char *foo, *path = r_file_abspath (r_config_get (core->config, "dir.projects")); + if (!path) + return 0; + list = r_sys_dir (path); + switch (mode) { + case 'j': + r_cons_printf ("["); + r_list_foreach (list, iter, foo) { + // todo. escape string + if (r_core_is_project (core, foo)) { + r_cons_printf ("%s\"%s\"", + isfirst?"":",", foo); + isfirst = 0; + } + } + r_cons_printf ("]\n"); + break; + default: + r_list_foreach (list, iter, foo) { + if (r_core_is_project (core, foo)) + r_cons_printf ("%s\n", foo); + } + break; + } + r_list_free (list); + free (path); + return 0; +} + R_API int r_core_project_open(RCore *core, const char *prjfile) { int ret; char *prj; diff --git a/libr/include/r_core.h b/libr/include/r_core.h index 9ccf141419..11964a2a46 100644 --- a/libr/include/r_core.h +++ b/libr/include/r_core.h @@ -349,6 +349,7 @@ R_API int r_core_gdiff(RCore *core1, RCore *core2, int anal_all); R_API int r_core_gdiff_fcn(RCore *c, ut64 addr, ut64 addr2); R_API int r_core_project_open(RCore *core, const char *file); +R_API int r_core_project_list(RCore *core, int mode); R_API int r_core_project_save(RCore *core, const char *file); R_API char *r_core_project_info(RCore *core, const char *file); R_API char *r_core_sysenv_begin(RCore *core, const char *cmd);