Lines Matching defs:o

71 #define OPTIONS_IS_STRING(o)						\
72 ((o)->tableentry == NULL || \
73 (o)->tableentry->type == OPTIONS_TABLE_STRING)
74 #define OPTIONS_IS_NUMBER(o) \
75 ((o)->tableentry != NULL && \
76 ((o)->tableentry->type == OPTIONS_TABLE_NUMBER || \
77 (o)->tableentry->type == OPTIONS_TABLE_KEY || \
78 (o)->tableentry->type == OPTIONS_TABLE_COLOUR || \
79 (o)->tableentry->type == OPTIONS_TABLE_FLAG || \
80 (o)->tableentry->type == OPTIONS_TABLE_CHOICE))
81 #define OPTIONS_IS_COMMAND(o) \
82 ((o)->tableentry != NULL && \
83 (o)->tableentry->type == OPTIONS_TABLE_COMMAND)
85 #define OPTIONS_IS_ARRAY(o) \
86 ((o)->tableentry != NULL && \
87 ((o)->tableentry->flags & OPTIONS_TABLE_IS_ARRAY))
113 struct options_entry *o;
117 o = options_get(oo->parent, s);
118 if (o == NULL)
120 return (o->tableentry);
124 options_value_free(struct options_entry *o, union options_value *ov)
126 if (OPTIONS_IS_STRING(o))
128 if (OPTIONS_IS_COMMAND(o) && ov->cmdlist != NULL)
133 options_value_to_string(struct options_entry *o, union options_value *ov,
138 if (OPTIONS_IS_COMMAND(o))
140 if (OPTIONS_IS_NUMBER(o)) {
141 switch (o->tableentry->type) {
158 s = xstrdup(o->tableentry->choices[ov->number]);
165 if (OPTIONS_IS_STRING(o))
184 struct options_entry *o, *tmp;
186 RB_FOREACH_SAFE(o, options_tree, &oo->tree, tmp)
187 options_remove(o);
210 options_next(struct options_entry *o)
212 return (RB_NEXT(options_tree, &oo->tree, o));
218 struct options_entry o = { .name = name }, *found;
220 found = RB_FIND(options_tree, &oo->tree, &o);
222 o.name = options_map_name(name);
223 return (RB_FIND(options_tree, &oo->tree, &o));
231 struct options_entry *o;
233 o = options_get_only(oo, name);
234 while (o == NULL) {
238 o = options_get_only(oo, name);
240 return (o);
246 struct options_entry *o;
248 o = options_add(oo, oe->name);
249 o->tableentry = oe;
252 RB_INIT(&o->value.array);
254 return (o);
260 struct options_entry *o;
264 o = options_empty(oo, oe);
265 ov = &o->value;
269 options_array_assign(o, oe->default_str, NULL);
270 return (o);
273 options_array_set(o, i, oe->default_arr[i], 0, NULL);
274 return (o);
285 return (o);
322 struct options_entry *o;
324 o = options_get_only(oo, name);
325 if (o != NULL)
326 options_remove(o);
328 o = xcalloc(1, sizeof *o);
329 o->owner = oo;
330 o->name = xstrdup(name);
332 RB_INSERT(options_tree, &oo->tree, o);
333 return (o);
337 options_remove(struct options_entry *o)
339 struct options *oo = o->owner;
341 if (OPTIONS_IS_ARRAY(o))
342 options_array_clear(o);
344 options_value_free(o, &o->value);
345 RB_REMOVE(options_tree, &oo->tree, o);
346 free((void *)o->name);
347 free(o);
351 options_name(struct options_entry *o)
353 return (o->name);
357 options_owner(struct options_entry *o)
359 return (o->owner);
363 options_table_entry(struct options_entry *o)
365 return (o->tableentry);
369 options_array_item(struct options_entry *o, u_int idx)
374 return (RB_FIND(options_array, &o->value.array, &a));
378 options_array_new(struct options_entry *o, u_int idx)
384 RB_INSERT(options_array, &o->value.array, a);
389 options_array_free(struct options_entry *o, struct options_array_item *a)
391 options_value_free(o, &a->value);
392 RB_REMOVE(options_array, &o->value.array, a);
397 options_array_clear(struct options_entry *o)
401 if (!OPTIONS_IS_ARRAY(o))
404 RB_FOREACH_SAFE(a, options_array, &o->value.array, a1)
405 options_array_free(o, a);
409 options_array_get(struct options_entry *o, u_int idx)
413 if (!OPTIONS_IS_ARRAY(o))
415 a = options_array_item(o, idx);
422 options_array_set(struct options_entry *o, u_int idx, const char *value,
430 if (!OPTIONS_IS_ARRAY(o)) {
437 a = options_array_item(o, idx);
439 options_array_free(o, a);
443 if (OPTIONS_IS_COMMAND(o)) {
456 a = options_array_item(o, idx);
458 a = options_array_new(o, idx);
460 options_value_free(o, &a->value);
465 if (OPTIONS_IS_STRING(o)) {
466 a = options_array_item(o, idx);
472 a = options_array_new(o, idx);
474 options_value_free(o, &a->value);
479 if (o->tableentry->type == OPTIONS_TABLE_COLOUR) {
484 a = options_array_item(o, idx);
486 a = options_array_new(o, idx);
488 options_value_free(o, &a->value);
499 options_array_assign(struct options_entry *o, const char *s, char **cause)
505 separator = o->tableentry->separator;
512 if (options_array_item(o, i) == NULL)
515 return (options_array_set(o, i, s, 0, cause));
525 if (options_array_item(o, i) == NULL)
530 if (options_array_set(o, i, next, 0, cause) != 0) {
540 options_array_first(struct options_entry *o)
542 if (!OPTIONS_IS_ARRAY(o))
544 return (RB_MIN(options_array, &o->value.array));
550 return (RB_NEXT(options_array, &o->value.array, a));
566 options_is_array(struct options_entry *o)
568 return (OPTIONS_IS_ARRAY(o));
572 options_is_string(struct options_entry *o)
574 return (OPTIONS_IS_STRING(o));
578 options_to_string(struct options_entry *o, int idx, int numeric)
585 if (OPTIONS_IS_ARRAY(o)) {
587 RB_FOREACH(a, options_array, &o->value.array) {
588 next = options_value_to_string(o, &a->value,
603 a = options_array_item(o, idx);
606 return (options_value_to_string(o, &a->value, numeric));
608 return (options_value_to_string(o, &o->value, numeric));
639 struct options_entry *o;
646 o = options_get_only(oo, name);
648 o = options_get(oo, name);
650 return (o);
700 struct options_entry *o;
707 o = options_get_only(oo, name);
709 o = options_get(oo, name);
711 return (o);
717 struct options_entry *o;
719 o = options_get(oo, name);
720 if (o == NULL)
722 if (!OPTIONS_IS_STRING(o))
724 return (o->value.string);
730 struct options_entry *o;
732 o = options_get(oo, name);
733 if (o == NULL)
735 if (!OPTIONS_IS_NUMBER(o))
737 return (o->value.number);
744 struct options_entry *o;
753 o = options_get_only(oo, name);
754 if (o != NULL && append && OPTIONS_IS_STRING(o)) {
756 separator = o->tableentry->separator;
760 xasprintf(&value, "%s%s%s", o->value.string, separator, s);
764 if (o == NULL && *name == '@')
765 o = options_add(oo, name);
766 else if (o == NULL) {
767 o = options_default(oo, options_parent_table_entry(oo, name));
768 if (o == NULL)
772 if (!OPTIONS_IS_STRING(o))
774 free(o->value.string);
775 o->value.string = value;
776 o->cached = 0;
777 return (o);
783 struct options_entry *o;
788 o = options_get_only(oo, name);
789 if (o == NULL) {
790 o = options_default(oo, options_parent_table_entry(oo, name));
791 if (o == NULL)
795 if (!OPTIONS_IS_NUMBER(o))
797 o->value.number = value;
798 return (o);
931 struct options_entry *o;
935 o = options_get(oo, name);
936 if (o == NULL || !OPTIONS_IS_STRING(o))
939 if (o->cached)
940 return (&o->style);
941 s = o->value.string;
944 style_set(&o->style, &grid_default_cell);
945 o->cached = (strstr(s, "#{") == NULL);
947 if (ft != NULL && !o->cached) {
949 if (style_parse(&o->style, &grid_default_cell, expanded) != 0) {
955 if (style_parse(&o->style, &grid_default_cell, s) != 0)
958 return (&o->style);
1203 options_remove_or_default(struct options_entry *o, int idx, char **cause)
1205 struct options *oo = o->owner;
1208 if (o->tableentry != NULL &&
1212 options_default(oo, o->tableentry);
1214 options_remove(o);
1215 } else if (options_array_set(o, idx, NULL, 0, cause) != 0)