Fixed bug of visible color code that does not have text to color.

This commit is contained in:
2017-03-18 20:23:17 -07:00
parent 2c26d3a225
commit fdc0b3f67a

View File

@ -2,9 +2,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#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("<TD>");
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("</span>");
}
} else {
printf("%s", token);
}
token = strtok(NULL, "^");
}
printf("</span></TD>");
printf("</TD>");
}
void print_plname(const char* str) {