=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/options.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- src/usr.bin/tmux/options.c 2017/01/18 08:43:21 1.30 +++ src/usr.bin/tmux/options.c 2017/01/24 19:11:46 1.31 @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.30 2017/01/18 08:43:21 nicm Exp $ */ +/* $OpenBSD: options.c,v 1.31 2017/01/24 19:11:46 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -170,22 +170,11 @@ options_default(struct options *oo, const struct options_table_entry *oe) { struct options_entry *o; - char *cp, *copy, *next; - u_int idx = 0; o = options_empty(oo, oe); - - if (oe->type == OPTIONS_TABLE_ARRAY) { - copy = cp = xstrdup(oe->default_str); - while ((next = strsep(&cp, ",")) != NULL) { - options_array_set(o, idx, next); - idx++; - } - free(copy); - return (o); - } - - if (oe->type == OPTIONS_TABLE_STRING) + if (oe->type == OPTIONS_TABLE_ARRAY) + options_array_assign(o, oe->default_str); + else if (oe->type == OPTIONS_TABLE_STRING) o->string = xstrdup(oe->default_str); else if (oe->type == OPTIONS_TABLE_STYLE) { memcpy(&o->style, &grid_default_cell, sizeof o->style); @@ -242,6 +231,13 @@ return (o->tableentry); } +void +options_array_clear(struct options_entry *o) +{ + if (OPTIONS_IS_ARRAY(o)) + o->arraysize = 0; +} + const char * options_array_get(struct options_entry *o, u_int idx) { @@ -253,9 +249,11 @@ } int -options_array_set(struct options_entry *o, u_int idx, const char *value) +options_array_set(struct options_entry *o, u_int idx, const char *value, + int append) { - u_int i; + char *new; + u_int i; if (!OPTIONS_IS_ARRAY(o)) return (-1); @@ -268,12 +266,17 @@ o->array[i] = NULL; o->arraysize = idx + 1; } - if (o->array[idx] != NULL) - free((void *)o->array[idx]); - if (value != NULL) - o->array[idx] = xstrdup(value); - else - o->array[idx] = NULL; + + new = NULL; + if (value != NULL) { + if (o->array[idx] != NULL && append) + xasprintf(&new, "%s%s", o->array[idx], value); + else + new = xstrdup(value); + } + + free((void *)o->array[idx]); + o->array[idx] = new; return (0); } @@ -287,6 +290,32 @@ return (0); } +void +options_array_assign(struct options_entry *o, const char *s) +{ + const char *separator; + char *copy, *next, *string; + u_int i; + + separator = o->tableentry->separator; + if (separator == NULL) + separator = " ,"; + + copy = string = xstrdup(s); + while ((next = strsep(&string, separator)) != NULL) { + if (*next == '\0') + continue; + for (i = 0; i < OPTIONS_ARRAY_LIMIT; i++) { + if (i >= o->arraysize || o->array[i] == NULL) + break; + } + if (i == OPTIONS_ARRAY_LIMIT) + break; + options_array_set(o, i, next, 0); + } + free(copy); +} + int options_isstring(struct options_entry *o) { @@ -384,12 +413,6 @@ else o = options_get(oo, name); free(name); - if (o != NULL) { - if (OPTIONS_IS_ARRAY(o) && *idx == -1) - return (NULL); - if (!OPTIONS_IS_ARRAY(o) && *idx != -1) - return (NULL); - } return (o); } @@ -447,12 +470,6 @@ else o = options_get(oo, name); free(name); - if (o != NULL) { - if (OPTIONS_IS_ARRAY(o) && *idx == -1) - return (NULL); - if (!OPTIONS_IS_ARRAY(o) && *idx != -1) - return (NULL); - } return (o); }