aboutsummaryrefslogtreecommitdiffstats
path: root/colorize.c
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org> 2013-07-03 23:40:37 +0200
committerGravatar Steven Schubiger <stsc@refcnt.org> 2013-07-03 23:40:37 +0200
commitbc00d671241fb5509b81a13efdf50cae616610d0 (patch)
tree834a17bc1a8199d93acb5d958ebe0ff0f9cad979 /colorize.c
parent84ac1076aa25a687ddcaf3036ceeb0da6b5730dc (diff)
downloadcolorize-bc00d671241fb5509b81a13efdf50cae616610d0.tar.gz
colorize-bc00d671241fb5509b81a13efdf50cae616610d0.tar.bz2
Clean sequences more strictly
Diffstat (limited to 'colorize.c')
-rw-r--r--colorize.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/colorize.c b/colorize.c
index c402a01..02190f9 100644
--- a/colorize.c
+++ b/colorize.c
@@ -824,13 +824,13 @@ print_clean (const char *line)
}
else if (clean)
{
- bool check_values, first = true;
- if (!isdigit (*p))
- goto END;
+ bool check_values;
+ unsigned int iter = 0;
+ const char *digit;
do {
- const char *digit;
check_values = false;
- if (!first && !isdigit (*p))
+ iter++;
+ if (!isdigit (*p))
goto DISCARD;
digit = p;
while (isdigit (*p))
@@ -847,19 +847,36 @@ print_clean (const char *line)
val[i] = *digit++;
val[i] = '\0';
value = atoi (val);
- if (!((value == 0 || value == 1) /* attributes */
- || (value >= 30 && value <= 37) /* foreground colors */
- || (value >= 40 && value <= 47) /* background colors */
- || (value == 39 || value == 49))) /* default colors */
+ if (value == 0) /* reset */
+ {
+ if (iter > 1)
+ goto DISCARD;
+ goto END;
+ }
+ else if (value == 1) /* bold */
+ {
+ bool discard = false;
+ if (iter > 1)
+ discard = true;
+ else if (*p != ';')
+ discard = true;
+ if (discard)
+ goto DISCARD;
+ p++;
+ check_values = true;
+ }
+ else if ((value >= 30 && value <= 37) || value == 39) /* foreground colors */
+ goto END;
+ else if ((value >= 40 && value <= 47) || value == 49) /* background colors */
+ {
+ if (iter > 1)
+ goto DISCARD;
+ goto END;
+ }
+ else
goto DISCARD;
}
- if (*p == ';')
- {
- p++;
- check_values = true;
- }
- first = false;
- } while (check_values);
+ } while (iter == 1 && check_values);
}
END: if (*p == 'm')
{