From 256c0e0bd91af8aa47af8d2e336bac6b725ca82e Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 30 Oct 2012 03:22:30 +0100 Subject: [PATCH] dded r_cmd_alias_del to remove aliases and honor DEBUG=1 --- libr/cmd/cmd.c | 16 ++++++++++++++++ libr/core/cmd.c | 24 +++++++++++++++++------- libr/include/r_cmd.h | 1 + 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/libr/cmd/cmd.c b/libr/cmd/cmd.c index e002645e9d..75bec3b249 100644 --- a/libr/cmd/cmd.c +++ b/libr/cmd/cmd.c @@ -50,6 +50,22 @@ R_API void r_cmd_alias_free (RCmd *cmd) { cmd->aliases.values = NULL; } +R_API int r_cmd_alias_del (RCmd *cmd, const char *k) { + int i; // find + for (i=0; ialiases.count; i++) { + if (!strcmp (k, cmd->aliases.keys[i])) { + free (cmd->aliases.values[i]); + cmd->aliases.count--; + if (cmd->aliases.count>0) { + cmd->aliases.values[i] = cmd->aliases.values[0]; + cmd->aliases.values += sizeof (void*); + } + return 1; + } + } + return 0; +} + R_API int r_cmd_alias_set (RCmd *cmd, const char *k, const char *v) { int i; // find for (i=0; ialiases.count; i++) { diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 098c3fbf5c..712c0f8e6a 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -85,13 +85,15 @@ static int cmd_alias(void *data, const char *input) { p = strchr (buf, '='); q = strchr (buf, ' '); if (p) { - *p = 0; - if (!q || (q && q>p)) - r_cmd_alias_set (core->rcmd, buf, p+1); + *p++ = 0; + if (!q || (q && q>p)) { + if (*p) r_cmd_alias_set (core->rcmd, buf, p); + else r_cmd_alias_del (core->rcmd, buf); + } } else - if (!*buf) { + if (!buf[1]) { int i, count; - const char **keys = r_cmd_alias_keys (core->rcmd, &count); + char **keys = r_cmd_alias_keys (core->rcmd, &count); for (i=0; ioobi); core->oobi = (ut8*)r_file_slurp (str, &core->oobi_len); @@ -727,6 +734,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd) { return r_core_cmd_buffer (core, (const char *)core->oobi); } } +next: // TODO must honor " and ` /* pipe console to file */ @@ -740,6 +748,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd) { r_cons_set_interactive (R_FALSE); *ptr = '\0'; str = r_str_trim_head_tail (ptr+1+(ptr[1]=='>')); + if (!*str) goto next2; if (!strcmp (str, "-")) { use_editor = R_TRUE; str = r_file_temp ("dumpedit"); @@ -761,6 +770,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd) { } return ret; } +next2: /* sub commands */ ptr = strchr (cmd, '`'); @@ -922,7 +932,7 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { case '?': r_cons_printf ( "Foreach '@@' iterator command:\n" - " This command is used to repeat a command over a list of offsets.\n" + " Repeat a command over a list of offsets.\n" " x @@ sym.* Run 'x' over all flags matching 'sym.' in current flagspace\n" " x @@.file \"\" over the offsets specified in the file (one offset per line)\n" " x @@=off1 off2 .. Manual list of offsets\n" diff --git a/libr/include/r_cmd.h b/libr/include/r_cmd.h index cce1774561..df84acb499 100644 --- a/libr/include/r_cmd.h +++ b/libr/include/r_cmd.h @@ -102,6 +102,7 @@ R_API void r_cmd_macro_list(RCmdMacro *mac); R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name); R_API int r_cmd_macro_break(RCmdMacro *mac, const char *value); +R_API int r_cmd_alias_del (RCmd *cmd, const char *k); R_API char **r_cmd_alias_keys(RCmd *cmd, int *sz); R_API int r_cmd_alias_set (RCmd *cmd, const char *k, const char *v); R_API char *r_cmd_alias_get (RCmd *cmd, const char *k);