From 0baad694c569894bc6ecaf8c96a2d478a6b59f40 Mon Sep 17 00:00:00 2001 From: sabetts Date: Sun, 24 Mar 2002 06:05:03 +0000 Subject: * src/actions.c (command): look for the command in the aliases before looking in the command list. * src/actions.h (cmd_unalias): new prototype * src/actions.c (user_commands): new command unalias (cmd_unalias): new function --- src/actions.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++---------- src/actions.h | 1 + 2 files changed, 59 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/actions.c b/src/actions.c index ec44cda..3f23ddf 100644 --- a/src/actions.c +++ b/src/actions.c @@ -82,6 +82,7 @@ static user_command user_commands[] = {"startup_message", cmd_startup_message, arg_STRING}, {"link", cmd_link, arg_STRING}, {"alias", cmd_alias, arg_STRING}, + {"unalias", cmd_unalias, arg_STRING}, {"prevscreen", cmd_prevscreen, arg_VOID}, {"nextscreen", cmd_nextscreen, arg_VOID}, /*@end (tag required for genrpbindings) */ @@ -875,17 +876,7 @@ command (int interactive, char *data) PRINT_DEBUG ("cmd==%s rest==%s\n", cmd, (char*)rest); - /* find the command */ - for (uc = user_commands; uc->name; uc++) - { - if (!strcmp (cmd, uc->name)) - { - result = uc->func (interactive, rest); - goto done; - } - } - - /* Look for it in the aliases. */ + /* Look for it in the aliases, first. */ for (i=0; iname; uc++) + { + if (!strcmp (cmd, uc->name)) + { + result = uc->func (interactive, rest); + goto done; + } + } + marked_message_printf (0, 0, MESSAGE_UNKNOWN_COMMAND, cmd); done: @@ -2433,6 +2434,52 @@ cmd_alias (int interactive, void *data) return NULL; } +char * +cmd_unalias (int interactive, void *data) +{ + char *name; + int index; + + if (data == NULL) + { + message (" unalias: One argument required "); + return NULL; + } + + /* Parse out the arguments. */ + name = (char *)data; + + /* Are we updating an existing alias, or creating a new one? */ + index = find_alias_index (name); + if (index >= 0) + { + char *tmp; + + alias_list_last--; + + /* Free the alias and put the last alias in the the space to + keep alias_list from becoming sparse. This code must jump + through some hoops to correctly handle the case when + alias_list_last == index. */ + tmp = alias_list[index].alias; + alias_list[index].alias = xstrdup (alias_list[alias_list_last].alias); + free (tmp); + free (alias_list[alias_list_last].alias); + + /* Do the same for the name element. */ + tmp = alias_list[index].name; + alias_list[index].name = xstrdup (alias_list[alias_list_last].name); + free (tmp); + free (alias_list[alias_list_last].name); + } + else + { + message (" unalias: alias not found "); + } + + return NULL; +} + char * cmd_nextscreen (int interactive, void *data) { diff --git a/src/actions.h b/src/actions.h index cbedd60..0503484 100644 --- a/src/actions.h +++ b/src/actions.h @@ -110,6 +110,7 @@ char * cmd_alias (int interactive, void *data); char *cmd_defbarborder (int interactive, void *data); char *cmd_prevscreen (int interactive, void *data); char *cmd_nextscreen (int interactive, void *data); +char *cmd_unalias (int interactive, void *data); void initialize_default_keybindings (void); rp_action* find_keybinding (KeySym keysym, int state); -- cgit v1.2.3