7 /* returns a static buffer */
10 static char clr_buf
[32];
13 sprintf(clr_buf
, "#%02x%02x%02x", CLR_R(c
), CLR_G(c
), CLR_B(c
));
21 {"black", CLR_RGB(0, 0, 0)},
22 {"red", CLR_RGB(0xff, 0, 0)},
23 {"green", CLR_RGB(0, 0xff, 0)},
24 {"yellow", CLR_RGB(0xff, 0xff, 0)},
25 {"blue", CLR_RGB(0, 0, 0xff)},
26 {"magenta", CLR_RGB(0xff, 0, 0xff)},
27 {"cyan", CLR_RGB(0, 0xff, 0xff)},
28 {"white", CLR_RGB(0xff, 0xff, 0xff)},
31 /* read color component */
32 static int clrcomp(char *s
, int len
)
34 static char *digs
= "0123456789abcdef";
37 for (i
= 0; i
< len
; i
++)
38 if (strchr(digs
, tolower(s
[i
])))
39 n
= n
* 16 + (strchr(digs
, tolower(s
[i
])) - digs
);
40 return len
== 1 ? n
* 255 / 15 : n
;
46 if (s
[0] == '#' && strlen(s
) == 7)
47 return CLR_RGB(clrcomp(s
+ 1, 2), clrcomp(s
+ 3, 2), clrcomp(s
+ 5, 2));
48 if (s
[0] == '#' && strlen(s
) == 4)
49 return CLR_RGB(clrcomp(s
+ 1, 1), clrcomp(s
+ 2, 1), clrcomp(s
+ 3, 1));
50 if (isdigit(s
[0]) && atoi(s
) >= 0 && atoi(s
) < LEN(colors
))
51 return colors
[atoi(s
)].value
;
52 for (i
= 0; i
< LEN(colors
); i
++)
53 if (!strcmp(colors
[i
].name
, s
))
54 return colors
[i
].value
;