summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsabetts <sabetts>2002-03-24 06:05:03 +0000
committersabetts <sabetts>2002-03-24 06:05:03 +0000
commit0baad694c569894bc6ecaf8c96a2d478a6b59f40 (patch)
treee4b5d78b1cdc5aa62a3a780cae4cb8652b0f1811
parentec4753341dc1712c02989f477902a763af7daec0 (diff)
downloadratpoison-0baad694c569894bc6ecaf8c96a2d478a6b59f40.zip
* 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
-rw-r--r--src/actions.c69
-rw-r--r--src/actions.h1
2 files changed, 59 insertions, 11 deletions
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; i<alias_list_last; i++)
{
if (!strcmp (cmd, alias_list[i].name))
@@ -910,6 +901,16 @@ command (int interactive, char *data)
}
}
+ /* If it wasn't an alias, maybe its a command. */
+ for (uc = user_commands; uc->name; uc++)
+ {
+ if (!strcmp (cmd, uc->name))
+ {
+ result = uc->func (interactive, rest);
+ goto done;
+ }
+ }
+
marked_message_printf (0, 0, MESSAGE_UNKNOWN_COMMAND, cmd);
done:
@@ -2434,6 +2435,52 @@ cmd_alias (int interactive, void *data)
}
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)
{
int new_screen;
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);