diff options
Diffstat (limited to 'src/options.c')
-rw-r--r-- | src/options.c | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/src/options.c b/src/options.c index 5e4ba4e..725599e 100644 --- a/src/options.c +++ b/src/options.c @@ -36,17 +36,15 @@ /* A brightness string contains either one floating point value, or two values separated by a colon. */ static void -parse_brightness_string( - const char *str, double *bright_day, double *bright_night) +parse_brightness_string(const char *str, double *bright_day, double *bright_night) { char *s = strchr(str, ':'); - if (s == NULL) { - /* Same value for day and night. */ - *bright_day = *bright_night = atof(str); - } else { - *(s++) = '\0'; + if (s) { + *s++ = '\0'; *bright_day = atof(str); *bright_night = atof(s); + } else { + *bright_day = *bright_night = atof(str); } } @@ -56,7 +54,7 @@ static int parse_gamma_string(const char *str, double gamma[3]) { char *s = strchr(str, ':'); - if (s == NULL) { + if (!s) { /* Use value for all channels */ double g = atof(str); gamma[0] = gamma[1] = gamma[2] = g; @@ -66,7 +64,8 @@ parse_gamma_string(const char *str, double gamma[3]) *s++ = '\0'; g_s = s; s = strchr(s, ':'); - if (s == NULL) return -1; + if (!s) + return -1; *(s++) = '\0'; gamma[0] = atof(str); /* Red */ @@ -87,8 +86,7 @@ parse_transition_time(const char *str, const char **end) errno = 0; hours = strtol(str, (void *)&min, 10); - if (errno != 0 || min == str || min[0] != ':' || - hours < 0 || hours >= 24) { + if (errno != 0 || min == str || min[0] != ':' || hours < 0 || hours >= 24) { return -1; } @@ -121,7 +119,8 @@ parse_transition_range(const char *str, struct time_range *range) const char *end = NULL; next += 1; end_time = parse_transition_time(next, &end); - if (end_time < 0 || end[0] != '\0') return -1; + if (end_time < 0 || end[0] != '\0') + return -1; } else { return -1; } @@ -475,14 +474,12 @@ options_parse_args( const struct gamma_method *gamma_methods, const struct location_provider *location_providers) { - const char* program_name = argv[0]; - int opt; + int r, opt; while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:pPrt:vVx")) != -1) { - char option = opt; - int r = parse_command_line_option( - option, optarg, options, program_name, gamma_methods, - location_providers); - if (r < 0) exit(EXIT_FAILURE); + r = parse_command_line_option(opt, optarg, options, argv0, + gamma_methods, location_providers); + if (r < 0) + exit(EXIT_FAILURE); } } @@ -611,26 +608,23 @@ parse_config_file_option( /* Parse options defined in the config file. */ void -options_parse_config_file( - struct options *options, struct config_ini_state *config_state, - const struct gamma_method *gamma_methods, - const struct location_provider *location_providers) +options_parse_config_file(struct options *options, struct config_ini_state *config_state, + const struct gamma_method *gamma_methods, + const struct location_provider *location_providers) { struct config_ini_section *section; struct config_ini_setting *setting; /* Read global config settings. */ section = config_ini_get_section(config_state, "redshift"); - if (section == NULL) return; - - setting = section->settings; - while (setting != NULL) { - int r = parse_config_file_option( - setting->name, setting->value, options, - gamma_methods, location_providers); - if (r < 0) exit(EXIT_FAILURE); - - setting = setting->next; + if (!section) + return; + + for (setting = section->settings; setting; setting = setting->next) { + int r = parse_config_file_option(setting->name, setting->value, options, + gamma_methods, location_providers); + if (r < 0) + exit(EXIT_FAILURE); } } @@ -638,19 +632,15 @@ options_parse_config_file( void options_set_defaults(struct options *options) { - if (options->scheme.day.temperature < 0) { + if (options->scheme.day.temperature < 0) options->scheme.day.temperature = DEFAULT_DAY_TEMP; - } - if (options->scheme.night.temperature < 0) { + if (options->scheme.night.temperature < 0) options->scheme.night.temperature = DEFAULT_NIGHT_TEMP; - } - if (isnan(options->scheme.day.brightness)) { + if (isnan(options->scheme.day.brightness)) options->scheme.day.brightness = DEFAULT_BRIGHTNESS; - } - if (isnan(options->scheme.night.brightness)) { + if (isnan(options->scheme.night.brightness)) options->scheme.night.brightness = DEFAULT_BRIGHTNESS; - } if (isnan(options->scheme.day.gamma[0])) { options->scheme.day.gamma[0] = DEFAULT_GAMMA; @@ -663,5 +653,6 @@ options_set_defaults(struct options *options) options->scheme.night.gamma[2] = DEFAULT_GAMMA; } - if (options->use_fade < 0) options->use_fade = 1; + if (options->use_fade < 0) + options->use_fade = 1; } |