Merge branch 'pm/build-persistent-https-with-recent-go'
[gitweb.git] / color.c
diff --git a/color.c b/color.c
index 8f85153d0d2c1f4bf9340ced9371797eb3c92de9..81c26767239f9e028057c1843f57b77640db6c26 100644 (file)
--- a/color.c
+++ b/color.c
@@ -123,19 +123,34 @@ static int parse_color(struct color *out, const char *name, int len)
        return -1;
 }
 
-static int parse_attr(const char *name, int len)
+static int parse_attr(const char *name, size_t len)
 {
-       static const int attr_values[] = { 1, 2, 4, 5, 7,
-                                          22, 22, 24, 25, 27 };
-       static const char * const attr_names[] = {
-               "bold", "dim", "ul", "blink", "reverse",
-               "nobold", "nodim", "noul", "noblink", "noreverse"
+       static const struct {
+               const char *name;
+               size_t len;
+               int val, neg;
+       } attrs[] = {
+#define ATTR(x, val, neg) { (x), sizeof(x)-1, (val), (neg) }
+               ATTR("bold",      1, 22),
+               ATTR("dim",       2, 22),
+               ATTR("italic",    3, 23),
+               ATTR("ul",        4, 24),
+               ATTR("blink",     5, 25),
+               ATTR("reverse",   7, 27),
+               ATTR("strike",    9, 29)
+#undef ATTR
        };
+       int negate = 0;
        int i;
-       for (i = 0; i < ARRAY_SIZE(attr_names); i++) {
-               const char *str = attr_names[i];
-               if (!strncasecmp(name, str, len) && !str[len])
-                       return attr_values[i];
+
+       if (skip_prefix_mem(name, len, "no", &name, &len)) {
+               skip_prefix_mem(name, len, "-", &name, &len);
+               negate = 1;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(attrs); i++) {
+               if (attrs[i].len == len && !memcmp(attrs[i].name, name, len))
+                       return negate ? attrs[i].neg : attrs[i].val;
        }
        return -1;
 }