diff options
author | sabetts <sabetts> | 2001-12-21 13:58:01 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2001-12-21 13:58:01 +0000 |
commit | 5127b4ce3d24180599e09b959c16da1cf72290e6 (patch) | |
tree | 28205ce5cb91af3a3bf2d57379ae8d75891a7cc2 /src/actions.c | |
parent | bf97100618c4808f0e6d204c77290e4494e28e6e (diff) | |
download | ratpoison-5127b4ce3d24180599e09b959c16da1cf72290e6.zip |
* src/actions.h (cmd_alias): new prototype
* src/actions.c (user_commands): remove "license" from the
unimplemented section.
(user_commands): new command "alias"
(cmd_alias): new function
(command): handle aliases
(initialize_default_keybindings): initialize the alias list
(struct cmd_alias): new struct
(alias_list): new static global
(alias_list_size): likewise
(alias_list_last): likewise
Diffstat (limited to 'src/actions.c')
-rw-r--r-- | src/actions.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/actions.c b/src/actions.c index 3fc733f..6adb8cf 100644 --- a/src/actions.c +++ b/src/actions.c @@ -81,6 +81,7 @@ static user_command user_commands[] = {"restart", cmd_restart, arg_VOID}, {"startup_message", cmd_startup_message, arg_STRING}, {"link", cmd_link, arg_STRING}, + {"alias", cmd_alias, arg_STRING}, /*@end (tag required for genrpbindings) */ /* Commands to set default behavior. */ @@ -115,6 +116,16 @@ static user_command user_commands[] = #endif {0, 0, 0} }; +struct cmd_alias +{ + char *name; + char *alias; +}; + +static struct cmd_alias *alias_list; +static int alias_list_size; +static int alias_list_last; + rp_action* find_keybinding_by_action (char *action) { @@ -249,6 +260,11 @@ initialize_default_keybindings (void) key_actions = (rp_action*) xmalloc (sizeof (rp_action) * key_actions_table_size); key_actions_last = 0; + /* Initialive the alias list. */ + alias_list_size = 5; + alias_list_last = 0; + alias_list = xmalloc (sizeof (cmd_alias) * alias_list_size); + prefix_key.sym = KEY_PREFIX; prefix_key.state = MODIFIER_PREFIX; @@ -827,6 +843,7 @@ command (int interactive, char *data) char *cmd, *rest; char *input; user_command *uc; + int i; if (data == NULL) return NULL; @@ -863,6 +880,16 @@ command (int interactive, char *data) } } + /* Look for it in the aliases. */ + for (i=0; i<alias_list_last; i++) + { + if (!strcmp (cmd, alias_list[i].name)) + { + result = command (interactive, alias_list[i].alias); + goto done; + } + } + marked_message_printf (0, 0, MESSAGE_UNKNOWN_COMMAND, cmd); done: @@ -2212,3 +2239,36 @@ cmd_defbarpadding (int interactive, void *data) } return NULL; } + +char * +cmd_alias (int interactive, void *data) +{ + char *name, *alias; + + if (data == NULL) + { + message (" alias: At least one argument required "); + return NULL; + } + + if (alias_list_last >= alias_list_size) + { + alias_list_size *= 2; + alias_list = xrealloc (alias_list, sizeof (cmd_alias) * alias_list_size); + } + + name = strtok (data, " "); + alias = strtok (NULL, "\0"); + + if (name == NULL || alias == NULL) + { + message (" alias: Two arguments required "); + return NULL; + } + + alias_list[alias_list_last].name = xstrdup (name); + alias_list[alias_list_last].alias = xstrdup (alias); + alias_list_last++; + + return NULL; +} |