diff options
author | sabetts <sabetts> | 2003-08-10 23:22:59 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2003-08-10 23:22:59 +0000 |
commit | 458692956c3f885f74d73116ac484fac9d666c57 (patch) | |
tree | fd2706aad7fab2e5b0d992e6e150b4d5e9dd5dd6 /src/actions.c | |
parent | 87fc9408259dbcfb65df76a5a061958c52ee6705 (diff) | |
download | ratpoison-458692956c3f885f74d73116ac484fac9d666c57.zip |
* src/actions.h (cmd_listhook): new prototype
* src/actions.c (use_commands): new command listhook
(cmd_remhook): fix error messages
(hook_completions): new function
(cmd_listhook): likewise
Diffstat (limited to 'src/actions.c')
-rw-r--r-- | src/actions.c | 85 |
1 files changed, 83 insertions, 2 deletions
diff --git a/src/actions.c b/src/actions.c index 3812218..9b70e47 100644 --- a/src/actions.c +++ b/src/actions.c @@ -108,6 +108,7 @@ static user_command user_commands[] = {"gmerge", cmd_gmerge, arg_VOID}, {"addhook", cmd_addhook, arg_STRING}, {"remhook", cmd_remhook, arg_STRING}, + {"listhook", cmd_listhook, arg_STRING}, /* Commands to set default behavior. */ {"defbargravity", cmd_defbargravity, arg_STRING}, @@ -3718,7 +3719,7 @@ cmd_remhook (int interactive, char *data) hook = hook_lookup (token); if (hook == NULL) { - marked_message_printf (0, 0, " addhook: unknown hook \"%s\"", token); + marked_message_printf (0, 0, " remhook: unknown hook \"%s\"", token); free (dup); return NULL; } @@ -3727,7 +3728,7 @@ cmd_remhook (int interactive, char *data) if (token == NULL) { - message (" addhook: two arguments required "); + message (" remhook: two arguments required "); free (dup); return NULL; } @@ -3740,3 +3741,83 @@ cmd_remhook (int interactive, char *data) free (dup); return NULL; } + +struct list_head * +hook_completions (char* str) +{ + struct list_head *list; + struct rp_hook_db_entry *entry; + + /* Initialize our list. */ + list = xmalloc (sizeof (struct list_head)); + INIT_LIST_HEAD (list); + + for (entry = rp_hook_db; entry->name; entry++) + { + struct sbuf *hookname; + + hookname = sbuf_new(0); + sbuf_copy (hookname, entry->name); + list_add_tail (&hookname->node, list); + } + + return list; +} + +char * +cmd_listhook (int interactive, char *data) +{ + struct sbuf *buffer; + struct list_head *hook; + struct sbuf *cur; + char *str; + + if (data == NULL) + str = get_input (" Hook: ", hook_completions); + else + str = xstrdup (data); + + /* User aborted. */ + if (str == NULL) + return NULL; + + hook = hook_lookup (str); + if (hook == NULL) + { + marked_message_printf (0, 0, " listhook: unknown hook \"%s\" ", str); + return NULL; + } + + buffer = sbuf_new(0); + + if (list_empty(hook)) + { + sbuf_printf(buffer, " Nothing defined for %s ", str); + } + else + { + list_for_each_entry (cur, hook, node) + { + sbuf_printf_concat(buffer, "%s", sbuf_get (cur)); + if (cur->node.next != hook) + sbuf_printf_concat(buffer, "\n"); + } + } + + /* Display it or return it. */ + if (interactive) + { + marked_message (sbuf_get (buffer), 0, 0); + sbuf_free (buffer); + return NULL; + } + else + { + char* tmp = sbuf_get(buffer); + free(buffer); + return tmp; + } + + +} + |