#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
+#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
return buff;
}
+char *invert_color(const char *color)
+{
+ char c;
+ static char inverted[8];
+
+ strcpy(inverted, color);
+ for (int i = 1; i < 7; i++)
+ {
+ c = color[i];
+ inverted[i] = (c < 'a') ?
+ "0123456789ABCDEF"[15 - (c - '0' - (c > '9' ? 7 : 0))] :
+ "0123456789abcdef"[15 - (c - 'a')];
+ }
+
+ inverted[7] = '\0';
+ return inverted;
+}
+
int get_max_len(char *string, XftFont *font, int max_text_width)
{
int eol = strlen(string);
int main(int argc, char *argv[])
{
- int nargc = 0;
+ int nargc = 0, rstatus;
+ regex_t regex;
+ regmatch_t match;
char **nargv = NULL;
char *body = NULL, *bptr;
+ const char *pattern = "#[a-fA-F0-9]{6}";
if (!isatty(STDIN_FILENO))
{
struct sigaction act_expire, act_ignore;
+ if ((rstatus = regcomp(®ex, pattern, REG_EXTENDED)))
+ die("%s: regex compilation failed", argv[0]);
+
+ if (!(rstatus = regexec(®ex, argv[1], 1, &match, 0)))
+ {
+ background_color = argv[1];
+ font_color = invert_color(argv[1]);
+ border_color = font_color;
+ }
+
act_expire.sa_handler = expire;
act_expire.sa_flags = SA_RESTART;
sigemptyset(&act_expire.sa_mask);
if (body)
free(body);
free(lines);
+ regfree(®ex);
XftDrawDestroy(draw);
XftColorFree(display, visual, colormap, &color);
XftFontClose(display, font);