From 7e81521772240ec3567a1773d2919a3e90d104c7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Oct 2008 14:25:45 +0200 Subject: [PATCH] options: don't pass the "options" pointer around Just make everybody use the global "options" variable. This eliminates namespace confusion and the NO_GLOBAL_OPTIONS hack. --- src/conf.c | 83 +++++++++++++++++++++++++-------------------------- src/conf.h | 2 +- src/main.c | 2 +- src/options.c | 10 ++----- src/options.h | 6 ++-- 5 files changed, 48 insertions(+), 55 deletions(-) diff --git a/src/conf.c b/src/conf.c index 4485cda..1630f62 100644 --- a/src/conf.c +++ b/src/conf.c @@ -16,7 +16,6 @@ * */ -#define NO_GLOBAL_OPTIONS #include "conf.h" #include "config.h" #include "defaults.h" @@ -359,7 +358,7 @@ check_screen_list(char *value) } static int -read_rc_file(char *filename, options_t *options) +read_rc_file(char *filename) { int fd; int quit = 0; @@ -441,13 +440,13 @@ read_rc_file(char *filename, options_t *options) /* enable colors */ else if(!strcasecmp(CONF_ENABLE_COLORS, name)) #ifdef ENABLE_COLORS - options->enable_colors = str2bool(value); + options.enable_colors = str2bool(value); #else {} #endif /* auto center */ else if (!strcasecmp(CONF_AUTO_CENTER, name)) - options->auto_center = str2bool(value); + options.auto_center = str2bool(value); /* color assignment */ else if (!strcasecmp(CONF_COLOR, name)) #ifdef ENABLE_COLORS @@ -457,17 +456,17 @@ read_rc_file(char *filename, options_t *options) #endif /* wide cursor */ else if (!strcasecmp(CONF_WIDE_CURSOR, name)) - options->wide_cursor = str2bool(value); + options.wide_cursor = str2bool(value); /* welcome screen list */ else if (!strcasecmp(CONF_WELCOME_SCREEN_LIST, name)) - options->welcome_screen_list = str2bool(value); + options.welcome_screen_list = str2bool(value); /* visible bitrate */ else if (!strcasecmp(CONF_VISIBLE_BITRATE, name)) - options->visible_bitrate = str2bool(value); + options.visible_bitrate = str2bool(value); /* timer display type */ else if (!strcasecmp(CONF_TIMEDISPLAY_TYPE, name)) { - g_free(options->timedisplay_type); - options->timedisplay_type=g_strdup(parse_timedisplay_type(value)); + g_free(options.timedisplay_type); + options.timedisplay_type=g_strdup(parse_timedisplay_type(value)); /* color definition */ } else if (!strcasecmp(CONF_COLOR_DEFINITION, name)) #ifdef ENABLE_COLORS @@ -477,56 +476,56 @@ read_rc_file(char *filename, options_t *options) #endif /* list format string */ else if (!strcasecmp(CONF_LIST_FORMAT, name)) { - g_free(options->list_format); - options->list_format = get_format(value); + g_free(options.list_format); + options.list_format = get_format(value); /* status format string */ } else if (!strcasecmp(CONF_STATUS_FORMAT, name)) { - g_free(options->status_format); - options->status_format = get_format(value); + g_free(options.status_format); + options.status_format = get_format(value); /* xterm title format string */ } else if (!strcasecmp(CONF_XTERM_TITLE_FORMAT, name)) { - g_free(options->xterm_title_format); - options->xterm_title_format = get_format(value); + g_free(options.xterm_title_format); + options.xterm_title_format = get_format(value); } else if (!strcasecmp(CONF_LIST_WRAP, name)) - options->list_wrap = str2bool(value); + options.list_wrap = str2bool(value); else if (!strcasecmp(CONF_FIND_WRAP, name)) - options->find_wrap = str2bool(value); + options.find_wrap = str2bool(value); else if (!strcasecmp(CONF_FIND_SHOW_LAST,name)) - options->find_show_last_pattern = str2bool(value); + options.find_show_last_pattern = str2bool(value); else if (!strcasecmp(CONF_AUDIBLE_BELL, name)) - options->audible_bell = str2bool(value); + options.audible_bell = str2bool(value); else if (!strcasecmp(CONF_VISIBLE_BELL, name)) - options->visible_bell = str2bool(value); + options.visible_bell = str2bool(value); else if (!strcasecmp(CONF_XTERM_TITLE, name)) - options->enable_xterm_title = str2bool(value); + options.enable_xterm_title = str2bool(value); else if (!strcasecmp(CONF_ENABLE_MOUSE, name)) - options->enable_mouse = str2bool(value); + options.enable_mouse = str2bool(value); else if (!strcasecmp(CONF_CROSSFADE_TIME, name)) - options->crossfade_time = atoi(value); + options.crossfade_time = atoi(value); else if (!strcasecmp(CONF_SEARCH_MODE, name)) - options->search_mode = atoi(value); + options.search_mode = atoi(value); else if (!strcasecmp(CONF_HIDE_CURSOR, name)) - options->hide_cursor = atoi(value); + options.hide_cursor = atoi(value); else if (!strcasecmp(CONF_SEEK_TIME, name)) - options->seek_time = atoi(value); + options.seek_time = atoi(value); else if (!strcasecmp(CONF_SCREEN_LIST, name)) { - g_strfreev(options->screen_list); - options->screen_list = check_screen_list(value); + g_strfreev(options.screen_list); + options.screen_list = check_screen_list(value); } else if (!strcasecmp(CONF_SHOW_SPLASH, name)) { /* the splash screen was removed */ } else if (!strcasecmp(CONF_HOST, name)) - options->host = get_format(value); + options.host = get_format(value); else if (!strcasecmp(CONF_PORT, name)) - options->port = atoi(get_format(value)); + options.port = atoi(get_format(value)); else if (!strcasecmp(CONF_PASSWORD, name)) - options->password = get_format(value); + options.password = get_format(value); else if (!strcasecmp(CONF_LYRICS_TIMEOUT, name)) - options->lyrics_timeout = atoi(get_format(value)); + options.lyrics_timeout = atoi(get_format(value)); else if (!strcasecmp(CONF_SCROLL, name)) - options->scroll = str2bool(value); + options.scroll = str2bool(value); else if (!strcasecmp(CONF_SCROLL_SEP, name)) { - g_free(options->scroll_sep); - options->scroll_sep = get_format(value); + g_free(options.scroll_sep); + options.scroll_sep = get_format(value); } else match_found = 0; @@ -567,13 +566,13 @@ get_user_key_binding_filename(void) } int -read_configuration(options_t *options) +read_configuration(void) { char *filename = NULL; /* check for command line configuration file */ - if (options->config_file) - filename = g_strdup(options->config_file); + if (options.config_file) + filename = g_strdup(options.config_file); /* check for user configuration ~/.ncmpc/config */ if (filename == NULL) { @@ -596,14 +595,14 @@ read_configuration(options_t *options) /* load configuration */ if (filename) { - read_rc_file(filename, options); + read_rc_file(filename); g_free(filename); filename = NULL; } /* check for command line key binding file */ - if (options->key_file) - filename = g_strdup(options->key_file); + if (options.key_file) + filename = g_strdup(options.key_file); /* check for user key bindings ~/.ncmpc/keys */ if (filename == NULL) { @@ -625,7 +624,7 @@ read_configuration(options_t *options) /* load key bindings */ if (filename) { - read_rc_file(filename, options); + read_rc_file(filename); g_free(filename); filename = NULL; } diff --git a/src/conf.h b/src/conf.h index 97e73b3..3203a2d 100644 --- a/src/conf.h +++ b/src/conf.h @@ -4,5 +4,5 @@ int check_user_conf_dir(void); char *get_user_key_binding_filename(void); -int read_configuration(options_t *options); +int read_configuration(void); diff --git a/src/main.c b/src/main.c index e701712..3a6243c 100644 --- a/src/main.c +++ b/src/main.c @@ -352,7 +352,7 @@ main(int argc, const char *argv[]) options_parse(argc, argv); /* read configuration */ - read_configuration(&options); + read_configuration(); /* check key bindings */ check_key_bindings(NULL, NULL, 0); diff --git a/src/options.c b/src/options.c index 1b592a5..53f54b7 100644 --- a/src/options.c +++ b/src/options.c @@ -217,7 +217,7 @@ handle_option(int c, const char *arg) break; #ifndef NDEBUG case 'K': /* --dump-keys */ - read_configuration(&options); + read_configuration(); write_key_bindings(stdout, KEYDEF_WRITE_ALL | KEYDEF_COMMENT_ALL); exit(EXIT_SUCCESS); break; @@ -231,7 +231,7 @@ handle_option(int c, const char *arg) } } -options_t * +void options_parse(int argc, const char *argv[]) { int i; @@ -310,11 +310,9 @@ options_parse(int argc, const char *argv[]) option_cb (opt->shortopt, NULL); else if (opt && opt->argument) option_error(ERROR_MISSING_ARGUMENT, opt->longopt, opt->argument); - - return &options; } -options_t * +void options_init(void) { const char *value; @@ -357,6 +355,4 @@ options_init(void) options.lyrics_timeout = DEFAULT_LYRICS_TIMEOUT; options.scroll = DEFAULT_SCROLL; options.scroll_sep = g_strdup(DEFAULT_SCROLL_SEP); - - return &options; } diff --git a/src/options.h b/src/options.h index e7e9e8f..0f9fa13 100644 --- a/src/options.h +++ b/src/options.h @@ -45,11 +45,9 @@ typedef struct { bool welcome_screen_list; } options_t; -#ifndef NO_GLOBAL_OPTIONS extern options_t options; -#endif -options_t *options_init(void); -options_t *options_parse(int argc, const char **argv); +void options_init(void); +void options_parse(int argc, const char **argv); #endif -- 2.30.2