diff options
Diffstat (limited to 'i3status.c')
-rw-r--r-- | i3status.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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"); |