diff options
Diffstat (limited to 'src/location-manual.c')
-rw-r--r-- | src/location-manual.c | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/src/location-manual.c b/src/location-manual.c index c5da074..db3a8a9 100644 --- a/src/location-manual.c +++ b/src/location-manual.c @@ -14,9 +14,13 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2017 Jon Lund Steffensen <jonlst@gmail.com> */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include <stdio.h> #include <stdlib.h> #include <math.h> @@ -33,16 +37,25 @@ #endif -int -location_manual_init(location_manual_state_t *state) +typedef struct { + location_t loc; +} location_manual_state_t; + + +static int +location_manual_init(location_manual_state_t **state) { - state->loc.lat = NAN; - state->loc.lon = NAN; + *state = malloc(sizeof(location_manual_state_t)); + if (*state == NULL) return -1; + + location_manual_state_t *s = *state; + s->loc.lat = NAN; + s->loc.lon = NAN; return 0; } -int +static int location_manual_start(location_manual_state_t *state) { /* Latitude and longitude must be set */ @@ -54,12 +67,13 @@ location_manual_start(location_manual_state_t *state) return 0; } -void +static void location_manual_free(location_manual_state_t *state) { + free(state); } -void +static void location_manual_print_help(FILE *f) { fputs(_("Specify location manually.\n"), f); @@ -75,7 +89,7 @@ location_manual_print_help(FILE *f) fputs("\n", f); } -int +static int location_manual_set_option(location_manual_state_t *state, const char *key, const char *value) { @@ -100,11 +114,30 @@ location_manual_set_option(location_manual_state_t *state, const char *key, return 0; } -int -location_manual_get_location(location_manual_state_t *state, - location_t *loc) +static int +location_manual_get_fd(location_manual_state_t *state) { - *loc = state->loc; + return -1; +} + +static int +location_manual_handle( + location_manual_state_t *state, location_t *location, int *available) +{ + *location = state->loc; + *available = 1; return 0; } + + +const location_provider_t manual_location_provider = { + "manual", + (location_provider_init_func *)location_manual_init, + (location_provider_start_func *)location_manual_start, + (location_provider_free_func *)location_manual_free, + (location_provider_print_help_func *)location_manual_print_help, + (location_provider_set_option_func *)location_manual_set_option, + (location_provider_get_fd_func *)location_manual_get_fd, + (location_provider_handle_func *)location_manual_handle +}; |