aboutsummaryrefslogtreecommitdiffstats
path: root/src/location-manual.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-03-21 16:50:15 +0100
committerMattias Andrée <m@maandree.se>2025-03-21 16:50:15 +0100
commit96a6575e23b5baebcdd38269b80f47cc02a2627e (patch)
tree0561580306c882e0e7a4f76c542130bb7ee44537 /src/location-manual.c
parentRefactor (diff)
downloadredshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.gz
redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.bz2
redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.xz
Refactor
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/location-manual.c')
-rw-r--r--src/location-manual.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/location-manual.c b/src/location-manual.c
index a394f29..d1285f1 100644
--- a/src/location-manual.c
+++ b/src/location-manual.c
@@ -1,4 +1,5 @@
-/* redshift-ng - Automatically adjust display colour temperature according the Sun
+/*-
+ * redshift-ng - Automatically adjust display colour temperature according the Sun
*
* Copyright (c) 2009-2018 Jon Lund Steffensen <jonlst@gmail.com>
* Copyright (c) 2014-2016, 2025 Mattias Andrée <m@maandree.se>
@@ -20,7 +21,10 @@
struct location_state {
- struct location loc;
+ /**
+ * The specified location, any unspecified coordinate is set to NAN
+ */
+ struct location location;
};
@@ -28,34 +32,36 @@ static int
manual_create(struct location_state **state_out)
{
*state_out = emalloc(sizeof(**state_out));
- (*state_out)->loc.latitude = NAN;
- (*state_out)->loc.longitude = NAN;
+ (*state_out)->location.latitude = FNAN;
+ (*state_out)->location.longitude = FNAN;
return 0;
}
+
GCC_ONLY(__attribute__((__pure__)))
static int
manual_start(struct location_state *state)
{
- if (isnan(state->loc.latitude) || isnan(state->loc.longitude))
+ if (isnan(state->location.latitude) || isnan(state->location.longitude))
eprintf(_("Latitude and longitude must be set."));
return 0;
}
+
static void
manual_free(struct location_state *state)
{
free(state);
}
+
static void
manual_print_help(FILE *f)
{
fputs(_("Specify location manually.\n"), f);
fputs("\n", f);
- /* TRANSLATORS: Manual location help output
- left column must not be translated */
+ /* TRANSLATORS: Manual location help output left column must not be translated */
fputs(_(" lat=N\t\tLatitude\n"
" lon=N\t\tLongitude\n"), f);
fputs("\n", f);
@@ -64,10 +70,10 @@ manual_print_help(FILE *f)
fputs("\n", f);
}
+
static int
manual_set_option(struct location_state *state, const char *key, const char *value)
{
- /* Parse float value */
char *end;
double v;
@@ -79,9 +85,9 @@ manual_set_option(struct location_state *state, const char *key, const char *val
}
if (!strcasecmp(key, "lat")) {
- state->loc.latitude = v;
+ state->location.latitude = v;
} else if (!strcasecmp(key, "lon")) {
- state->loc.longitude = v;
+ state->location.longitude = v;
} else {
weprintf(_("Unknown method parameter: `%s'."), key);
return -1;
@@ -90,6 +96,7 @@ manual_set_option(struct location_state *state, const char *key, const char *val
return 0;
}
+
static int
manual_get_fd(struct location_state *state)
{
@@ -97,10 +104,11 @@ manual_get_fd(struct location_state *state)
return -1;
}
+
static int
manual_fetch(struct location_state *state, struct location *location_out, int *available_out)
{
- *location_out = state->loc;
+ *location_out = state->location;
*available_out = 1;
return 0;
}