version 1.21, 2017/01/11 14:56:44 |
version 1.22, 2017/01/12 15:36:35 |
|
|
} |
} |
|
|
static struct options_entry * |
static struct options_entry * |
options_new(struct options *oo, const char *name, char **s) |
options_new(struct options *oo, const char *name) |
{ |
{ |
struct options_entry *o; |
struct options_entry *o; |
|
|
if (s != NULL) |
|
*s = NULL; |
|
|
|
if ((o = options_find1(oo, name)) == NULL) { |
if ((o = options_find1(oo, name)) == NULL) { |
o = xmalloc(sizeof *o); |
o = xmalloc(sizeof *o); |
o->name = xstrdup(name); |
o->name = xstrdup(name); |
RB_INSERT(options_tree, &oo->tree, o); |
RB_INSERT(options_tree, &oo->tree, o); |
memcpy(&o->style, &grid_default_cell, sizeof o->style); |
memcpy(&o->style, &grid_default_cell, sizeof o->style); |
} else if (o->type == OPTIONS_STRING) { |
} else if (o->type == OPTIONS_STRING) |
if (s != NULL) |
free(o->str); |
*s = o->str; |
|
else |
|
free(o->str); |
|
} |
|
return (o); |
return (o); |
} |
} |
|
|
|
|
} |
} |
|
|
struct options_entry * |
struct options_entry * |
options_set_string(struct options *oo, const char *name, const char *fmt, ...) |
options_set_string(struct options *oo, const char *name, int append, |
|
const char *fmt, ...) |
{ |
{ |
struct options_entry *o; |
struct options_entry *o; |
va_list ap; |
va_list ap; |
char *s; |
char *s, *value; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
|
xvasprintf(&s, fmt, ap); |
|
va_end(ap); |
|
|
o = options_new(oo, name, &s); |
o = options_find1(oo, name); |
|
if (o == NULL || !append) |
|
value = s; |
|
else { |
|
xasprintf(&value, "%s%s", s, o->str); |
|
free(s); |
|
} |
|
|
|
o = options_new(oo, name); |
o->type = OPTIONS_STRING; |
o->type = OPTIONS_STRING; |
xvasprintf(&o->str, fmt, ap); |
o->str = value; |
free(s); |
|
|
|
va_end(ap); |
|
return (o); |
return (o); |
} |
} |
|
|
|
|
{ |
{ |
struct options_entry *o; |
struct options_entry *o; |
|
|
o = options_new(oo, name, NULL); |
o = options_new(oo, name); |
o->type = OPTIONS_NUMBER; |
o->type = OPTIONS_NUMBER; |
o->num = value; |
o->num = value; |
|
|
|
|
} |
} |
|
|
struct options_entry * |
struct options_entry * |
options_set_style(struct options *oo, const char *name, const char *value, |
options_set_style(struct options *oo, const char *name, int append, |
int append) |
const char *value) |
{ |
{ |
struct options_entry *o; |
struct options_entry *o; |
struct grid_cell tmpgc; |
struct grid_cell tmpgc; |
|
|
if (style_parse(&grid_default_cell, &tmpgc, value) == -1) |
if (style_parse(&grid_default_cell, &tmpgc, value) == -1) |
return (NULL); |
return (NULL); |
|
|
o = options_new(oo, name, NULL); |
o = options_new(oo, name); |
o->type = OPTIONS_STYLE; |
o->type = OPTIONS_STYLE; |
memcpy(&o->style, &tmpgc, sizeof o->style); |
memcpy(&o->style, &tmpgc, sizeof o->style); |
|
|