summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/cmd-set-hook.c5
-rw-r--r--usr.bin/tmux/hooks.c30
-rw-r--r--usr.bin/tmux/options.c44
-rw-r--r--usr.bin/tmux/tmux.h6
4 files changed, 47 insertions, 38 deletions
diff --git a/usr.bin/tmux/cmd-set-hook.c b/usr.bin/tmux/cmd-set-hook.c
index fb021dd92d8..d69d50944e6 100644
--- a/usr.bin/tmux/cmd-set-hook.c
+++ b/usr.bin/tmux/cmd-set-hook.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-hook.c,v 1.1 2015/12/08 01:10:31 nicm Exp $ */
+/* $OpenBSD: cmd-set-hook.c,v 1.2 2015/12/11 15:46:57 nicm Exp $ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
@@ -93,8 +93,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
name);
return (CMD_RETURN_ERROR);
}
- if ((hook = hooks_find(hooks, name)) != NULL)
- hooks_remove(hooks, hook);
+ hooks_remove(hooks, name);
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/hooks.c b/usr.bin/tmux/hooks.c
index 25391b999bb..8bc72cb1012 100644
--- a/usr.bin/tmux/hooks.c
+++ b/usr.bin/tmux/hooks.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hooks.c,v 1.1 2015/12/08 01:10:31 nicm Exp $ */
+/* $OpenBSD: hooks.c,v 1.2 2015/12/11 15:46:57 nicm Exp $ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
@@ -32,7 +32,8 @@ static int hooks_cmp(struct hook *, struct hook *);
RB_PROTOTYPE(hooks_tree, hook, entry, hooks_cmp);
RB_GENERATE(hooks_tree, hook, entry, hooks_cmp);
-struct hook *hooks_find1(struct hooks *, const char *);
+static struct hook *hooks_find1(struct hooks *, const char *);
+static void hooks_free1(struct hooks *, struct hook *);
static int
hooks_cmp(struct hook *hook1, struct hook *hook2)
@@ -51,13 +52,22 @@ hooks_create(struct hooks *parent)
return (hooks);
}
+static void
+hooks_free1(struct hooks *hooks, struct hook *hook)
+{
+ RB_REMOVE(hooks_tree, &hooks->tree, hook);
+ cmd_list_free(hook->cmdlist);
+ free((char *)hook->name);
+ free(hook);
+}
+
void
hooks_free(struct hooks *hooks)
{
struct hook *hook, *hook1;
RB_FOREACH_SAFE(hook, hooks_tree, &hooks->tree, hook1)
- hooks_remove(hooks, hook);
+ hooks_free1(hooks, hook);
free(hooks);
}
@@ -79,7 +89,7 @@ hooks_add(struct hooks *hooks, const char *name, struct cmd_list *cmdlist)
struct hook *hook;
if ((hook = hooks_find1(hooks, name)) != NULL)
- hooks_remove(hooks, hook);
+ hooks_free1(hooks, hook);
hook = xcalloc(1, sizeof *hook);
hook->name = xstrdup(name);
@@ -89,15 +99,15 @@ hooks_add(struct hooks *hooks, const char *name, struct cmd_list *cmdlist)
}
void
-hooks_remove(struct hooks *hooks, struct hook *hook)
+hooks_remove(struct hooks *hooks, const char *name)
{
- RB_REMOVE(hooks_tree, &hooks->tree, hook);
- cmd_list_free(hook->cmdlist);
- free((char *) hook->name);
- free(hook);
+ struct hook *hook;
+
+ if ((hook = hooks_find1(hooks, name)) != NULL)
+ hooks_free1(hooks, hook);
}
-struct hook *
+static struct hook *
hooks_find1(struct hooks *hooks, const char *name)
{
struct hook hook;
diff --git a/usr.bin/tmux/options.c b/usr.bin/tmux/options.c
index cea57e5d054..0529a7de3d1 100644
--- a/usr.bin/tmux/options.c
+++ b/usr.bin/tmux/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.16 2015/12/08 08:14:04 nicm Exp $ */
+/* $OpenBSD: options.c,v 1.17 2015/12/11 15:46:57 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,11 +34,13 @@ struct options {
struct options *parent;
};
-int options_cmp(struct options_entry *, struct options_entry *);
+static int options_cmp(struct options_entry *, struct options_entry *);
RB_PROTOTYPE(options_tree, options_entry, entry, options_cmp);
RB_GENERATE(options_tree, options_entry, entry, options_cmp);
-int
+static void options_free1(struct options *, struct options_entry *);
+
+static int
options_cmp(struct options_entry *o1, struct options_entry *o2)
{
return (strcmp(o1->name, o2->name));
@@ -55,19 +57,23 @@ options_create(struct options *parent)
return (oo);
}
+static void
+options_free1(struct options *oo, struct options_entry *o)
+{
+ RB_REMOVE(options_tree, &oo->tree, o);
+ free((char *)o->name);
+ if (o->type == OPTIONS_STRING)
+ free(o->str);
+ free(o);
+}
+
void
options_free(struct options *oo)
{
- struct options_entry *o;
+ struct options_entry *o, *o1;
- while (!RB_EMPTY(&oo->tree)) {
- o = RB_ROOT(&oo->tree);
- RB_REMOVE(options_tree, &oo->tree, o);
- free(o->name);
- if (o->type == OPTIONS_STRING)
- free(o->str);
- free(o);
- }
+ RB_FOREACH_SAFE (o, options_tree, &oo->tree, o1)
+ options_free1(oo, o);
free(oo);
}
@@ -88,7 +94,7 @@ options_find1(struct options *oo, const char *name)
{
struct options_entry p;
- p.name = (char *) name;
+ p.name = (char *)name;
return (RB_FIND(options_tree, &oo->tree, &p));
}
@@ -97,7 +103,7 @@ options_find(struct options *oo, const char *name)
{
struct options_entry *o, p;
- p.name = (char *) name;
+ p.name = (char *)name;
o = RB_FIND(options_tree, &oo->tree, &p);
while (o == NULL) {
oo = oo->parent;
@@ -113,14 +119,8 @@ options_remove(struct options *oo, const char *name)
{
struct options_entry *o;
- if ((o = options_find1(oo, name)) == NULL)
- return;
-
- RB_REMOVE(options_tree, &oo->tree, o);
- free(o->name);
- if (o->type == OPTIONS_STRING)
- free(o->str);
- free(o);
+ if ((o = options_find1(oo, name)) != NULL)
+ options_free1(oo, o);
}
struct options_entry *
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index c60557d8d23..21dd0cb87c4 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.598 2015/12/11 12:27:36 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.599 2015/12/11 15:46:57 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -703,7 +703,7 @@ struct hook {
/* Option data structures. */
struct options_entry {
- char *name;
+ const char *name;
enum {
OPTIONS_STRING,
@@ -1514,7 +1514,7 @@ struct hook *hooks_first(struct hooks *);
struct hook *hooks_next(struct hook *);
void hooks_add(struct hooks *, const char *, struct cmd_list *);
void hooks_copy(struct hooks *, struct hooks *);
-void hooks_remove(struct hooks *, struct hook *);
+void hooks_remove(struct hooks *, const char *);
struct hook *hooks_find(struct hooks *, const char *);
void hooks_run(struct hooks *, const char *, struct client *);