diff options
author | Sebastian Pipping <sebastian@pipping.org> | 2010-10-11 17:20:11 +0200 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2010-10-11 17:20:11 +0200 |
commit | f3fee983dd082266cc932df5b248d1a9b1bdd41a (patch) | |
tree | 547d2b6c7e6fc1afed5854568d1a18a2f8331b02 /config.c | |
parent | Zero (diff) | |
download | conf-update-f3fee983dd082266cc932df5b248d1a9b1bdd41a.tar.gz conf-update-f3fee983dd082266cc932df5b248d1a9b1bdd41a.tar.bz2 conf-update-f3fee983dd082266cc932df5b248d1a9b1bdd41a.zip |
Add code of conf-update 1.01.0
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/config.c b/config.c new file mode 100644 index 0000000..4637ed0 --- /dev/null +++ b/config.c @@ -0,0 +1,50 @@ +#include "conf-update.h" + +void read_config() { + extern struct configuration config; + GKeyFile *conffile; + GError *error = NULL; + + // set reasonable defaults + config.check_actions = TRUE; + + if (getenv("EDITOR")) { + config.edit_tool = strdup(getenv("EDITOR")); + } else { + fprintf(stderr, "!!! ERROR: environment variable EDITOR not set; edit your /etc/rc.conf\n" + "!!! If you are using sudo, make sure it doesn't clean out the env.\n"); + exit(EXIT_FAILURE); + } + + conffile = g_key_file_new(); + if (!g_key_file_load_from_file(conffile, CONFIG_FILE, G_KEY_FILE_NONE, NULL)) { + fprintf(stderr, "!!! ERROR: Could not load config file %s\n", CONFIG_FILE); + exit(EXIT_FAILURE); + } else { + config.automerge_trivial = g_key_file_get_boolean(conffile, PROG_NAME, "autoreplace_trivial", &error); + if (g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE) || g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { + config.automerge_trivial = TRUE; + g_clear_error(&error); + } + config.automerge_unmodified = g_key_file_get_boolean(conffile, PROG_NAME, "autoreplace_unmodified", &error); + if (g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE) || g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { + config.automerge_unmodified = FALSE; + g_clear_error(&error); + } + config.check_actions = g_key_file_get_boolean(conffile, PROG_NAME, "confirm_actions", &error); + if (g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE) || g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { + config.check_actions = TRUE; + g_clear_error(&error); + } + if (!(config.diff_tool = g_key_file_get_string(conffile, PROG_NAME, "diff_tool", NULL))) { + config.diff_tool = strdup("diff -u"); + } + if (!(config.pager = g_key_file_get_string(conffile, PROG_NAME, "pager", NULL))) { + config.pager = strdup(""); + } + if (!(config.merge_tool = g_key_file_get_string(conffile, PROG_NAME, "merge_tool", NULL))) { + config.merge_tool = strdup("sdiff -s -o"); + } + } + g_key_file_free(conffile); +} |