version 1.7, 2017/03/22 07:16:54 |
version 1.8, 2018/10/18 07:57:57 |
|
|
const char * |
const char * |
attributes_tostring(int attr) |
attributes_tostring(int attr) |
{ |
{ |
static char buf[128]; |
static char buf[512]; |
size_t len; |
size_t len; |
|
|
if (attr == 0) |
if (attr == 0) |
return ("none"); |
return ("none"); |
|
|
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s", |
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s", |
(attr & GRID_ATTR_BRIGHT) ? "bright," : "", |
(attr & GRID_ATTR_BRIGHT) ? "bright," : "", |
(attr & GRID_ATTR_DIM) ? "dim," : "", |
(attr & GRID_ATTR_DIM) ? "dim," : "", |
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "", |
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "", |
|
|
(attr & GRID_ATTR_REVERSE) ? "reverse," : "", |
(attr & GRID_ATTR_REVERSE) ? "reverse," : "", |
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "", |
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "", |
(attr & GRID_ATTR_ITALICS) ? "italics," : "", |
(attr & GRID_ATTR_ITALICS) ? "italics," : "", |
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : ""); |
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "", |
|
(attr & GRID_ATTR_UNDERSCORE_2) ? "double-underscore," : "", |
|
(attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "", |
|
(attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "", |
|
(attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : ""); |
if (len > 0) |
if (len > 0) |
buf[len - 1] = '\0'; |
buf[len - 1] = '\0'; |
|
|
|
|
const char delimiters[] = " ,|"; |
const char delimiters[] = " ,|"; |
int attr; |
int attr; |
size_t end; |
size_t end; |
|
u_int i; |
|
struct { |
|
const char* name; |
|
int attr; |
|
} table[] = { |
|
{ "bright", GRID_ATTR_BRIGHT }, |
|
{ "bold", GRID_ATTR_BRIGHT }, |
|
{ "dim", GRID_ATTR_DIM }, |
|
{ "underscore", GRID_ATTR_UNDERSCORE }, |
|
{ "blink", GRID_ATTR_BLINK }, |
|
{ "reverse", GRID_ATTR_REVERSE }, |
|
{ "hidden", GRID_ATTR_HIDDEN }, |
|
{ "italics", GRID_ATTR_ITALICS }, |
|
{ "strikethrough", GRID_ATTR_STRIKETHROUGH }, |
|
{ "double-underscore", GRID_ATTR_UNDERSCORE_2 }, |
|
{ "curly-underscore", GRID_ATTR_UNDERSCORE_3 }, |
|
{ "dotted-underscore", GRID_ATTR_UNDERSCORE_4 }, |
|
{ "dashed-underscore", GRID_ATTR_UNDERSCORE_5 } |
|
}; |
|
|
if (*str == '\0' || strcspn(str, delimiters) == 0) |
if (*str == '\0' || strcspn(str, delimiters) == 0) |
return (-1); |
return (-1); |
|
|
attr = 0; |
attr = 0; |
do { |
do { |
end = strcspn(str, delimiters); |
end = strcspn(str, delimiters); |
if ((end == 6 && strncasecmp(str, "bright", end) == 0) || |
for (i = 0; i < nitems(table); i++) { |
(end == 4 && strncasecmp(str, "bold", end) == 0)) |
if (end != strlen(table[i].name)) |
attr |= GRID_ATTR_BRIGHT; |
continue; |
else if (end == 3 && strncasecmp(str, "dim", end) == 0) |
if (strncasecmp(str, table[i].name, end) == 0) { |
attr |= GRID_ATTR_DIM; |
attr |= table[i].attr; |
else if (end == 10 && strncasecmp(str, "underscore", end) == 0) |
break; |
attr |= GRID_ATTR_UNDERSCORE; |
} |
else if (end == 5 && strncasecmp(str, "blink", end) == 0) |
} |
attr |= GRID_ATTR_BLINK; |
if (i == nitems(table)) |
else if (end == 7 && strncasecmp(str, "reverse", end) == 0) |
|
attr |= GRID_ATTR_REVERSE; |
|
else if (end == 6 && strncasecmp(str, "hidden", end) == 0) |
|
attr |= GRID_ATTR_HIDDEN; |
|
else if (end == 7 && strncasecmp(str, "italics", end) == 0) |
|
attr |= GRID_ATTR_ITALICS; |
|
else if (end == 13 && strncasecmp(str, "strikethrough", end) == 0) |
|
attr |= GRID_ATTR_STRIKETHROUGH; |
|
else |
|
return (-1); |
return (-1); |
str += end + strspn(str + end, delimiters); |
str += end + strspn(str + end, delimiters); |
} while (*str != '\0'); |
} while (*str != '\0'); |