Move code clearing the config to a new function

This commit is contained in:
Orestis Floros 2019-03-29 11:41:27 +02:00
parent 4a2cacebf6
commit 7754de900a
No known key found for this signature in database
GPG Key ID: E9AD9F32E401E38F
1 changed files with 121 additions and 115 deletions

View File

@ -39,45 +39,12 @@ void update_barconfig(void) {
}
}
/*
* Finds the configuration file to use (either the one specified by
* override_configpath), the users one or the system default) and calls
* parse_file().
*
*/
bool parse_configuration(const char *override_configpath, bool use_nagbar) {
char *path = get_config_path(override_configpath, true);
if (path == NULL) {
die("Unable to find the configuration file (looked at "
"$XDG_CONFIG_HOME/i3/config, ~/.i3/config, $XDG_CONFIG_DIRS/i3/config "
"and " SYSCONFDIR "/i3/config)");
}
static void free_configuration(void) {
assert(conn != NULL);
LOG("Parsing configfile %s\n", path);
FREE(current_configpath);
current_configpath = path;
/* initialize default bindings if we're just validating the config file */
if (!use_nagbar && bindings == NULL) {
bindings = scalloc(1, sizeof(struct bindings_head));
TAILQ_INIT(bindings);
}
return parse_file(path, use_nagbar);
}
/*
* (Re-)loads the configuration file (sets useful defaults before).
*
* If you specify override_configpath, only this path is used to look for a
* configuration file.
*
*/
void load_configuration(const char *override_configpath, bool reload) {
if (reload) {
/* If we are currently in a binding mode, we first revert to the
* default since we have no guarantee that the current mode will even
* still exist after parsing the config again. See #2228. */
/* If we are currently in a binding mode, we first revert to the default
* since we have no guarantee that the current mode will even still exist
* after parsing the config again. See #2228. */
switch_mode("default");
/* First ungrab the keys */
@ -190,6 +157,45 @@ void load_configuration(const char *override_configpath, bool reload) {
free(config.ipc_socket_path);
free(config.restart_state_path);
free(config.fake_outputs);
}
/*
* Finds the configuration file to use (either the one specified by
* override_configpath), the users one or the system default) and calls
* parse_file().
*
*/
bool parse_configuration(const char *override_configpath, bool use_nagbar) {
char *path = get_config_path(override_configpath, true);
if (path == NULL) {
die("Unable to find the configuration file (looked at "
"$XDG_CONFIG_HOME/i3/config, ~/.i3/config, $XDG_CONFIG_DIRS/i3/config "
"and " SYSCONFDIR "/i3/config)");
}
LOG("Parsing configfile %s\n", path);
FREE(current_configpath);
current_configpath = path;
/* initialize default bindings if we're just validating the config file */
if (!use_nagbar && bindings == NULL) {
bindings = scalloc(1, sizeof(struct bindings_head));
TAILQ_INIT(bindings);
}
return parse_file(path, use_nagbar);
}
/*
* (Re-)loads the configuration file (sets useful defaults before).
*
* If you specify override_configpath, only this path is used to look for a
* configuration file.
*
*/
void load_configuration(const char *override_configpath, bool reload) {
if (reload) {
free_configuration();
}
SLIST_INIT(&modes);