summaryrefslogtreecommitdiffstats
path: root/options.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2014-01-31 21:39:56 +0000
committerThomas Adam <thomas@xteddy.org>2014-01-31 21:39:56 +0000
commitd50e47fc4ab5cbbdbe6bbebdc2c36ce3aae6e987 (patch)
tree397f4999444c2eef367f884b815bec2a14697c3c /options.c
parentcbf9224c5f7bcf07352f6ea128c90c12cb0af22e (diff)
parent9f02feb9d089b1a4639afb52ab0e8212eeb55a7c (diff)
Merge branch 'obsd-master'
Conflicts: Makefile cmd-server-info.c cmd-start-server.c
Diffstat (limited to 'options.c')
-rw-r--r--options.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/options.c b/options.c
index 7360906b..8bec8e5c 100644
--- a/options.c
+++ b/options.c
@@ -26,7 +26,7 @@
/*
* Option handling; each option has a name, type and value and is stored in
- * a splay tree.
+ * a red-black tree.
*/
RB_GENERATE(options_tree, options_entry, entry, options_cmp);
@@ -109,6 +109,7 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
o = xmalloc(sizeof *o);
o->name = xstrdup(name);
RB_INSERT(options_tree, &oo->tree, o);
+ memcpy(&o->style, &grid_default_cell, sizeof o->style);
} else if (o->type == OPTIONS_STRING)
free(o->str);
@@ -140,6 +141,7 @@ options_set_number(struct options *oo, const char *name, long long value)
o = xmalloc(sizeof *o);
o->name = xstrdup(name);
RB_INSERT(options_tree, &oo->tree, o);
+ memcpy(&o->style, &grid_default_cell, sizeof o->style);
} else if (o->type == OPTIONS_STRING)
free(o->str);
@@ -159,3 +161,37 @@ options_get_number(struct options *oo, const char *name)
fatalx("option not a number");
return (o->num);
}
+
+struct options_entry *
+options_set_style(struct options *oo, const char *name, const char *value,
+ int append)
+{
+ struct options_entry *o;
+
+ if ((o = options_find1(oo, name)) == NULL) {
+ o = xmalloc(sizeof *o);
+ o->name = xstrdup(name);
+ RB_INSERT(options_tree, &oo->tree, o);
+ } else if (o->type == OPTIONS_STRING)
+ free(o->str);
+
+ if (!append)
+ memcpy(&o->style, &grid_default_cell, sizeof o->style);
+
+ o->type = OPTIONS_STYLE;
+ if (style_parse(&grid_default_cell, &o->style, value) == -1)
+ return (NULL);
+ return (o);
+}
+
+struct grid_cell *
+options_get_style(struct options *oo, const char *name)
+{
+ struct options_entry *o;
+
+ if ((o = options_find(oo, name)) == NULL)
+ fatalx("missing option");
+ if (o->type != OPTIONS_STYLE)
+ fatalx("option not a style");
+ return (&o->style);
+}