aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-04-25 21:02:43 +0100
committerThomas Adam <thomas@xteddy.org>2019-04-25 21:02:43 +0100
commit7c4a2253e89dd26018de489301e46d8425893a78 (patch)
tree50a72e4f59f1d27092b9e1c29fb0d0a1228cfe62
parentf2c0605d6d7051898318703142af4ceb7e3f845f (diff)
parent2d65bbd94129c4542394a83151cb1a131c3c7871 (diff)
downloadrtmux-7c4a2253e89dd26018de489301e46d8425893a78.tar.gz
rtmux-7c4a2253e89dd26018de489301e46d8425893a78.tar.bz2
rtmux-7c4a2253e89dd26018de489301e46d8425893a78.zip
Merge branch 'obsd-master'
-rw-r--r--cmd-show-options.c5
-rw-r--r--cmd.c4
-rw-r--r--environ.c4
-rw-r--r--format.c27
-rw-r--r--options.c39
-rw-r--r--status.c7
-rw-r--r--tmux.h2
-rw-r--r--tty-keys.c3
-rw-r--r--tty-term.c3
-rw-r--r--tty.c12
10 files changed, 45 insertions, 61 deletions
diff --git a/cmd-show-options.c b/cmd-show-options.c
index 59d9f9f5..642b3f89 100644
--- a/cmd-show-options.c
+++ b/cmd-show-options.c
@@ -161,8 +161,8 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
struct options_entry *o, int idx)
{
struct options_array_item *a;
- const char *name, *value;
- char *tmp, *escaped;
+ const char *name;
+ char *value, *tmp, *escaped;
if (idx != -1) {
xasprintf(&tmp, "%s[%d]", options_name(o), idx);
@@ -190,6 +190,7 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
free(escaped);
} else
cmdq_print(item, "%s %s", name, value);
+ free(value);
free(tmp);
}
diff --git a/cmd.c b/cmd.c
index 82dcae3d..8d61a572 100644
--- a/cmd.c
+++ b/cmd.c
@@ -334,10 +334,6 @@ cmd_try_alias(int *argc, char ***argv)
a = options_array_first(o);
while (a != NULL) {
ov = options_array_item_value(a);
- if (ov == NULL) {
- a = options_array_next(a);
- continue;
- }
cp = strchr(ov->string, '=');
if (cp != NULL &&
(size_t)(cp - ov->string) == wanted &&
diff --git a/environ.c b/environ.c
index 301c4f29..25968f7b 100644
--- a/environ.c
+++ b/environ.c
@@ -185,10 +185,6 @@ environ_update(struct options *oo, struct environ *src, struct environ *dst)
a = options_array_first(o);
while (a != NULL) {
ov = options_array_item_value(a);
- if (ov == NULL) {
- a = options_array_next(a);
- continue;
- }
if ((envent = environ_find(src, ov->string)) == NULL)
environ_clear(dst, ov->string);
else
diff --git a/format.c b/format.c
index a5c61d68..db642f63 100644
--- a/format.c
+++ b/format.c
@@ -920,9 +920,8 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
struct environ_entry *envent;
static char s[64];
struct options_entry *o;
- const char *found;
int idx;
- char *copy, *saved;
+ char *found, *saved;
if (~modifiers & FORMAT_TIMESTRING) {
o = options_parse_get(global_options, key, &idx, 0);
@@ -949,12 +948,11 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
return (NULL);
ctime_r(&fe->t, s);
s[strcspn(s, "\n")] = '\0';
- found = s;
+ found = xstrdup(s);
goto found;
}
if (fe->t != 0) {
- xsnprintf(s, sizeof s, "%lld", (long long)fe->t);
- found = s;
+ xasprintf(&found, "%lld", (long long)fe->t);
goto found;
}
if (fe->value == NULL && fe->cb != NULL) {
@@ -962,7 +960,7 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
if (fe->value == NULL)
fe->value = xstrdup("");
}
- found = fe->value;
+ found = xstrdup(fe->value);
goto found;
}
@@ -973,7 +971,7 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
if (envent == NULL)
envent = environ_find(global_environ, key);
if (envent != NULL) {
- found = envent->value;
+ found = xstrdup(envent->value);
goto found;
}
}
@@ -983,23 +981,22 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
found:
if (found == NULL)
return (NULL);
- copy = xstrdup(found);
if (modifiers & FORMAT_BASENAME) {
- saved = copy;
- copy = xstrdup(basename(saved));
+ saved = found;
+ found = xstrdup(basename(saved));
free(saved);
}
if (modifiers & FORMAT_DIRNAME) {
- saved = copy;
- copy = xstrdup(dirname(saved));
+ saved = found;
+ found = xstrdup(dirname(saved));
free(saved);
}
if (modifiers & FORMAT_QUOTE) {
- saved = copy;
- copy = xstrdup(format_quote(saved));
+ saved = found;
+ found = xstrdup(format_quote(saved));
free(saved);
}
- return (copy);
+ return (found);
}
/* Skip until end. */
diff --git a/options.c b/options.c
index 0b13bca0..fb271d5e 100644
--- a/options.c
+++ b/options.c
@@ -110,47 +110,43 @@ options_value_free(struct options_entry *o, union options_value *ov)
free(ov->string);
}
-static const char *
+static char *
options_value_tostring(struct options_entry *o, union options_value *ov,
int numeric)
{
- static char s[1024];
- const char *tmp;
+ char *s;
if (OPTIONS_IS_STYLE(o))
- return (style_tostring(&ov->style));
+ return (xstrdup(style_tostring(&ov->style)));
if (OPTIONS_IS_NUMBER(o)) {
- tmp = NULL;
switch (o->tableentry->type) {
case OPTIONS_TABLE_NUMBER:
- xsnprintf(s, sizeof s, "%lld", ov->number);
+ xasprintf(&s, "%lld", ov->number);
break;
case OPTIONS_TABLE_KEY:
- tmp = key_string_lookup_key(ov->number);
+ s = xstrdup(key_string_lookup_key(ov->number));
break;
case OPTIONS_TABLE_COLOUR:
- tmp = colour_tostring(ov->number);
+ s = xstrdup(colour_tostring(ov->number));
break;
case OPTIONS_TABLE_FLAG:
if (numeric)
- xsnprintf(s, sizeof s, "%lld", ov->number);
+ xasprintf(&s, "%lld", ov->number);
else
- tmp = (ov->number ? "on" : "off");
+ s = xstrdup(ov->number ? "on" : "off");
break;
case OPTIONS_TABLE_CHOICE:
- tmp = o->tableentry->choices[ov->number];
+ s = xstrdup(o->tableentry->choices[ov->number]);
break;
case OPTIONS_TABLE_STRING:
case OPTIONS_TABLE_STYLE:
- break;
+ fatalx("not a number option type");
}
- if (tmp != NULL)
- xsnprintf(s, sizeof s, "%s", tmp);
return (s);
}
if (OPTIONS_IS_STRING(o))
- return (ov->string);
- return ("");
+ return (xstrdup(ov->string));
+ return (xstrdup(""));
}
struct options *
@@ -218,11 +214,8 @@ options_empty(struct options *oo, const struct options_table_entry *oe)
o = options_add(oo, oe->name);
o->tableentry = oe;
- if (oe->flags & OPTIONS_TABLE_IS_ARRAY) {
- if (oe->type != OPTIONS_TABLE_STRING)
- fatalx("arrays can only be strings");
+ if (oe->flags & OPTIONS_TABLE_IS_ARRAY)
RB_INIT(&o->value.array);
- }
return (o);
}
@@ -443,17 +436,17 @@ options_isstring(struct options_entry *o)
return (OPTIONS_IS_STRING(o));
}
-const char *
+char *
options_tostring(struct options_entry *o, int idx, int numeric)
{
struct options_array_item *a;
if (OPTIONS_IS_ARRAY(o)) {
if (idx == -1)
- return (NULL);
+ return (xstrdup(""));
a = options_array_item(o, idx);
if (a == NULL)
- return ("");
+ return (xstrdup(""));
return (options_value_tostring(o, &a->value, numeric));
}
return (options_value_tostring(o, &o->value, numeric));
diff --git a/status.c b/status.c
index 1a11a564..34ed3778 100644
--- a/status.c
+++ b/status.c
@@ -1293,7 +1293,6 @@ status_prompt_complete_list(u_int *size, const char *s)
size_t slen = strlen(s), valuelen;
struct options_entry *o;
struct options_array_item *a;
- union options_value *ov;
const char *layouts[] = {
"even-horizontal", "even-vertical", "main-horizontal",
"main-vertical", "tiled", NULL
@@ -1322,11 +1321,7 @@ status_prompt_complete_list(u_int *size, const char *s)
if (o != NULL) {
a = options_array_first(o);
while (a != NULL) {
- ov = options_array_item_value(a);
- if (ov == NULL)
- goto next;
-
- value = ov->string;
+ value = options_array_item_value(a)->string;
if ((cp = strchr(value, '=')) == NULL)
goto next;
valuelen = cp - value;
diff --git a/tmux.h b/tmux.h
index 0c317b8b..03ed41af 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1744,7 +1744,7 @@ u_int options_array_item_index(struct options_array_item *);
union options_value *options_array_item_value(struct options_array_item *);
int options_isarray(struct options_entry *);
int options_isstring(struct options_entry *);
-const char *options_tostring(struct options_entry *, int, int);
+char *options_tostring(struct options_entry *, int, int);
char *options_parse(const char *, int *);
struct options_entry *options_parse_get(struct options *, const char *, int *,
int);
diff --git a/tty-keys.c b/tty-keys.c
index c6dcbb56..850c9119 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -429,8 +429,7 @@ tty_keys_build(struct tty *tty)
a = options_array_first(o);
while (a != NULL) {
ov = options_array_item_value(a);
- if (ov != NULL)
- tty_keys_add(tty, ov->string, KEYC_USER + i);
+ tty_keys_add(tty, ov->string, KEYC_USER + i);
a = options_array_next(a);
}
}
diff --git a/tty-term.c b/tty-term.c
index 89d3241c..c458752d 100644
--- a/tty-term.c
+++ b/tty-term.c
@@ -499,8 +499,7 @@ tty_term_find(char *name, int fd, char **cause)
a = options_array_first(o);
while (a != NULL) {
ov = options_array_item_value(a);
- if (ov != NULL)
- tty_term_override(term, ov->string);
+ tty_term_override(term, ov->string);
a = options_array_next(a);
}
diff --git a/tty.c b/tty.c
index ff72b7da..cc528e8e 100644
--- a/tty.c
+++ b/tty.c
@@ -2388,7 +2388,11 @@ tty_colours_fg(struct tty *tty, const struct grid_cell *gc)
/* Is this an aixterm bright colour? */
if (gc->fg >= 90 && gc->fg <= 97) {
- tty_putcode1(tty, TTYC_SETAF, gc->fg - 90 + 8);
+ if (tty->term_flags & TERM_256COLOURS) {
+ xsnprintf(s, sizeof s, "\033[%dm", gc->fg);
+ tty_puts(tty, s);
+ } else
+ tty_putcode1(tty, TTYC_SETAF, gc->fg - 90 + 8);
goto save_fg;
}
@@ -2416,7 +2420,11 @@ tty_colours_bg(struct tty *tty, const struct grid_cell *gc)
/* Is this an aixterm bright colour? */
if (gc->bg >= 90 && gc->bg <= 97) {
- tty_putcode1(tty, TTYC_SETAB, gc->bg - 90 + 8);
+ if (tty->term_flags & TERM_256COLOURS) {
+ xsnprintf(s, sizeof s, "\033[%dm", gc->bg + 10);
+ tty_puts(tty, s);
+ } else
+ tty_putcode1(tty, TTYC_SETAB, gc->bg - 90 + 8);
goto save_bg;
}