aboutsummaryrefslogtreecommitdiffstats
path: root/src/options.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/options.c')
-rw-r--r--src/options.c72
1 files changed, 27 insertions, 45 deletions
diff --git a/src/options.c b/src/options.c
index 28c9149..dc38e2a 100644
--- a/src/options.c
+++ b/src/options.c
@@ -16,24 +16,6 @@
Copyright (c) 2017 Jon Lund Steffensen <jonlst@gmail.com>
*/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <math.h>
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(s) gettext(s)
-#else
-# define _(s) s
-#endif
-
#include "common.h"
#include "config-ini.h"
#include "options.h"
@@ -123,7 +105,7 @@ parse_transition_time(const char *str, const char **end)
failure, otherwise zero. Parsed start and end times are returned as seconds
since midnight. */
static int
-parse_transition_range(const char *str, time_range_t *range)
+parse_transition_range(const char *str, struct time_range *range)
{
const char *next = NULL;
int start_time = parse_transition_time(str, &next);
@@ -217,7 +199,7 @@ print_help(const char *program_name)
/* Print list of adjustment methods. */
static void
-print_method_list(const gamma_method_t *gamma_methods)
+print_method_list(const struct gamma_method *gamma_methods)
{
fputs(_("Available adjustment methods:\n"), stdout);
for (int i = 0; gamma_methods[i].name != NULL; i++) {
@@ -233,7 +215,7 @@ print_method_list(const gamma_method_t *gamma_methods)
/* Print list of location providers. */
static void
-print_provider_list(const location_provider_t location_providers[])
+print_provider_list(const struct location_provider location_providers[])
{
fputs(_("Available location providers:\n"), stdout);
for (int i = 0; location_providers[i].name != NULL; i++) {
@@ -248,12 +230,12 @@ print_provider_list(const location_provider_t location_providers[])
}
/* Return the gamma method with the given name. */
-static const gamma_method_t *
-find_gamma_method(const gamma_method_t gamma_methods[], const char *name)
+static const struct gamma_method *
+find_gamma_method(const struct gamma_method gamma_methods[], const char *name)
{
- const gamma_method_t *method = NULL;
+ const struct gamma_method *method = NULL;
for (int i = 0; gamma_methods[i].name != NULL; i++) {
- const gamma_method_t *m = &gamma_methods[i];
+ const struct gamma_method *m = &gamma_methods[i];
if (strcasecmp(name, m->name) == 0) {
method = m;
break;
@@ -264,13 +246,13 @@ find_gamma_method(const gamma_method_t gamma_methods[], const char *name)
}
/* Return location provider with the given name. */
-static const location_provider_t *
+static const struct location_provider *
find_location_provider(
- const location_provider_t location_providers[], const char *name)
+ const struct location_provider location_providers[], const char *name)
{
- const location_provider_t *provider = NULL;
+ const struct location_provider *provider = NULL;
for (int i = 0; location_providers[i].name != NULL; i++) {
- const location_provider_t *p = &location_providers[i];
+ const struct location_provider *p = &location_providers[i];
if (strcasecmp(name, p->name) == 0) {
provider = p;
break;
@@ -283,7 +265,7 @@ find_location_provider(
/* Initialize options struct. */
void
-options_init(options_t *options)
+options_init(struct options *options)
{
options->config_filepath = NULL;
@@ -325,9 +307,9 @@ options_init(options_t *options)
/* Parse a single option from the command-line. */
static int
parse_command_line_option(
- const char option, char *value, options_t *options,
- const char *program_name, const gamma_method_t *gamma_methods,
- const location_provider_t *location_providers)
+ const char option, char *value, struct options *options,
+ const char *program_name, const struct gamma_method *gamma_methods,
+ const struct location_provider *location_providers)
{
int r;
char *s;
@@ -486,9 +468,9 @@ parse_command_line_option(
/* Parse command line arguments. */
void
options_parse_args(
- options_t *options, int argc, char *argv[],
- const gamma_method_t *gamma_methods,
- const location_provider_t *location_providers)
+ struct options *options, int argc, char *argv[],
+ const struct gamma_method *gamma_methods,
+ const struct location_provider *location_providers)
{
const char* program_name = argv[0];
int opt;
@@ -504,9 +486,9 @@ options_parse_args(
/* Parse a single key-value pair from the configuration file. */
static int
parse_config_file_option(
- const char *key, const char *value, options_t *options,
- const gamma_method_t *gamma_methods,
- const location_provider_t *location_providers)
+ const char *key, const char *value, struct options *options,
+ const struct gamma_method *gamma_methods,
+ const struct location_provider *location_providers)
{
if (strcasecmp(key, "temp-day") == 0) {
if (options->scheme.day.temperature < 0) {
@@ -627,16 +609,16 @@ parse_config_file_option(
/* Parse options defined in the config file. */
void
options_parse_config_file(
- options_t *options, config_ini_state_t *config_state,
- const gamma_method_t *gamma_methods,
- const location_provider_t *location_providers)
+ struct options *options, struct config_ini_state *config_state,
+ const struct gamma_method *gamma_methods,
+ const struct location_provider *location_providers)
{
/* Read global config settings. */
- config_ini_section_t *section = config_ini_get_section(
+ struct config_ini_section *section = config_ini_get_section(
config_state, "redshift");
if (section == NULL) return;
- config_ini_setting_t *setting = section->settings;
+ struct config_ini_setting *setting = section->settings;
while (setting != NULL) {
int r = parse_config_file_option(
setting->name, setting->value, options,
@@ -649,7 +631,7 @@ options_parse_config_file(
/* Replace unspecified options with default values. */
void
-options_set_defaults(options_t *options)
+options_set_defaults(struct options *options)
{
if (options->scheme.day.temperature < 0) {
options->scheme.day.temperature = DEFAULT_DAY_TEMP;