mirror of
https://github.com/tmux/tmux.git
synced 2025-04-23 04:48:47 +00:00
Remove some unnecessary temporary variables and be much less strict
about spacing in style_parse.
This commit is contained in:
parent
4206bcc10e
commit
bace79a571
65
style.c
65
style.c
@ -39,24 +39,24 @@ static struct style style_default = {
|
|||||||
int
|
int
|
||||||
style_parse(struct style *sy, const struct grid_cell *base, const char *in)
|
style_parse(struct style *sy, const struct grid_cell *base, const char *in)
|
||||||
{
|
{
|
||||||
struct style saved;
|
struct style saved;
|
||||||
const char delimiters[] = " ,";
|
const char delimiters[] = " ,";
|
||||||
char tmp[32];
|
char tmp[32];
|
||||||
int value, fg, bg, attr, flags;
|
int value;
|
||||||
size_t end;
|
size_t end;
|
||||||
|
|
||||||
if (*in == '\0')
|
if (*in == '\0')
|
||||||
return (0);
|
return (0);
|
||||||
if (strchr(delimiters, in[strlen(in) - 1]) != NULL)
|
|
||||||
return (-1);
|
|
||||||
style_copy(&saved, sy);
|
style_copy(&saved, sy);
|
||||||
|
|
||||||
fg = sy->gc.fg;
|
|
||||||
bg = sy->gc.bg;
|
|
||||||
attr = sy->gc.attr;
|
|
||||||
flags = sy->gc.flags;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
while (*in != '\0' && strchr(delimiters, *in) != NULL) {
|
||||||
|
in++;
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
if (*in == '\0')
|
||||||
|
break;
|
||||||
|
|
||||||
end = strcspn(in, delimiters);
|
end = strcspn(in, delimiters);
|
||||||
if (end > (sizeof tmp) - 1)
|
if (end > (sizeof tmp) - 1)
|
||||||
goto error;
|
goto error;
|
||||||
@ -64,45 +64,40 @@ style_parse(struct style *sy, const struct grid_cell *base, const char *in)
|
|||||||
tmp[end] = '\0';
|
tmp[end] = '\0';
|
||||||
|
|
||||||
if (strcasecmp(tmp, "default") == 0) {
|
if (strcasecmp(tmp, "default") == 0) {
|
||||||
fg = base->fg;
|
sy->gc.fg = base->fg;
|
||||||
bg = base->bg;
|
sy->gc.bg = base->bg;
|
||||||
attr = base->attr;
|
sy->gc.attr = base->attr;
|
||||||
flags = base->flags;
|
sy->gc.flags = base->flags;
|
||||||
} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
|
} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
|
||||||
if ((value = colour_fromstring(tmp + 3)) == -1)
|
if ((value = colour_fromstring(tmp + 3)) == -1)
|
||||||
goto error;
|
goto error;
|
||||||
if (*in == 'f' || *in == 'F') {
|
if (*in == 'f' || *in == 'F') {
|
||||||
if (value != 8)
|
if (value != 8)
|
||||||
fg = value;
|
sy->gc.fg = value;
|
||||||
else
|
else
|
||||||
fg = base->fg;
|
sy->gc.fg = base->fg;
|
||||||
} else if (*in == 'b' || *in == 'B') {
|
} else if (*in == 'b' || *in == 'B') {
|
||||||
if (value != 8)
|
if (value != 8)
|
||||||
bg = value;
|
sy->gc.bg = value;
|
||||||
else
|
else
|
||||||
bg = base->bg;
|
sy->gc.bg = base->bg;
|
||||||
} else
|
} else
|
||||||
goto error;
|
goto error;
|
||||||
} else if (strcasecmp(tmp, "none") == 0)
|
} else if (strcasecmp(tmp, "none") == 0)
|
||||||
attr = 0;
|
sy->gc.attr = 0;
|
||||||
else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
|
else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
|
||||||
if ((value = attributes_fromstring(tmp + 2)) == -1)
|
if ((value = attributes_fromstring(tmp + 2)) == -1)
|
||||||
goto error;
|
goto error;
|
||||||
attr &= ~value;
|
sy->gc.attr &= ~value;
|
||||||
} else {
|
} else {
|
||||||
if ((value = attributes_fromstring(tmp)) == -1)
|
if ((value = attributes_fromstring(tmp)) == -1)
|
||||||
goto error;
|
goto error;
|
||||||
attr |= value;
|
sy->gc.attr |= value;
|
||||||
}
|
}
|
||||||
|
|
||||||
in += end + strspn(in + end, delimiters);
|
in += end + strspn(in + end, delimiters);
|
||||||
} while (*in != '\0');
|
} while (*in != '\0');
|
||||||
|
|
||||||
sy->gc.fg = fg;
|
|
||||||
sy->gc.bg = bg;
|
|
||||||
sy->gc.attr = attr;
|
|
||||||
sy->gc.flags = flags;
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@ -122,18 +117,18 @@ style_tostring(struct style *sy)
|
|||||||
*s = '\0';
|
*s = '\0';
|
||||||
|
|
||||||
if (gc->fg != 8) {
|
if (gc->fg != 8) {
|
||||||
off += xsnprintf(s + off, sizeof s - off, "%sfg=%s",
|
off += xsnprintf(s + off, sizeof s - off, "%sfg=%s", comma,
|
||||||
comma, colour_tostring(gc->fg));
|
colour_tostring(gc->fg));
|
||||||
comma = ",";
|
comma = ",";
|
||||||
}
|
}
|
||||||
if (gc->bg != 8) {
|
if (gc->bg != 8) {
|
||||||
off += xsnprintf(s + off, sizeof s - off, "%sbg=%s",
|
off += xsnprintf(s + off, sizeof s - off, "%sbg=%s", comma,
|
||||||
comma, colour_tostring(gc->bg));
|
colour_tostring(gc->bg));
|
||||||
comma = ",";
|
comma = ",";
|
||||||
}
|
}
|
||||||
if (gc->attr != 0 && gc->attr != GRID_ATTR_CHARSET) {
|
if (gc->attr != 0 && gc->attr != GRID_ATTR_CHARSET) {
|
||||||
xsnprintf(s + off, sizeof s - off, "%s%s",
|
xsnprintf(s + off, sizeof s - off, "%s%s", comma,
|
||||||
comma, attributes_tostring(gc->attr));
|
attributes_tostring(gc->attr));
|
||||||
comma = ",";
|
comma = ",";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +169,7 @@ style_apply_update(struct grid_cell *gc, struct options *oo, const char *name)
|
|||||||
void
|
void
|
||||||
style_set(struct style *sy, const struct grid_cell *gc)
|
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);
|
memcpy(&sy->gc, gc, sizeof sy->gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user