summaryrefslogtreecommitdiff
path: root/ted.c
diff options
context:
space:
mode:
Diffstat (limited to 'ted.c')
-rw-r--r--ted.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/ted.c b/ted.c
index e861736..9bff01a 100644
--- a/ted.c
+++ b/ted.c
@@ -352,3 +352,38 @@ static void ted_reload_all(Ted *ted) {
menu_close(ted);
}
}
+
+// load/reload configs
+void ted_load_configs(Ted *ted) {
+ config_free(ted);
+
+ // copy global config to local config
+ char local_config_filename[TED_PATH_MAX];
+ strbuf_printf(local_config_filename, "%s" PATH_SEPARATOR_STR TED_CFG, ted->local_data_dir);
+ char global_config_filename[TED_PATH_MAX];
+ strbuf_printf(global_config_filename, "%s" PATH_SEPARATOR_STR TED_CFG, ted->global_data_dir);
+ if (!fs_file_exists(local_config_filename)) {
+ if (fs_file_exists(global_config_filename)) {
+ if (!copy_file(global_config_filename, local_config_filename)) {
+ die("Couldn't copy config %s to %s.", global_config_filename, local_config_filename);
+ }
+ } else {
+ die("ted's backup config file, %s, does not exist. Try reinstalling ted?", global_config_filename);
+ }
+ }
+
+ // read global settings
+ config_read(ted, global_config_filename, 0);
+ config_read(ted, local_config_filename, 0);
+ if (ted->search_cwd) {
+ // read config in cwd
+ config_read(ted, TED_CFG, 0);
+ }
+ // copy global settings to language-specific settings
+ for (int l = 1; l < LANG_COUNT; ++l)
+ ted->settings_by_language[l] = ted->settings_by_language[0];
+ // read language-specific settings
+ config_read(ted, global_config_filename, 1);
+ config_read(ted, local_config_filename, 1);
+ if (ted->search_cwd) config_read(ted, TED_CFG, 1);
+}