From 9a92be6c795732528005ce28fcefcb5bb52cc5a6 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 4 Feb 2008 20:03:28 +0000 Subject: [PATCH] 2008-02-04 Dan Williams * system-settings/src/main.c - (parse_config_file): parse a config file - (main): accept --config option and read plugins from config file git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3288 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 6 ++++++ system-settings/src/main.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 460c4987b9..d264dfc56c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-02-04 Dan Williams + + * system-settings/src/main.c + - (parse_config_file): parse a config file + - (main): accept --config option and read plugins from config file + 2008-02-04 Dan Williams * system-settings/plugins/ifcfg-fedora/plugin.c diff --git a/system-settings/src/main.c b/system-settings/src/main.c index d84f4ed4b5..27b2b93728 100644 --- a/system-settings/src/main.c +++ b/system-settings/src/main.c @@ -375,6 +375,30 @@ error: return FALSE; } +static gboolean +parse_config_file (const char *filename, char **plugins, GError **error) +{ + GKeyFile *config; + + config = g_key_file_new (); + if (!config) { + g_set_error (error, plugins_error_quark (), 0, + "Not enough memory to load config file."); + return FALSE; + } + + g_key_file_set_list_separator (config, ','); + if (!g_key_file_load_from_file (config, filename, G_KEY_FILE_NONE, error)) + return FALSE; + + *plugins = g_key_file_get_value (config, "main", "plugins", error); + if (*error) + return FALSE; + + g_key_file_free (config); + return TRUE; +} + int main (int argc, char **argv) { @@ -382,8 +406,10 @@ main (int argc, char **argv) GOptionContext *opt_ctx; GError *error = NULL; char *plugins = NULL; + char *config = NULL; GOptionEntry entries[] = { + { "config", 0, 0, G_OPTION_ARG_FILENAME, &config, "Config file location", "/path/to/config.file" }, { "plugins", 0, 0, G_OPTION_ARG_STRING, &plugins, "List of plugins separated by ,", "plugin1,plugin2" }, { NULL } }; @@ -400,8 +426,15 @@ main (int argc, char **argv) g_option_context_free (opt_ctx); + if (config) { + if (!parse_config_file (config, &plugins, &error)) { + g_warning ("Invalid config file: %s.", error->message); + return 1; + } + } + if (!plugins) { - g_warning ("'plugins' argument is required."); + g_warning ("No plugins were specified."); return 1; }