summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-03-14 21:46:09 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-03-14 21:46:09 +0000
commit5c25cc5df53d56a69f71ee6e5511b783112712f6 (patch)
tree1184a365e5495904a7925cc24c18af4349ce8715 /usr.bin
parentce8af9e41e9fb51fc6306fa9be2dff716cf566de (diff)
Remove some unnecessary temporary variables and be much less strict
about spacing in style_parse.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/style.c67
1 files changed, 31 insertions, 36 deletions
diff --git a/usr.bin/tmux/style.c b/usr.bin/tmux/style.c
index 6c7b083c382..02ab5617b97 100644
--- a/usr.bin/tmux/style.c
+++ b/usr.bin/tmux/style.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: style.c,v 1.16 2019/03/14 10:19:52 nicm Exp $ */
+/* $OpenBSD: style.c,v 1.17 2019/03/14 21:46:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -39,24 +39,24 @@ static struct style style_default = {
int
style_parse(struct style *sy, const struct grid_cell *base, const char *in)
{
- struct style saved;
- const char delimiters[] = " ,";
- char tmp[32];
- int value, fg, bg, attr, flags;
- size_t end;
+ struct style saved;
+ const char delimiters[] = " ,";
+ char tmp[32];
+ int value;
+ size_t end;
if (*in == '\0')
return (0);
- if (strchr(delimiters, in[strlen(in) - 1]) != NULL)
- return (-1);
style_copy(&saved, sy);
- fg = sy->gc.fg;
- bg = sy->gc.bg;
- attr = sy->gc.attr;
- flags = sy->gc.flags;
-
do {
+ while (*in != '\0' && strchr(delimiters, *in) != NULL) {
+ in++;
+ end--;
+ }
+ if (*in == '\0')
+ break;
+
end = strcspn(in, delimiters);
if (end > (sizeof tmp) - 1)
goto error;
@@ -64,45 +64,40 @@ style_parse(struct style *sy, const struct grid_cell *base, const char *in)
tmp[end] = '\0';
if (strcasecmp(tmp, "default") == 0) {
- fg = base->fg;
- bg = base->bg;
- attr = base->attr;
- flags = base->flags;
+ sy->gc.fg = base->fg;
+ sy->gc.bg = base->bg;
+ sy->gc.attr = base->attr;
+ sy->gc.flags = base->flags;
} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
if ((value = colour_fromstring(tmp + 3)) == -1)
goto error;
if (*in == 'f' || *in == 'F') {
if (value != 8)
- fg = value;
+ sy->gc.fg = value;
else
- fg = base->fg;
+ sy->gc.fg = base->fg;
} else if (*in == 'b' || *in == 'B') {
if (value != 8)
- bg = value;
+ sy->gc.bg = value;
else
- bg = base->bg;
+ sy->gc.bg = base->bg;
} else
goto error;
} else if (strcasecmp(tmp, "none") == 0)
- attr = 0;
+ sy->gc.attr = 0;
else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
if ((value = attributes_fromstring(tmp + 2)) == -1)
goto error;
- attr &= ~value;
+ sy->gc.attr &= ~value;
} else {
if ((value = attributes_fromstring(tmp)) == -1)
goto error;
- attr |= value;
+ sy->gc.attr |= value;
}
in += end + strspn(in + end, delimiters);
} while (*in != '\0');
- sy->gc.fg = fg;
- sy->gc.bg = bg;
- sy->gc.attr = attr;
- sy->gc.flags = flags;
-
return (0);
error:
@@ -122,18 +117,18 @@ style_tostring(struct style *sy)
*s = '\0';
if (gc->fg != 8) {
- off += xsnprintf(s + off, sizeof s - off, "%sfg=%s",
- comma, colour_tostring(gc->fg));
+ off += xsnprintf(s + off, sizeof s - off, "%sfg=%s", comma,
+ colour_tostring(gc->fg));
comma = ",";
}
if (gc->bg != 8) {
- off += xsnprintf(s + off, sizeof s - off, "%sbg=%s",
- comma, colour_tostring(gc->bg));
+ off += xsnprintf(s + off, sizeof s - off, "%sbg=%s", comma,
+ colour_tostring(gc->bg));
comma = ",";
}
if (gc->attr != 0 && gc->attr != GRID_ATTR_CHARSET) {
- xsnprintf(s + off, sizeof s - off, "%s%s",
- comma, attributes_tostring(gc->attr));
+ xsnprintf(s + off, sizeof s - off, "%s%s", comma,
+ attributes_tostring(gc->attr));
comma = ",";
}
@@ -174,7 +169,7 @@ style_apply_update(struct grid_cell *gc, struct options *oo, const char *name)
void
style_set(struct style *sy, const struct grid_cell *gc)
{
- memset(sy, 0, sizeof *sy);
+ memcpy(sy, &style_default, sizeof *sy);
memcpy(&sy->gc, gc, sizeof sy->gc);
}