The branch, master has been updated
       via  b8aec17af16ca557a3069a475d31a90d2925fe11 (commit)
       via  568f5ef3c6263004c5f6f1278346e18c66d02be3 (commit)
      from  f4196138cefe01df9aed085a7534dc30f45999e8 (commit)

- Log -----------------------------------------------------------------
commit b8aec17af16ca557a3069a475d31a90d2925fe11
Merge: f419613 568f5ef
Author: Thomas Adam <tho...@xteddy.org>
Commit: Thomas Adam <tho...@xteddy.org>

    Merge branch 'obsd-master'

 options.c |   18 ++++++++++++------
 style.c   |   26 ++++++++++++++++----------
 2 files changed, 28 insertions(+), 16 deletions(-)


commit 568f5ef3c6263004c5f6f1278346e18c66d02be3
Author: nicm <nicm>
Commit: nicm <nicm>

    When given an invalid style, don't set the option to the default. Fix
    from J Raynor. Also make style_parse not alter the grid_cell when it
    fails.
---
 options.c |   18 ++++++++++++------
 style.c   |   26 ++++++++++++++++----------
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/options.c b/options.c
index 67f8abd..030cfd5 100644
--- a/options.c
+++ b/options.c
@@ -167,20 +167,26 @@ options_set_style(struct options *oo, const char *name, 
const char *value,
     int append)
 {
        struct options_entry    *o;
+       struct grid_cell         tmpgc;
 
-       if ((o = options_find1(oo, name)) == NULL) {
+       o = options_find1(oo, name);
+       if (o == NULL || !append)
+               memcpy(&tmpgc, &grid_default_cell, sizeof tmpgc);
+       else
+               memcpy(&tmpgc, &o->style, sizeof tmpgc);
+
+       if (style_parse(&grid_default_cell, &tmpgc, value) == -1)
+               return (NULL);
+
+       if (o == NULL) {
                o = xmalloc(sizeof *o);
                o->name = xstrdup(name);
                RB_INSERT(options_tree, &oo->tree, o);
        } else if (o->type == OPTIONS_STRING)
                free(o->str);
 
-       if (!append)
-               memcpy(&o->style, &grid_default_cell, sizeof o->style);
-
        o->type = OPTIONS_STYLE;
-       if (style_parse(&grid_default_cell, &o->style, value) == -1)
-               return (NULL);
+       memcpy(&o->style, &tmpgc, sizeof o->style);
        return (o);
 }
 
diff --git a/style.c b/style.c
index 6df2ed0..d8ab07a 100644
--- a/style.c
+++ b/style.c
@@ -28,16 +28,18 @@ int
 style_parse(const struct grid_cell *defgc, struct grid_cell *gc,
     const char *in)
 {
-       const char      delimiters[] = " ,";
-       char            tmp[32];
-       int             val;
-       size_t          end;
-       u_char          fg, bg, attr, flags;
+       struct grid_cell        savedgc;
+       const char              delimiters[] = " ,";
+       char                    tmp[32];
+       int                     val;
+       size_t                  end;
+       u_char                  fg, bg, attr, flags;
 
        if (*in == '\0')
                return (0);
        if (strchr(delimiters, in[strlen(in) - 1]) != NULL)
                return (-1);
+       memcpy(&savedgc, gc, sizeof savedgc);
 
        fg = gc->fg;
        bg = gc->bg;
@@ -46,7 +48,7 @@ style_parse(const struct grid_cell *defgc, struct grid_cell 
*gc,
        do {
                end = strcspn(in, delimiters);
                if (end > (sizeof tmp) - 1)
-                       return (-1);
+                       goto error;
                memcpy(tmp, in, end);
                tmp[end] = '\0';
 
@@ -59,7 +61,7 @@ style_parse(const struct grid_cell *defgc, struct grid_cell 
*gc,
                            defgc->flags & (GRID_FLAG_FG256|GRID_FLAG_BG256);
                } else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
                        if ((val = colour_fromstring(tmp + 3)) == -1)
-                               return (-1);
+                               goto error;
                        if (*in == 'f' || *in == 'F') {
                                if (val != 8) {
                                        if (val & 0x100) {
@@ -87,16 +89,16 @@ style_parse(const struct grid_cell *defgc, struct grid_cell 
*gc,
                                        flags |= defgc->flags & GRID_FLAG_BG256;
                                }
                        } else
-                               return (-1);
+                               goto error;
                } else if (strcasecmp(tmp, "none") == 0)
                        attr = 0;
                else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
                        if ((val = attributes_fromstring(tmp + 2)) == -1)
-                               return (-1);
+                               goto error;
                        attr &= ~val;
                } else {
                        if ((val = attributes_fromstring(tmp)) == -1)
-                               return (-1);
+                               goto error;
                        attr |= val;
                }
 
@@ -108,6 +110,10 @@ style_parse(const struct grid_cell *defgc, struct 
grid_cell *gc,
        gc->flags = flags;
 
        return (0);
+
+error:
+       memcpy(gc, &savedgc, sizeof *gc);
+       return (-1);
 }
 
 /* Convert style to a string. */


-----------------------------------------------------------------------

Summary of changes:
 options.c |   18 ++++++++++++------
 style.c   |   26 ++++++++++++++++----------
 2 files changed, 28 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to