12 {"black", CLR_RGB(0, 0, 0)},
13 {"red", CLR_RGB(0xff, 0, 0)},
14 {"green", CLR_RGB(0, 0xff, 0)},
15 {"yellow", CLR_RGB(0xff, 0xff, 0)},
16 {"blue", CLR_RGB(0, 0, 0xff)},
17 {"magenta", CLR_RGB(0xff, 0, 0xff)},
18 {"cyan", CLR_RGB(0, 0xff, 0xff)},
19 {"white", CLR_RGB(0xff, 0xff, 0xff)},
22 /* returns a static buffer */
25 static char clr_buf
[32];
28 sprintf(clr_buf
, "#%02x%02x%02x", CLR_R(c
), CLR_G(c
), CLR_B(c
));
32 /* read color component */
33 static int ccom(char *s
, int len
)
35 static char *digs
= "0123456789abcdef";
38 for (i
= 0; i
< len
; i
++)
39 if (strchr(digs
, tolower(s
[i
])))
40 n
= n
* 16 + (strchr(digs
, tolower(s
[i
])) - digs
);
41 return len
== 1 ? n
<< 4 : n
;
47 if (s
[0] == '#' && strlen(s
) == 7)
48 return CLR_RGB(ccom(s
+ 1, 2), ccom(s
+ 3, 2), ccom(s
+ 5, 2));
49 if (s
[0] == '#' && strlen(s
) == 4)
50 return CLR_RGB(ccom(s
+ 1, 1), ccom(s
+ 2, 1), ccom(s
+ 3, 1));
51 if (s
[0] == '#' && strlen(s
) == 3)
52 return CLR_RGB(ccom(s
+ 1, 2), ccom(s
+ 1, 2), ccom(s
+ 1, 2));
53 if (s
[0] == '#' && strlen(s
) == 2)
54 return CLR_RGB(ccom(s
+ 1, 1), ccom(s
+ 1, 1), ccom(s
+ 1, 1));
55 if (isdigit(s
[0]) && atoi(s
) >= 0 && atoi(s
) < LEN(colors
))
56 return colors
[atoi(s
)].value
;
57 for (i
= 0; i
< LEN(colors
); i
++)
58 if (!strcmp(colors
[i
].name
, s
))
59 return colors
[i
].value
;