[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r37133 - in gnunet: doc/man src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r37133 - in gnunet: doc/man src/util |
Date: |
Thu, 5 May 2016 17:10:48 +0200 |
Author: grothoff
Date: 2016-05-05 17:10:48 +0200 (Thu, 05 May 2016)
New Revision: 37133
Modified:
gnunet/doc/man/gnunet-config.1
gnunet/src/util/gnunet-config.c
Log:
add -w option to gnunet-config
Modified: gnunet/doc/man/gnunet-config.1
===================================================================
--- gnunet/doc/man/gnunet-config.1 2016-05-05 13:02:18 UTC (rev 37132)
+++ gnunet/doc/man/gnunet-config.1 2016-05-05 15:10:48 UTC (rev 37133)
@@ -22,6 +22,9 @@
.IP "\-S, \-\-list\-sections"
List available configuration sections for use with \-\-section.
.B
+.IP "\-W, \-\-rewrite"
+Consider differences to defaults only.
+.B
.IP "\-o OPTION, \-\-option=OPTION"
Which configuration option should be accessed or edited. Required to set a
value. If not given, all values of a given section will be printed in the
format "OPTION = VALUE".
.B
@@ -43,4 +46,3 @@
.SH BUGS
Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending
electronic mail to <address@hidden>
-
Modified: gnunet/src/util/gnunet-config.c
===================================================================
--- gnunet/src/util/gnunet-config.c 2016-05-05 13:02:18 UTC (rev 37132)
+++ gnunet/src/util/gnunet-config.c 2016-05-05 15:10:48 UTC (rev 37133)
@@ -57,6 +57,11 @@
*/
static int ret;
+/**
+ * Should we generate a configuration file that is clean and
+ * only contains the deltas to the defaults?
+ */
+static int rewrite;
/**
* Print each option in a given section.
@@ -99,29 +104,55 @@
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- struct GNUNET_CONFIGURATION_Handle *out;
+ struct GNUNET_CONFIGURATION_Handle *out = NULL;
+ struct GNUNET_CONFIGURATION_Handle *diff = NULL;
- if (NULL == section || list_sections)
+ if (rewrite)
{
+ struct GNUNET_CONFIGURATION_Handle *def;
+
+ def = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (def, NULL))
+ {
+ fprintf (stderr,
+ _("failed to load configuration defaults"));
+ ret = 1;
+ return;
+ }
+ diff = GNUNET_CONFIGURATION_get_diff (def,
+ cfg);
+ cfg = diff;
+ }
+ if ( ((! rewrite) && (NULL == section)) || list_sections)
+ {
if (! list_sections)
{
- fprintf (stderr, _("--section argument is required\n"));
+ fprintf (stderr,
+ _("--section argument is required\n"));
}
- fprintf (stderr, _("The following sections are available:\n"));
- GNUNET_CONFIGURATION_iterate_sections (cfg, &print_section_name, NULL);
+ fprintf (stderr,
+ _("The following sections are available:\n"));
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &print_section_name,
+ NULL);
ret = 1;
- return;
+ goto cleanup;
}
- if (NULL == value)
+ if ( (NULL != section) && (NULL == value) )
{
if (NULL == option)
{
- GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
- &print_option, NULL);
+ GNUNET_CONFIGURATION_iterate_section_values (cfg,
+ section,
+ &print_option,
+ NULL);
}
else
{
@@ -128,12 +159,15 @@
if (is_filename)
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, section, option,
&value))
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ section,
+ option,
+ &value))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
section, option);
ret = 3;
- return;
+ goto cleanup;
}
}
else
@@ -144,28 +178,38 @@
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
section, option);
ret = 3;
- return;
+ goto cleanup;
}
}
fprintf (stdout, "%s\n", value);
}
}
- else
+ else if (NULL != section)
{
if (NULL == option)
{
fprintf (stderr, _("--option argument required to set value\n"));
ret = 1;
- return;
+ goto cleanup;
}
out = GNUNET_CONFIGURATION_dup (cfg);
- GNUNET_CONFIGURATION_set_value_string (out, section, option, value);
+ GNUNET_CONFIGURATION_set_value_string (out,
+ section,
+ option,
+ value);
+ }
+ if ( (NULL != diff) || (NULL != out) )
+ {
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write (out, cfgfile))
+ GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out,
+ cfgfile))
ret = 2;
+ }
+ if (NULL != out)
GNUNET_CONFIGURATION_destroy (out);
- return;
- }
+ cleanup:
+ if (NULL != diff)
+ GNUNET_CONFIGURATION_destroy (diff);
}
@@ -195,6 +239,9 @@
{ 'S', "list-sections", NULL,
gettext_noop ("print available configuration sections"),
0, &GNUNET_GETOPT_set_one, &list_sections },
+ { 'w', "rewrite", NULL,
+ gettext_noop ("write configuration file that only contains delta to
defaults"),
+ 0, &GNUNET_GETOPT_set_one, &rewrite },
GNUNET_GETOPT_OPTION_END
};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r37133 - in gnunet: doc/man src/util,
gnunet <=