X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3status.c;h=eabcd6c68cbf79469ca105e0013673da42ad3718;hb=38337511e9b5896006f276c111265c985b2af70d;hp=64fac76997138321866cf87c8c7b708bea705cf6;hpb=9db8f7221afbf2c1dead8c0ef689007f3b0838a9;p=i3%2Fi3status diff --git a/i3status.c b/i3status.c index 64fac76..eabcd6c 100644 --- a/i3status.c +++ b/i3status.c @@ -65,12 +65,33 @@ static char *file_exists(char *path) { return full_path; } +/* + * Validates a color in "#RRGGBB" format + * + */ +static int valid_color(const char *value) +{ + if (strlen(value) != 7) return 0; + if (value[0] != '#') return 0; + for (int i = 1; i < 7; ++i) { + if (value[i] >= '0' && value[i] <= '9') continue; + if (value[i] >= 'a' && value[i] <= 'f') continue; + if (value[i] >= 'A' && value[i] <= 'F') continue; + return 0; + } + return 1; +} + int main(int argc, char *argv[]) { unsigned int j; cfg_opt_t general_opts[] = { CFG_STR("output_format", "dzen2", CFGF_NONE), CFG_BOOL("colors", 1, CFGF_NONE), + CFG_STR("color_good", "#00FF00", CFGF_NONE), + CFG_STR("color_degraded", "#FFFF00", CFGF_NONE), + CFG_STR("color_bad", "#FF0000", CFGF_NONE), + CFG_STR("color_separator", "#333333", CFGF_NONE), CFG_INT("interval", 1, CFGF_NONE), CFG_END() }; @@ -194,6 +215,12 @@ int main(int argc, char *argv[]) { output_format = O_NONE; else die("Unknown output format: \"%s\"\n", output_str); + if (!valid_color(cfg_getstr(cfg_general, "color_good")) + || !valid_color(cfg_getstr(cfg_general, "color_degraded")) + || !valid_color(cfg_getstr(cfg_general, "color_bad")) + || !valid_color(cfg_getstr(cfg_general, "color_separator"))) + die("Bad color format"); + if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) die("Could not create socket\n");