A tiling window manager
1/*
2 * Copyright (C) 2000, 2001, 2002, 2003, 2004 Shawn Betts <sabetts@vcn.bc.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place, Suite 330, Boston, MA 02111-1307 USA.
17 */
18
19/*
20 * A hook is simply a list of strings that get passed to command() in sequence.
21 */
22
23#include "sdorfehs.h"
24
25#include <string.h>
26
27void
28hook_add(struct list_head *hook, struct sbuf *s)
29{
30 struct sbuf *cur;
31
32 /* Check if it's in the list already. */
33 list_for_each_entry(cur, hook, node) {
34 if (!strcmp(sbuf_get(cur), sbuf_get(s))) {
35 sbuf_free(s);
36 return;
37 }
38 }
39
40 /* It's not in the list, so add it. */
41 list_add_tail(&s->node, hook);
42}
43
44void
45hook_remove(struct list_head *hook, struct sbuf *s)
46{
47 struct list_head *tmp, *iter;
48 struct sbuf *cur;
49
50 /* If it's in the list, delete it. */
51 list_for_each_safe_entry(cur, iter, tmp, hook, node) {
52 if (!strcmp(sbuf_get(cur), sbuf_get(s))) {
53 list_del(&cur->node);
54 sbuf_free(cur);
55 }
56 }
57}
58
59void
60hook_run(struct list_head *hook)
61{
62 struct sbuf *cur;
63 cmdret *result;
64
65 list_for_each_entry(cur, hook, node) {
66 result = command(1, sbuf_get(cur));
67 if (result) {
68 if (result->output)
69 message(result->output);
70 cmdret_free(result);
71 }
72 }
73}
74
75struct list_head *
76hook_lookup(char *s)
77{
78 struct rp_hook_db_entry *entry;
79
80 for (entry = rp_hook_db; entry->name; entry++) {
81 if (!strcmp(s, entry->name)) {
82 return entry->hook;
83 }
84 }
85
86 return NULL;
87}