From fdc0b3f67a323054ee214769215158d3da8cafb5 Mon Sep 17 00:00:00 2001 From: <> Date: Sat, 18 Mar 2017 20:23:17 -0700 Subject: [PATCH] Fixed bug of visible color code that does not have text to color. --- includes/colors.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/includes/colors.c b/includes/colors.c index 580e95a..519c5e2 100644 --- a/includes/colors.c +++ b/includes/colors.c @@ -2,9 +2,8 @@ #include #include #include +#include #include "colors.h" -#define ASCII_ZERO 48 -#define ASCII_NINE 57 #define MIN_CONTRAST 0.5 void hsl2rgb(struct Rgb *dest, const struct Hls const *src) { @@ -134,24 +133,30 @@ static void hexspan(const char *str) { } static void b(char * const str) { -#define IS_DIGIT(x) (x >= ASCII_ZERO && x <= ASCII_NINE) char *token = strtok(str, "^"); char c; printf(""); while (token) { c = token[0]; - if (IS_DIGIT(c)) { + if (isdigit(c)) { decspan(c - ASCII_ZERO); - printf("%s", token + 1); - } else if (c == 'x' && strlen(token) > 4) { - hexspan(token + 1); //exclude x - printf("%s", token + 4); + if (strlen(token) > 1) { + printf("%s", token + 1); + } + } else if (c == 'x' && strlen(token) > 3) { + if (isxdigit(token[1]) && isxdigit(token[2]) && isxdigit(token[3])) { + hexspan(token + 1); //exclude x + if (strlen(token) > 4){ + printf("%s", token + 4); + } + printf(""); + } } else { printf("%s", token); } token = strtok(NULL, "^"); } - printf(""); + printf(""); } void print_plname(const char* str) {