summaryrefslogtreecommitdiffstats
path: root/options.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-09-22 14:22:21 +0000
committerTiago Cunha <tcunha@gmx.com>2009-09-22 14:22:21 +0000
commitdf7b68480cf37f4039a5fd1809fd7c8dbf127277 (patch)
tree4e764c63c18a86cd683cabe5bdf1817d970dfb03 /options.c
parent31ccf2f8134538bd3f4b2bad0d092536b3adb519 (diff)
Sync OpenBSD patchset 343:
Permit multiple prefix keys to be defined, separated by commas, for example: set -g prefix ^a,^b Any key in the list acts as the prefix. The send-prefix command always sends the first key in the list.
Diffstat (limited to 'options.c')
-rw-r--r--options.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/options.c b/options.c
index 78a11ae8..9e870370 100644
--- a/options.c
+++ b/options.c
@@ -1,4 +1,4 @@
-/* $Id: options.c,v 1.8 2009-09-22 13:59:46 tcunha Exp $ */
+/* $Id: options.c,v 1.9 2009-09-22 14:22:20 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -54,6 +54,8 @@ options_free(struct options *oo)
xfree(o->name);
if (o->type == OPTIONS_STRING)
xfree(o->str);
+ else if (o->type == OPTIONS_DATA)
+ o->freefn(o->data);
xfree(o);
}
}
@@ -95,6 +97,8 @@ options_remove(struct options *oo, const char *name)
xfree(o->name);
if (o->type == OPTIONS_STRING)
xfree(o->str);
+ else if (o->type == OPTIONS_DATA)
+ o->freefn(o->data);
xfree(o);
}
@@ -110,6 +114,8 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
SPLAY_INSERT(options_tree, &oo->tree, o);
} else if (o->type == OPTIONS_STRING)
xfree(o->str);
+ else if (o->type == OPTIONS_DATA)
+ o->freefn(o->data);
va_start(ap, fmt);
o->type = OPTIONS_STRING;
@@ -141,6 +147,8 @@ options_set_number(struct options *oo, const char *name, long long value)
SPLAY_INSERT(options_tree, &oo->tree, o);
} else if (o->type == OPTIONS_STRING)
xfree(o->str);
+ else if (o->type == OPTIONS_DATA)
+ o->freefn(o->data);
o->type = OPTIONS_NUMBER;
o->num = value;
@@ -158,3 +166,36 @@ options_get_number(struct options *oo, const char *name)
fatalx("option not a number");
return (o->num);
}
+
+struct options_entry *
+options_set_data(
+ struct options *oo, const char *name, void *value, void (*freefn)(void *))
+{
+ struct options_entry *o;
+
+ if ((o = options_find1(oo, name)) == NULL) {
+ o = xmalloc(sizeof *o);
+ o->name = xstrdup(name);
+ SPLAY_INSERT(options_tree, &oo->tree, o);
+ } else if (o->type == OPTIONS_STRING)
+ xfree(o->str);
+ else if (o->type == OPTIONS_DATA)
+ o->freefn(o->data);
+
+ o->type = OPTIONS_DATA;
+ o->data = value;
+ o->freefn = freefn;
+ return (o);
+}
+
+void *
+options_get_data(struct options *oo, const char *name)
+{
+ struct options_entry *o;
+
+ if ((o = options_find(oo, name)) == NULL)
+ fatalx("missing option");
+ if (o->type != OPTIONS_DATA)
+ fatalx("option not data");
+ return (o->data);
+}