Christian Grothoff 5 år sedan
förälder
incheckning
988ac7f121

+ 11 - 10
src/arm/gnunet-arm.c

@@ -799,25 +799,26 @@ main (int argc, char *const *argv)
        gettext_noop ("don't let gnunet-service-arm inherit standard error"),
        gettext_noop ("don't let gnunet-service-arm inherit standard error"),
        &no_stderr),
        &no_stderr),
      GNUNET_GETOPT_OPTION_END};
      GNUNET_GETOPT_OPTION_END};
+  int lret;
 
 
   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
     return 2;
     return 2;
   if (GNUNET_OK ==
   if (GNUNET_OK ==
-      GNUNET_PROGRAM_run (
-        argc,
-        argv,
-        "gnunet-arm",
-        gettext_noop (
-          "Control services and the Automated Restart Manager (ARM)"),
-        options,
-        &run,
-        NULL))
+      (lret = GNUNET_PROGRAM_run (
+         argc,
+         argv,
+         "gnunet-arm",
+         gettext_noop (
+           "Control services and the Automated Restart Manager (ARM)"),
+         options,
+         &run,
+         NULL)))
   {
   {
     GNUNET_free ((void *) argv);
     GNUNET_free ((void *) argv);
     return ret;
     return ret;
   }
   }
   GNUNET_free ((void *) argv);
   GNUNET_free ((void *) argv);
-  return 1;
+  return lret;
 }
 }
 
 
 /* end of gnunet-arm.c */
 /* end of gnunet-arm.c */

+ 0 - 1
src/cadet/gnunet-service-cadet.c

@@ -32,7 +32,6 @@
  * - channel: logical link between two clients, on the same or different peers.
  * - channel: logical link between two clients, on the same or different peers.
  *            have properties like reliability.
  *            have properties like reliability.
  */
  */
-
 #include "platform.h"
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_util_lib.h"
 #include "cadet.h"
 #include "cadet.h"

+ 38 - 22
src/include/gnunet_getopt_lib.h

@@ -33,9 +33,8 @@
 #define GNUNET_GETOPT_LIB_H
 #define GNUNET_GETOPT_LIB_H
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
-extern "C"
-{
-#if 0                           /* keep Emacsens' auto-indent happy */
+extern "C" {
+#if 0 /* keep Emacsens' auto-indent happy */
 }
 }
 #endif
 #endif
 #endif
 #endif
@@ -77,7 +76,6 @@ struct GNUNET_GETOPT_CommandLineProcessorContext
    * Current argument.
    * Current argument.
    */
    */
   unsigned int currentArgument;
   unsigned int currentArgument;
-
 };
 };
 
 
 
 
@@ -90,12 +88,11 @@ struct GNUNET_GETOPT_CommandLineProcessorContext
  * @param value argument, NULL if none was given
  * @param value argument, NULL if none was given
  * @return #GNUNET_OK to continue processing other options, #GNUNET_SYSERR to abort
  * @return #GNUNET_OK to continue processing other options, #GNUNET_SYSERR to abort
  */
  */
-typedef int
-(*GNUNET_GETOPT_CommandLineOptionProcessor) (struct
-                                             GNUNET_GETOPT_CommandLineProcessorContext *ctx,
-                                             void *scls,
-                                             const char *option,
-                                             const char *value);
+typedef int (*GNUNET_GETOPT_CommandLineOptionProcessor) (
+  struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+  void *scls,
+  const char *option,
+  const char *value);
 
 
 
 
 /**
 /**
@@ -149,13 +146,12 @@ struct GNUNET_GETOPT_CommandLineOption
    * Function to call on @e scls to clean up after processing all
    * Function to call on @e scls to clean up after processing all
    * the arguments. Can be NULL.
    * the arguments. Can be NULL.
    */
    */
-  void (*cleaner)(void *cls);
+  void (*cleaner) (void *cls);
 
 
   /**
   /**
    * Specific closure to pass to the processor.
    * Specific closure to pass to the processor.
    */
    */
   void *scls;
   void *scls;
-
 };
 };
 
 
 
 
@@ -179,7 +175,6 @@ struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_version (const char *version);
 GNUNET_GETOPT_option_version (const char *version);
 
 
 
 
-
 /**
 /**
  * Allow user to specify log file name (-l option)
  * Allow user to specify log file name (-l option)
  *
  *
@@ -254,8 +249,17 @@ GNUNET_GETOPT_option_base32_fixed_size (char shortName,
  * @param[out] val binary value decoded from Crockford Base32-encoded argument;
  * @param[out] val binary value decoded from Crockford Base32-encoded argument;
  *             size is determined by type (sizeof (*val)).
  *             size is determined by type (sizeof (*val)).
  */
  */
-#define GNUNET_GETOPT_option_base32_auto(shortName,name,argumentHelp,description,val) \
-  GNUNET_GETOPT_option_base32_fixed_size(shortName,name,argumentHelp,description,val,sizeof(*val))
+#define GNUNET_GETOPT_option_base32_auto(shortName,     \
+                                         name,          \
+                                         argumentHelp,  \
+                                         description,   \
+                                         val)           \
+  GNUNET_GETOPT_option_base32_fixed_size (shortName,    \
+                                          name,         \
+                                          argumentHelp, \
+                                          description,  \
+                                          val,          \
+                                          sizeof (*val))
 
 
 
 
 /**
 /**
@@ -302,10 +306,10 @@ GNUNET_GETOPT_option_uint (char shortName,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_uint16 (char shortName,
 GNUNET_GETOPT_option_uint16 (char shortName,
-			     const char *name,
-			     const char *argumentHelp,
-			     const char *description,
-			     uint16_t *val);
+                             const char *name,
+                             const char *argumentHelp,
+                             const char *description,
+                             uint16_t *val);
 
 
 
 
 /**
 /**
@@ -425,11 +429,23 @@ struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt);
 GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt);
 
 
 
 
+/**
+ * Make the given option mutually exclusive with other options.
+ *
+ * @param opt option to modify
+ * @return @a opt with the exclusive flag set.
+ */
+struct GNUNET_GETOPT_CommandLineOption
+GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt);
+
+
 /**
 /**
  * Marker for the end of the list of options.
  * Marker for the end of the list of options.
  */
  */
-#define GNUNET_GETOPT_OPTION_END \
-  { '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL }
+#define GNUNET_GETOPT_OPTION_END                      \
+  {                                                   \
+    '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \
+  }
 
 
 
 
 /**
 /**
@@ -449,7 +465,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
                    char *const *argv);
                    char *const *argv);
 
 
 
 
-#if 0                           /* keep Emacsens' auto-indent happy */
+#if 0 /* keep Emacsens' auto-indent happy */
 {
 {
 #endif
 #endif
 #ifdef __cplusplus
 #ifdef __cplusplus

+ 10 - 8
src/namestore/gnunet-namestore.c

@@ -1647,6 +1647,7 @@ main (int argc, char *const *argv)
                                     "name of the ego controlling the zone"),
                                     "name of the ego controlling the zone"),
                                   &ego_name),
                                   &ego_name),
      GNUNET_GETOPT_OPTION_END};
      GNUNET_GETOPT_OPTION_END};
+  int lret;
 
 
   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
     return 2;
     return 2;
@@ -1654,17 +1655,18 @@ main (int argc, char *const *argv)
   is_public = -1;
   is_public = -1;
   is_shadow = -1;
   is_shadow = -1;
   GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL);
   GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL);
-  if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
-                                       argv,
-                                       "gnunet-namestore",
-                                       _ ("GNUnet zone manipulation tool"),
-                                       options,
-                                       &run,
-                                       NULL))
+  if (GNUNET_OK !=
+      (lret = GNUNET_PROGRAM_run (argc,
+                                  argv,
+                                  "gnunet-namestore",
+                                  _ ("GNUnet zone manipulation tool"),
+                                  options,
+                                  &run,
+                                  NULL)))
   {
   {
     GNUNET_free ((void *) argv);
     GNUNET_free ((void *) argv);
     GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
     GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
-    return 1;
+    return lret;
   }
   }
   GNUNET_free ((void *) argv);
   GNUNET_free ((void *) argv);
   GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
   GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);

+ 114 - 86
src/util/getopt.c

@@ -47,14 +47,15 @@ Copyright (C) 2006, 2017 Christian Grothoff
 #endif
 #endif
 #endif
 #endif
 
 
-#define LOG(kind,...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
 
 
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-getopt", syscall)
+#define LOG_STRERROR(kind, syscall) \
+  GNUNET_log_from_strerror (kind, "util-getopt", syscall)
 
 
-#if defined (WIN32) && !defined (__CYGWIN32__)
+#if defined(WIN32) && ! defined(__CYGWIN32__)
 /* It's not Unix, really.  See?  Capital letters.  */
 /* It's not Unix, really.  See?  Capital letters.  */
 #include <windows.h>
 #include <windows.h>
-#define getpid() GetCurrentProcessId()
+#define getpid() GetCurrentProcessId ()
 #endif
 #endif
 
 
 #ifndef _
 #ifndef _
@@ -62,9 +63,9 @@ Copyright (C) 2006, 2017 Christian Grothoff
    When compiling libc, the _ macro is predefined.  */
    When compiling libc, the _ macro is predefined.  */
 #ifdef HAVE_LIBINTL_H
 #ifdef HAVE_LIBINTL_H
 #include <libintl.h>
 #include <libintl.h>
-#define _(msgid)  gettext (msgid)
+#define _(msgid) gettext (msgid)
 #else
 #else
-#define _(msgid)  (msgid)
+#define _(msgid) (msgid)
 #endif
 #endif
 #endif
 #endif
 
 
@@ -176,21 +177,18 @@ static char *nextchar;
    of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
    of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
    `--' can cause `getopt' to return -1 with `GNoptind' != ARGC.  */
    `--' can cause `getopt' to return -1 with `GNoptind' != ARGC.  */
 
 
-static enum
-{
-  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
-} ordering;
+static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering;
 
 
 /* Value of POSIXLY_CORRECT environment variable.  */
 /* Value of POSIXLY_CORRECT environment variable.  */
 static char *posixly_correct;
 static char *posixly_correct;
 
 
-#ifdef  __GNU_LIBRARY__
+#ifdef __GNU_LIBRARY__
 /* We want to avoid inclusion of string.h with non-GNU libraries
 /* We want to avoid inclusion of string.h with non-GNU libraries
    because there are many ways it can cause trouble.
    because there are many ways it can cause trouble.
    On some systems, it contains special magic macros that don't work
    On some systems, it contains special magic macros that don't work
    in GCC.  */
    in GCC.  */
 #include <string.h>
 #include <string.h>
-#define  my_index	strchr
+#define my_index strchr
 #else
 #else
 
 
 /* Avoid depending on library functions or files
 /* Avoid depending on library functions or files
@@ -200,8 +198,7 @@ char *
 getenv ();
 getenv ();
 
 
 static char *
 static char *
-my_index (const char *str,
-	  int chr)
+my_index (const char *str, int chr)
 {
 {
   while (*str)
   while (*str)
   {
   {
@@ -217,7 +214,7 @@ my_index (const char *str,
 #ifdef __GNUC__
 #ifdef __GNUC__
 /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
 /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
    That was relevant to code that was here before.  */
    That was relevant to code that was here before.  */
-#if !defined (__STDC__) || !__STDC__
+#if ! defined(__STDC__) || ! __STDC__
 /* gcc with -traditional declares the built-in strlen to return int,
 /* gcc with -traditional declares the built-in strlen to return int,
    and has done so at least since version 2.4.5. -- rms.  */
    and has done so at least since version 2.4.5. -- rms.  */
 extern int
 extern int
@@ -247,7 +244,7 @@ static int last_nonopt;
    `first_nonopt' and `last_nonopt' are relocated so that they describe
    `first_nonopt' and `last_nonopt' are relocated so that they describe
    the new indices of the non-options in ARGV after they are moved.  */
    the new indices of the non-options in ARGV after they are moved.  */
 
 
-#if defined (__STDC__) && __STDC__
+#if defined(__STDC__) && __STDC__
 static void
 static void
 exchange (char **);
 exchange (char **);
 #endif
 #endif
@@ -311,14 +308,12 @@ exchange (char **argv)
 
 
 /* Initialize the internal data when the first call is made.  */
 /* Initialize the internal data when the first call is made.  */
 
 
-#if defined (__STDC__) && __STDC__
+#if defined(__STDC__) && __STDC__
 static const char *
 static const char *
 _getopt_initialize (int, char *const *, const char *);
 _getopt_initialize (int, char *const *, const char *);
 #endif
 #endif
 static const char *
 static const char *
-_getopt_initialize (int argc,
-		    char *const *argv,
-		    const char *optstring)
+_getopt_initialize (int argc, char *const *argv, const char *optstring)
 {
 {
   /* Start processing options with ARGV-element 1 (since ARGV-element 0
   /* Start processing options with ARGV-element 1 (since ARGV-element 0
    * is the program name); the sequence of previously skipped
    * is the program name); the sequence of previously skipped
@@ -407,8 +402,11 @@ _getopt_initialize (int argc,
    long-named options.  */
    long-named options.  */
 
 
 static int
 static int
-GN_getopt_internal (int argc, char *const *argv, const char *optstring,
-                    const struct GNoption *longopts, int *longind,
+GN_getopt_internal (int argc,
+                    char *const *argv,
+                    const char *optstring,
+                    const struct GNoption *longopts,
+                    int *longind,
                     int long_only)
                     int long_only)
 {
 {
   static int __getopt_initialized = 0;
   static int __getopt_initialized = 0;
@@ -416,10 +414,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
 
 
   GNoptarg = NULL;
   GNoptarg = NULL;
 
 
-  if (GNoptind == 0 || !__getopt_initialized)
+  if (GNoptind == 0 || ! __getopt_initialized)
   {
   {
     if (GNoptind == 0)
     if (GNoptind == 0)
-      GNoptind = 1;             /* Don't scan ARGV[0], the program name.  */
+      GNoptind = 1; /* Don't scan ARGV[0], the program name.  */
     optstring = _getopt_initialize (argc, argv, optstring);
     optstring = _getopt_initialize (argc, argv, optstring);
     __getopt_initialized = 1;
     __getopt_initialized = 1;
   }
   }
@@ -463,7 +461,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
      * Skip it like a null option,
      * Skip it like a null option,
      * then exchange with previous non-options as if it were an option,
      * then exchange with previous non-options as if it were an option,
      * then skip everything else like a non-option.  */
      * then skip everything else like a non-option.  */
-    if (GNoptind != argc && !strcmp (argv[GNoptind], "--"))
+    if (GNoptind != argc && ! strcmp (argv[GNoptind], "--"))
     {
     {
       GNoptind++;
       GNoptind++;
 
 
@@ -503,7 +501,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
      * Skip the initial punctuation.  */
      * Skip the initial punctuation.  */
 
 
     nextchar =
     nextchar =
-        (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
+      (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
   }
   }
 
 
   /* Decode the current option-ARGV-element.  */
   /* Decode the current option-ARGV-element.  */
@@ -524,7 +522,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
   if (longopts != NULL &&
   if (longopts != NULL &&
       (argv[GNoptind][1] == '-' ||
       (argv[GNoptind][1] == '-' ||
        (long_only &&
        (long_only &&
-        (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1])))))
+        (argv[GNoptind][2] || ! my_index (optstring, argv[GNoptind][1])))))
   {
   {
     char *nameend;
     char *nameend;
     const struct GNoption *p;
     const struct GNoption *p;
@@ -535,12 +533,12 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
     int option_index;
     int option_index;
 
 
     for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
     for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
-      /* Do nothing.  */ ;
+      /* Do nothing.  */;
 
 
     /* Test all long options for either exact match
     /* Test all long options for either exact match
      * or abbreviated matches.  */
      * or abbreviated matches.  */
     for (p = longopts, option_index = 0; p->name; p++, option_index++)
     for (p = longopts, option_index = 0; p->name; p++, option_index++)
-      if (!strncmp (p->name, nextchar, nameend - nextchar))
+      if (! strncmp (p->name, nextchar, nameend - nextchar))
       {
       {
         if ((unsigned int) (nameend - nextchar) ==
         if ((unsigned int) (nameend - nextchar) ==
             (unsigned int) strlen (p->name))
             (unsigned int) strlen (p->name))
@@ -562,10 +560,12 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
           ambig = 1;
           ambig = 1;
       }
       }
 
 
-    if (ambig && !exact)
+    if (ambig && ! exact)
     {
     {
       if (GNopterr)
       if (GNopterr)
-        FPRINTF (stderr, _("%s: option `%s' is ambiguous\n"), argv[0],
+        FPRINTF (stderr,
+                 _ ("%s: option `%s' is ambiguous\n"),
+                 argv[0],
                  argv[GNoptind]);
                  argv[GNoptind]);
       nextchar += strlen (nextchar);
       nextchar += strlen (nextchar);
       GNoptind++;
       GNoptind++;
@@ -589,13 +589,16 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
             if (argv[GNoptind - 1][1] == '-')
             if (argv[GNoptind - 1][1] == '-')
               /* --option */
               /* --option */
               FPRINTF (stderr,
               FPRINTF (stderr,
-                       _("%s: option `--%s' does not allow an argument\n"),
-                       argv[0], pfound->name);
+                       _ ("%s: option `--%s' does not allow an argument\n"),
+                       argv[0],
+                       pfound->name);
             else
             else
               /* +option or -option */
               /* +option or -option */
               FPRINTF (stderr,
               FPRINTF (stderr,
-                       _("%s: option `%c%s' does not allow an argument\n"),
-                       argv[0], argv[GNoptind - 1][0], pfound->name);
+                       _ ("%s: option `%c%s' does not allow an argument\n"),
+                       argv[0],
+                       argv[GNoptind - 1][0],
+                       pfound->name);
           }
           }
           nextchar += strlen (nextchar);
           nextchar += strlen (nextchar);
           return '?';
           return '?';
@@ -611,8 +614,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
         {
         {
           if (GNopterr)
           if (GNopterr)
           {
           {
-            FPRINTF (stderr, _("%s: option `%s' requires an argument\n"),
-                     argv[0], argv[GNoptind - 1]);
+            FPRINTF (stderr,
+                     _ ("%s: option `%s' requires an argument\n"),
+                     argv[0],
+                     argv[GNoptind - 1]);
           }
           }
           nextchar += strlen (nextchar);
           nextchar += strlen (nextchar);
           return (optstring[0] == ':') ? ':' : '?';
           return (optstring[0] == ':') ? ':' : '?';
@@ -633,19 +638,24 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
      * or the option starts with '--' or is not a valid short
      * or the option starts with '--' or is not a valid short
      * option, then it's an error.
      * option, then it's an error.
      * Otherwise interpret it as a short option.  */
      * Otherwise interpret it as a short option.  */
-    if (!long_only || argv[GNoptind][1] == '-' ||
+    if (! long_only || argv[GNoptind][1] == '-' ||
         my_index (optstring, *nextchar) == NULL)
         my_index (optstring, *nextchar) == NULL)
     {
     {
       if (GNopterr)
       if (GNopterr)
       {
       {
         if (argv[GNoptind][1] == '-')
         if (argv[GNoptind][1] == '-')
           /* --option */
           /* --option */
-          FPRINTF (stderr, _("%s: unrecognized option `--%s'\n"), argv[0],
+          FPRINTF (stderr,
+                   _ ("%s: unrecognized option `--%s'\n"),
+                   argv[0],
                    nextchar);
                    nextchar);
         else
         else
           /* +option or -option */
           /* +option or -option */
-          FPRINTF (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0],
-                   argv[GNoptind][0], nextchar);
+          FPRINTF (stderr,
+                   _ ("%s: unrecognized option `%c%s'\n"),
+                   argv[0],
+                   argv[GNoptind][0],
+                   nextchar);
       }
       }
       nextchar = (char *) "";
       nextchar = (char *) "";
       GNoptind++;
       GNoptind++;
@@ -669,9 +679,9 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
       {
       {
         if (posixly_correct)
         if (posixly_correct)
           /* 1003.2 specifies the format of this message.  */
           /* 1003.2 specifies the format of this message.  */
-          FPRINTF (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
+          FPRINTF (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
         else
         else
-          FPRINTF (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
+          FPRINTF (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
       }
       }
       return '?';
       return '?';
     }
     }
@@ -699,8 +709,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
         if (GNopterr)
         if (GNopterr)
         {
         {
           /* 1003.2 specifies the format of this message.  */
           /* 1003.2 specifies the format of this message.  */
-          FPRINTF (stderr, _("%s: option requires an argument -- %c\n"),
-                   argv[0], c);
+          FPRINTF (stderr,
+                   _ ("%s: option requires an argument -- %c\n"),
+                   argv[0],
+                   c);
         }
         }
         if (optstring[0] == ':')
         if (optstring[0] == ':')
           c = ':';
           c = ':';
@@ -718,13 +730,13 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
 
 
       for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
       for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
            nameend++)
            nameend++)
-        /* Do nothing.  */ ;
+        /* Do nothing.  */;
 
 
       /* Test all long options for either exact match
       /* Test all long options for either exact match
        * or abbreviated matches.  */
        * or abbreviated matches.  */
       if (longopts != NULL)
       if (longopts != NULL)
         for (p = longopts, option_index = 0; p->name; p++, option_index++)
         for (p = longopts, option_index = 0; p->name; p++, option_index++)
-          if (!strncmp (p->name, nextchar, nameend - nextchar))
+          if (! strncmp (p->name, nextchar, nameend - nextchar))
           {
           {
             if ((unsigned int) (nameend - nextchar) == strlen (p->name))
             if ((unsigned int) (nameend - nextchar) == strlen (p->name))
             {
             {
@@ -744,10 +756,12 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
               /* Second or later nonexact match found.  */
               /* Second or later nonexact match found.  */
               ambig = 1;
               ambig = 1;
           }
           }
-      if (ambig && !exact)
+      if (ambig && ! exact)
       {
       {
         if (GNopterr)
         if (GNopterr)
-          FPRINTF (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0],
+          FPRINTF (stderr,
+                   _ ("%s: option `-W %s' is ambiguous\n"),
+                   argv[0],
                    argv[GNoptind]);
                    argv[GNoptind]);
         nextchar += strlen (nextchar);
         nextchar += strlen (nextchar);
         GNoptind++;
         GNoptind++;
@@ -765,7 +779,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
           else
           else
           {
           {
             if (GNopterr)
             if (GNopterr)
-              FPRINTF (stderr, _("%s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name);
+              FPRINTF (stderr,
+                       _ ("%s: option `-W %s' does not allow an argument\n"),
+                       argv[0],
+                       pfound->name);
 
 
             nextchar += strlen (nextchar);
             nextchar += strlen (nextchar);
             return '?';
             return '?';
@@ -778,8 +795,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
           else
           else
           {
           {
             if (GNopterr)
             if (GNopterr)
-              FPRINTF (stderr, _("%s: option `%s' requires an argument\n"),
-                       argv[0], argv[GNoptind - 1]);
+              FPRINTF (stderr,
+                       _ ("%s: option `%s' requires an argument\n"),
+                       argv[0],
+                       argv[GNoptind - 1]);
             nextchar += strlen (nextchar);
             nextchar += strlen (nextchar);
             return optstring[0] == ':' ? ':' : '?';
             return optstring[0] == ':' ? ':' : '?';
           }
           }
@@ -795,7 +814,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
         return pfound->val;
         return pfound->val;
       }
       }
       nextchar = NULL;
       nextchar = NULL;
-      return 'W';               /* Let the application handle it.   */
+      return 'W'; /* Let the application handle it.   */
     }
     }
     if (temp[1] == ':')
     if (temp[1] == ':')
     {
     {
@@ -826,8 +845,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
           if (GNopterr)
           if (GNopterr)
           {
           {
             /* 1003.2 specifies the format of this message.  */
             /* 1003.2 specifies the format of this message.  */
-            FPRINTF (stderr, _("%s: option requires an argument -- %c\n"),
-                     argv[0], c);
+            FPRINTF (stderr,
+                     _ ("%s: option requires an argument -- %c\n"),
+                     argv[0],
+                     c);
           }
           }
           if (optstring[0] == ':')
           if (optstring[0] == ':')
             c = ':';
             c = ':';
@@ -880,8 +901,9 @@ GNUNET_GETOPT_run (const char *binaryOptions,
   char *shorts;
   char *shorts;
   int spos;
   int spos;
   int cont;
   int cont;
-  int c;
   uint8_t *seen;
   uint8_t *seen;
+  unsigned int optmatch = 0;
+  const char *have_exclusive = NULL;
 
 
   GNUNET_assert (argc > 0);
   GNUNET_assert (argc > 0);
   GNoptind = 0;
   GNoptind = 0;
@@ -890,12 +912,13 @@ GNUNET_GETOPT_run (const char *binaryOptions,
   clpc.allOptions = allOptions;
   clpc.allOptions = allOptions;
   clpc.argv = argv;
   clpc.argv = argv;
   clpc.argc = argc;
   clpc.argc = argc;
-  for (count = 0; NULL != allOptions[count].name; count++) ;
+  for (count = 0; NULL != allOptions[count].name; count++)
+    ;
 
 
-  long_options = GNUNET_new_array (count + 1,
-                                   struct GNoption);
-  seen = GNUNET_new_array (count,
-                           uint8_t);
+  /* transform our option representation into the format
+     used by the GNU getopt copylib */
+  long_options = GNUNET_new_array (count + 1, struct GNoption);
+  seen = GNUNET_new_array (count, uint8_t);
   shorts = GNUNET_malloc (count * 2 + 1);
   shorts = GNUNET_malloc (count * 2 + 1);
   spos = 0;
   spos = 0;
   for (unsigned i = 0; i < count; i++)
   for (unsigned i = 0; i < count; i++)
@@ -916,59 +939,64 @@ GNUNET_GETOPT_run (const char *binaryOptions,
   cont = GNUNET_OK;
   cont = GNUNET_OK;
 
 
   /* main getopt loop */
   /* main getopt loop */
-  while (GNUNET_OK == cont)
+  while (1)
   {
   {
     int option_index = 0;
     int option_index = 0;
     unsigned int i;
     unsigned int i;
+    int c;
 
 
-    c = GNgetopt_long (argc, argv,
-                       shorts,
-                       long_options,
-                       &option_index);
+    c = GNgetopt_long (argc, argv, shorts, long_options, &option_index);
     if (c == GNUNET_SYSERR)
     if (c == GNUNET_SYSERR)
-      break;                    /* No more flags to process */
+      break; /* No more flags to process */
 
 
+    /* Check which of our program's options was given by the user */
     for (i = 0; i < count; i++)
     for (i = 0; i < count; i++)
     {
     {
       clpc.currentArgument = GNoptind - 1;
       clpc.currentArgument = GNoptind - 1;
       if ((char) c == allOptions[i].shortName)
       if ((char) c == allOptions[i].shortName)
       {
       {
-        cont = allOptions[i].processor (&clpc,
-                                        allOptions[i].scls,
-                                        allOptions[i].name,
-                                        GNoptarg);
+        optmatch++;
+        if (allOptions[i].option_exclusive)
+          have_exclusive = allOptions[i].name;
+        if (GNUNET_OK == cont)
+        {
+          /* parse the option using the option-specific processor */
+          cont = allOptions[i].processor (&clpc,
+                                          allOptions[i].scls,
+                                          allOptions[i].name,
+                                          GNoptarg);
+        }
         seen[i] = 1;
         seen[i] = 1;
         break;
         break;
       }
       }
     }
     }
     if (i == count)
     if (i == count)
     {
     {
-      FPRINTF (stderr,
-               _("Use %s to get a list of options.\n"),
-               "--help");
+      FPRINTF (stderr, _ ("Use %s to get a list of options.\n"), "--help");
       cont = GNUNET_SYSERR;
       cont = GNUNET_SYSERR;
     }
     }
   }
   }
   GNUNET_free (shorts);
   GNUNET_free (shorts);
   GNUNET_free (long_options);
   GNUNET_free (long_options);
 
 
+  /* check that if any option that was marked as exclusive
+     is the only option that was provided */
+  if ((NULL != have_exclusive) && (optmatch > 1))
+  {
+    FPRINTF (stderr,
+             _ ("Option `%s' can't be used with other options.\n"),
+             have_exclusive);
+    cont = GNUNET_SYSERR;
+  }
   if (GNUNET_YES == cont)
   if (GNUNET_YES == cont)
   {
   {
-    for (count = 0; NULL != allOptions[count].name; count++) 
+    /* check that all mandatory options are present */
+    for (count = 0; NULL != allOptions[count].name; count++)
     {
     {
-      if (allOptions[count].option_exclusive)
-      {
-        FPRINTF (stderr,
-                 _("Option `%s' can't be used with other options.\n"),
-                 allOptions[count].name);
-        cont = GNUNET_SYSERR;
-      }
-
-      if ( (0 == seen[count]) &&
-           (allOptions[count].option_mandatory) )
+      if ((0 == seen[count]) && (allOptions[count].option_mandatory))
       {
       {
         FPRINTF (stderr,
         FPRINTF (stderr,
-                 _("Missing mandatory option `%s'.\n"),
+                 _ ("Missing mandatory option `%s'.\n"),
                  allOptions[count].name);
                  allOptions[count].name);
         cont = GNUNET_SYSERR;
         cont = GNUNET_SYSERR;
       }
       }

+ 208 - 233
src/util/getopt_helpers.c

@@ -26,7 +26,7 @@
 #include "platform.h"
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_util_lib.h"
 
 
-#define LOG(kind,...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
 
 
 
 
 /**
 /**
@@ -48,9 +48,7 @@ print_version (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
 
 
   (void) option;
   (void) option;
   (void) value;
   (void) value;
-  printf ("%s v%s\n",
-	  ctx->binaryName,
-	  version);
+  printf ("%s v%s\n", ctx->binaryName, version);
   return GNUNET_NO;
   return GNUNET_NO;
 }
 }
 
 
@@ -64,14 +62,13 @@ print_version (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_version (const char *version)
 GNUNET_GETOPT_option_version (const char *version)
 {
 {
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  'v',
-    .name = "version",
-    .description = gettext_noop("print the version number"),
-    .option_exclusive = 1,
-    .processor = &print_version,
-    .scls = (void *) version
-  };
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = 'v',
+                                                .name = "version",
+                                                .description = gettext_noop (
+                                                  "print the version number"),
+                                                .option_exclusive = 1,
+                                                .processor = &print_version,
+                                                .scls = (void *) version};
   return clo;
   return clo;
 }
 }
 
 
@@ -111,10 +108,9 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
   (void) value;
   (void) value;
   if (NULL != about)
   if (NULL != about)
   {
   {
-    printf ("%s\n%s\n",
-	    ctx->binaryOptions,
-	    gettext (about));
-    printf (_("Arguments mandatory for long options are also mandatory for short options.\n"));
+    printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
+    printf (_ (
+      "Arguments mandatory for long options are also mandatory for short options.\n"));
   }
   }
   i = 0;
   i = 0;
   opt = ctx->allOptions;
   opt = ctx->allOptions;
@@ -147,7 +143,7 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
       trans = "";
       trans = "";
     ml = strlen (trans);
     ml = strlen (trans);
     p = 0;
     p = 0;
-OUTER:
+  OUTER:
     while (ml - p > 78 - slen)
     while (ml - p > 78 - slen)
     {
     {
       for (j = p + 78 - slen; j > (int) p; j--)
       for (j = p + 78 - slen; j > (int) p; j--)
@@ -199,13 +195,13 @@ OUTER:
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_help (const char *about)
 GNUNET_GETOPT_option_help (const char *about)
 {
 {
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName = 'h',
-    .name = "help",
-    .description = gettext_noop("print this help"),
-    .processor = format_help,
-    .scls = (void *) about
-  };
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = 'h',
+                                                .name = "help",
+                                                .description = gettext_noop (
+                                                  "print this help"),
+                                                .option_exclusive = 1,
+                                                .processor = format_help,
+                                                .scls = (void *) about};
 
 
   return clo;
   return clo;
 }
 }
@@ -252,17 +248,15 @@ increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_increment_uint (char shortName,
 GNUNET_GETOPT_option_increment_uint (char shortName,
-				     const char *name,
-				     const char *description,
-				     unsigned int *val)
-{
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .description = description,
-    .processor = &increment_value,
-    .scls = (void *) val
-  };
+                                     const char *name,
+                                     const char *description,
+                                     unsigned int *val)
+{
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .description = description,
+                                                .processor = &increment_value,
+                                                .scls = (void *) val};
 
 
   return clo;
   return clo;
 }
 }
@@ -277,13 +271,12 @@ GNUNET_GETOPT_option_increment_uint (char shortName,
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_verbose (unsigned int *level)
 GNUNET_GETOPT_option_verbose (unsigned int *level)
 {
 {
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName = 'V',
-    .name = "verbose",
-    .description = gettext_noop("be verbose"),
-    .processor = &increment_value,
-    .scls = (void *) level
-  };
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = 'V',
+                                                .name = "verbose",
+                                                .description =
+                                                  gettext_noop ("be verbose"),
+                                                .processor = &increment_value,
+                                                .scls = (void *) level};
 
 
   return clo;
   return clo;
 }
 }
@@ -331,17 +324,15 @@ set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_flag (char shortName,
 GNUNET_GETOPT_option_flag (char shortName,
-			   const char *name,
-			   const char *description,
-			   int *val)
-{
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .description = description,
-    .processor = &set_one,
-    .scls = (void *) val
-  };
+                           const char *name,
+                           const char *description,
+                           int *val)
+{
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .description = description,
+                                                .processor = &set_one,
+                                                .scls = (void *) val};
 
 
   return clo;
   return clo;
 }
 }
@@ -394,15 +385,13 @@ GNUNET_GETOPT_option_string (char shortName,
                              const char *description,
                              const char *description,
                              char **str)
                              char **str)
 {
 {
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .argumentHelp = argumentHelp,
-    .description = description,
-    .require_argument = 1,
-    .processor = &set_string,
-    .scls = (void *) str
-  };
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .argumentHelp = argumentHelp,
+                                                .description = description,
+                                                .require_argument = 1,
+                                                .processor = &set_string,
+                                                .scls = (void *) str};
 
 
   return clo;
   return clo;
 }
 }
@@ -417,15 +406,14 @@ GNUNET_GETOPT_option_string (char shortName,
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_loglevel (char **level)
 GNUNET_GETOPT_option_loglevel (char **level)
 {
 {
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName = 'L',
-    .name = "log",
-    .argumentHelp = "LOGLEVEL",
-    .description = gettext_noop("configure logging to use LOGLEVEL"),
-    .require_argument = 1,
-    .processor = &set_string,
-    .scls = (void *) level
-  };
+  struct GNUNET_GETOPT_CommandLineOption clo =
+    {.shortName = 'L',
+     .name = "log",
+     .argumentHelp = "LOGLEVEL",
+     .description = gettext_noop ("configure logging to use LOGLEVEL"),
+     .require_argument = 1,
+     .processor = &set_string,
+     .scls = (void *) level};
 
 
   return clo;
   return clo;
 }
 }
@@ -470,20 +458,18 @@ set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_filename (char shortName,
 GNUNET_GETOPT_option_filename (char shortName,
-			       const char *name,
-			       const char *argumentHelp,
-			       const char *description,
-			       char **str)
-{
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .argumentHelp = argumentHelp,
-    .description = description,
-    .require_argument = 1,
-    .processor = &set_filename,
-    .scls = (void *) str
-  };
+                               const char *name,
+                               const char *argumentHelp,
+                               const char *description,
+                               char **str)
+{
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .argumentHelp = argumentHelp,
+                                                .description = description,
+                                                .require_argument = 1,
+                                                .processor = &set_filename,
+                                                .scls = (void *) str};
 
 
   return clo;
   return clo;
 }
 }
@@ -497,15 +483,15 @@ GNUNET_GETOPT_option_filename (char shortName,
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_logfile (char **logfn)
 GNUNET_GETOPT_option_logfile (char **logfn)
 {
 {
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  'l',
-    .name = "logfile",
-    .argumentHelp = "FILENAME",
-    .description = gettext_noop ("configure logging to write logs to FILENAME"),
-    .require_argument = 1,
-    .processor = &set_filename,
-    .scls = (void *) logfn
-  };
+  struct GNUNET_GETOPT_CommandLineOption clo =
+    {.shortName = 'l',
+     .name = "logfile",
+     .argumentHelp = "FILENAME",
+     .description =
+       gettext_noop ("configure logging to write logs to FILENAME"),
+     .require_argument = 1,
+     .processor = &set_filename,
+     .scls = (void *) logfn};
 
 
   return clo;
   return clo;
 }
 }
@@ -519,15 +505,14 @@ GNUNET_GETOPT_option_logfile (char **logfn)
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_cfgfile (char **fn)
 GNUNET_GETOPT_option_cfgfile (char **fn)
 {
 {
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  'c',
-    .name = "config",
-    .argumentHelp = "FILENAME",
-    .description = gettext_noop("use configuration file FILENAME"),
-    .require_argument = 1,
-    .processor = &set_filename,
-    .scls = (void *) fn
-  };
+  struct GNUNET_GETOPT_CommandLineOption clo =
+    {.shortName = 'c',
+     .name = "config",
+     .argumentHelp = "FILENAME",
+     .description = gettext_noop ("use configuration file FILENAME"),
+     .require_argument = 1,
+     .processor = &set_filename,
+     .scls = (void *) fn};
 
 
   return clo;
   return clo;
 }
 }
@@ -556,13 +541,10 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
   char dummy[2];
   char dummy[2];
 
 
   (void) ctx;
   (void) ctx;
-  if (1 != SSCANF (value,
-                   "%llu%1s",
-                   val,
-		   dummy))
+  if (1 != SSCANF (value, "%llu%1s", val, dummy))
   {
   {
     FPRINTF (stderr,
     FPRINTF (stderr,
-             _("You must pass a number to the `%s' option.\n"),
+             _ ("You must pass a number to the `%s' option.\n"),
              option);
              option);
     return GNUNET_SYSERR;
     return GNUNET_SYSERR;
   }
   }
@@ -581,20 +563,18 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_ulong (char shortName,
 GNUNET_GETOPT_option_ulong (char shortName,
-			    const char *name,
-			    const char *argumentHelp,
-			    const char *description,
-			    unsigned long long *val)
-{
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .argumentHelp = argumentHelp,
-    .description = description,
-    .require_argument = 1,
-    .processor = &set_ulong,
-    .scls = (void *) val
-  };
+                            const char *name,
+                            const char *argumentHelp,
+                            const char *description,
+                            unsigned long long *val)
+{
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .argumentHelp = argumentHelp,
+                                                .description = description,
+                                                .require_argument = 1,
+                                                .processor = &set_ulong,
+                                                .scls = (void *) val};
 
 
   return clo;
   return clo;
 }
 }
@@ -620,14 +600,12 @@ set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
                    const char *value)
                    const char *value)
 {
 {
   struct GNUNET_TIME_Relative *val = scls;
   struct GNUNET_TIME_Relative *val = scls;
-  
-  (void) ctx;  
-  if (GNUNET_OK !=
-      GNUNET_STRINGS_fancy_time_to_relative (value,
-					     val))
+
+  (void) ctx;
+  if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (value, val))
   {
   {
     FPRINTF (stderr,
     FPRINTF (stderr,
-             _("You must pass relative time to the `%s' option.\n"),
+             _ ("You must pass relative time to the `%s' option.\n"),
              option);
              option);
     return GNUNET_SYSERR;
     return GNUNET_SYSERR;
   }
   }
@@ -647,20 +625,18 @@ set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_relative_time (char shortName,
 GNUNET_GETOPT_option_relative_time (char shortName,
-				    const char *name,
-				    const char *argumentHelp,
-				    const char *description,
-				    struct GNUNET_TIME_Relative *val)
-{
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .argumentHelp = argumentHelp,
-    .description = description,
-    .require_argument = 1,
-    .processor = &set_relative_time,
-    .scls = (void *) val
-  };
+                                    const char *name,
+                                    const char *argumentHelp,
+                                    const char *description,
+                                    struct GNUNET_TIME_Relative *val)
+{
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .argumentHelp = argumentHelp,
+                                                .description = description,
+                                                .require_argument = 1,
+                                                .processor = &set_relative_time,
+                                                .scls = (void *) val};
 
 
   return clo;
   return clo;
 }
 }
@@ -688,12 +664,10 @@ set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
   struct GNUNET_TIME_Absolute *val = scls;
   struct GNUNET_TIME_Absolute *val = scls;
 
 
   (void) ctx;
   (void) ctx;
-  if (GNUNET_OK !=
-      GNUNET_STRINGS_fancy_time_to_absolute (value,
-					     val))
+  if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (value, val))
   {
   {
     FPRINTF (stderr,
     FPRINTF (stderr,
-             _("You must pass absolute time to the `%s' option.\n"),
+             _ ("You must pass absolute time to the `%s' option.\n"),
              option);
              option);
     return GNUNET_SYSERR;
     return GNUNET_SYSERR;
   }
   }
@@ -713,20 +687,18 @@ set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_absolute_time (char shortName,
 GNUNET_GETOPT_option_absolute_time (char shortName,
-				    const char *name,
-				    const char *argumentHelp,
-				    const char *description,
-				    struct GNUNET_TIME_Absolute *val)
-{
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .argumentHelp = argumentHelp,
-    .description = description,
-    .require_argument = 1,
-    .processor = &set_absolute_time,
-    .scls = (void *) val
-  };
+                                    const char *name,
+                                    const char *argumentHelp,
+                                    const char *description,
+                                    struct GNUNET_TIME_Absolute *val)
+{
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .argumentHelp = argumentHelp,
+                                                .description = description,
+                                                .require_argument = 1,
+                                                .processor = &set_absolute_time,
+                                                .scls = (void *) val};
 
 
   return clo;
   return clo;
 }
 }
@@ -755,20 +727,18 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
   char dummy[2];
   char dummy[2];
 
 
   (void) ctx;
   (void) ctx;
-  if('-' == *value)
+  if ('-' == *value)
   {
   {
-	FPRINTF (stderr,
-		_("Your input for the '%s' option has to be a non negative number \n"),
-		option);
-    	return GNUNET_SYSERR;
+    FPRINTF (stderr,
+             _ (
+               "Your input for the '%s' option has to be a non negative number \n"),
+             option);
+    return GNUNET_SYSERR;
   }
   }
-  if (1 != SSCANF (value,
-                   "%u%1s",
-                   val,
-		   dummy))
+  if (1 != SSCANF (value, "%u%1s", val, dummy))
   {
   {
     FPRINTF (stderr,
     FPRINTF (stderr,
-             _("You must pass a number to the `%s' option.\n"),
+             _ ("You must pass a number to the `%s' option.\n"),
              option);
              option);
     return GNUNET_SYSERR;
     return GNUNET_SYSERR;
   }
   }
@@ -787,26 +757,23 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_uint (char shortName,
 GNUNET_GETOPT_option_uint (char shortName,
-			   const char *name,
-			   const char *argumentHelp,
-			   const char *description,
-			   unsigned int *val)
-{
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .argumentHelp = argumentHelp,
-    .description = description,
-    .require_argument = 1,
-    .processor = &set_uint,
-    .scls = (void *) val
-  };
+                           const char *name,
+                           const char *argumentHelp,
+                           const char *description,
+                           unsigned int *val)
+{
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .argumentHelp = argumentHelp,
+                                                .description = description,
+                                                .require_argument = 1,
+                                                .processor = &set_uint,
+                                                .scls = (void *) val};
 
 
   return clo;
   return clo;
 }
 }
 
 
 
 
-
 /**
 /**
  * Set an option of type 'uint16_t' from the command line.
  * Set an option of type 'uint16_t' from the command line.
  * A pointer to this function should be passed as part of the
  * A pointer to this function should be passed as part of the
@@ -822,30 +789,27 @@ GNUNET_GETOPT_option_uint (char shortName,
  */
  */
 static int
 static int
 set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
 set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
-	    void *scls,
-	    const char *option,
-	    const char *value)
+            void *scls,
+            const char *option,
+            const char *value)
 {
 {
   uint16_t *val = scls;
   uint16_t *val = scls;
   unsigned int v;
   unsigned int v;
   char dummy[2];
   char dummy[2];
-  
+
   (void) ctx;
   (void) ctx;
-  if (1 != SSCANF (value,
-                   "%u%1s",
-                   &v,
-		   dummy))
+  if (1 != SSCANF (value, "%u%1s", &v, dummy))
   {
   {
     FPRINTF (stderr,
     FPRINTF (stderr,
-             _("You must pass a number to the `%s' option.\n"),
+             _ ("You must pass a number to the `%s' option.\n"),
              option);
              option);
     return GNUNET_SYSERR;
     return GNUNET_SYSERR;
   }
   }
   if (v > UINT16_MAX)
   if (v > UINT16_MAX)
   {
   {
     FPRINTF (stderr,
     FPRINTF (stderr,
-             _("You must pass a number below %u to the `%s' option.\n"),
-	     (unsigned int) UINT16_MAX,
+             _ ("You must pass a number below %u to the `%s' option.\n"),
+             (unsigned int) UINT16_MAX,
              option);
              option);
     return GNUNET_SYSERR;
     return GNUNET_SYSERR;
   }
   }
@@ -865,20 +829,18 @@ set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_uint16 (char shortName,
 GNUNET_GETOPT_option_uint16 (char shortName,
-			     const char *name,
-			     const char *argumentHelp,
-			     const char *description,
-			     uint16_t *val)
-{
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .argumentHelp = argumentHelp,
-    .description = description,
-    .require_argument = 1,
-    .processor = &set_uint16,
-    .scls = (void *) val
-  };
+                             const char *name,
+                             const char *argumentHelp,
+                             const char *description,
+                             uint16_t *val)
+{
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .argumentHelp = argumentHelp,
+                                                .description = description,
+                                                .require_argument = 1,
+                                                .processor = &set_uint16,
+                                                .scls = (void *) val};
 
 
   return clo;
   return clo;
 }
 }
@@ -923,15 +885,16 @@ set_base32 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
   struct Base32Context *bc = scls;
   struct Base32Context *bc = scls;
 
 
   (void) ctx;
   (void) ctx;
-  if (GNUNET_OK !=
-      GNUNET_STRINGS_string_to_data (value,
-                                     strlen (value),
-                                     bc->val,
-                                     bc->val_size))
+  if (GNUNET_OK != GNUNET_STRINGS_string_to_data (value,
+                                                  strlen (value),
+                                                  bc->val,
+                                                  bc->val_size))
   {
   {
-    fprintf (stderr,
-             _("Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
-             option);
+    fprintf (
+      stderr,
+      _ (
+        "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
+      option);
     return GNUNET_SYSERR;
     return GNUNET_SYSERR;
   }
   }
   return GNUNET_OK;
   return GNUNET_OK;
@@ -964,23 +927,21 @@ free_bc (void *cls)
  */
  */
 struct GNUNET_GETOPT_CommandLineOption
 struct GNUNET_GETOPT_CommandLineOption
 GNUNET_GETOPT_option_base32_fixed_size (char shortName,
 GNUNET_GETOPT_option_base32_fixed_size (char shortName,
-                                            const char *name,
-                                            const char *argumentHelp,
-                                            const char *description,
-                                            void *val,
-                                            size_t val_size)
+                                        const char *name,
+                                        const char *argumentHelp,
+                                        const char *description,
+                                        void *val,
+                                        size_t val_size)
 {
 {
   struct Base32Context *bc = GNUNET_new (struct Base32Context);
   struct Base32Context *bc = GNUNET_new (struct Base32Context);
-  struct GNUNET_GETOPT_CommandLineOption clo = {
-    .shortName =  shortName,
-    .name = name,
-    .argumentHelp = argumentHelp,
-    .description = description,
-    .require_argument = 1,
-    .processor = &set_base32,
-    .cleaner = &free_bc,
-    .scls = (void *) bc
-  };
+  struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName,
+                                                .name = name,
+                                                .argumentHelp = argumentHelp,
+                                                .description = description,
+                                                .require_argument = 1,
+                                                .processor = &set_base32,
+                                                .cleaner = &free_bc,
+                                                .scls = (void *) bc};
 
 
   bc->val = val;
   bc->val = val;
   bc->val_size = val_size;
   bc->val_size = val_size;
@@ -1002,4 +963,18 @@ GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt)
 }
 }
 
 
 
 
+/**
+ * Make the given option mutually exclusive with other options.
+ *
+ * @param opt option to modify
+ * @return @a opt with the exclusive flag set.
+ */
+struct GNUNET_GETOPT_CommandLineOption
+GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt)
+{
+  opt.option_exclusive = 1;
+  return opt;
+}
+
+
 /* end of getopt_helpers.c */
 /* end of getopt_helpers.c */

+ 81 - 100
src/util/gnunet-config.c

@@ -103,18 +103,12 @@ print_option (void *cls,
       fn = value_fn;
       fn = value_fn;
     else
     else
       GNUNET_free (value_fn);
       GNUNET_free (value_fn);
-    fprintf (stdout,
-             "%s = %s\n",
-             option,
-             fn);
+    fprintf (stdout, "%s = %s\n", option, fn);
     GNUNET_free (fn);
     GNUNET_free (fn);
   }
   }
   else
   else
   {
   {
-    fprintf (stdout,
-             "%s = %s\n",
-             option,
-             value);
+    fprintf (stdout, "%s = %s\n", option, value);
   }
   }
 }
 }
 
 
@@ -126,13 +120,10 @@ print_option (void *cls,
  * @param section a section in the configuration file
  * @param section a section in the configuration file
  */
  */
 static void
 static void
-print_section_name (void *cls,
-                    const char *section)
+print_section_name (void *cls, const char *section)
 {
 {
   (void) cls;
   (void) cls;
-  fprintf (stdout,
-           "%s\n",
-           section);
+  fprintf (stdout, "%s\n", section);
 }
 }
 
 
 
 
@@ -161,9 +152,7 @@ run (void *cls,
   {
   {
     char *name;
     char *name;
 
 
-    GNUNET_asprintf (&name,
-		     "libgnunet_plugin_%s",
-		     backend_check);
+    GNUNET_asprintf (&name, "libgnunet_plugin_%s", backend_check);
     global_ret = (GNUNET_OK == GNUNET_PLUGIN_test (name)) ? 0 : 77;
     global_ret = (GNUNET_OK == GNUNET_PLUGIN_test (name)) ? 0 : 77;
     GNUNET_free (name);
     GNUNET_free (name);
     return;
     return;
@@ -173,40 +162,34 @@ run (void *cls,
     struct GNUNET_CONFIGURATION_Handle *def;
     struct GNUNET_CONFIGURATION_Handle *def;
 
 
     def = GNUNET_CONFIGURATION_create ();
     def = GNUNET_CONFIGURATION_create ();
-    if (GNUNET_OK !=
-        GNUNET_CONFIGURATION_load (def, NULL))
+    if (GNUNET_OK != GNUNET_CONFIGURATION_load (def, NULL))
     {
     {
-      fprintf (stderr,
-               _("failed to load configuration defaults"));
+      fprintf (stderr, _ ("failed to load configuration defaults"));
       global_ret = 1;
       global_ret = 1;
       return;
       return;
     }
     }
-    diff = GNUNET_CONFIGURATION_get_diff (def,
-                                          cfg);
+    diff = GNUNET_CONFIGURATION_get_diff (def, cfg);
     cfg = diff;
     cfg = diff;
   }
   }
-  if ( ((! rewrite) && (NULL == section)) || list_sections)
+  if (((! rewrite) && (NULL == section)) || list_sections)
   {
   {
     if (! list_sections)
     if (! list_sections)
     {
     {
       fprintf (stderr,
       fprintf (stderr,
-               _("%s or %s argument is required\n"),
+               _ ("%s or %s argument is required\n"),
                "--section",
                "--section",
                "--list-sections");
                "--list-sections");
       global_ret = 1;
       global_ret = 1;
     }
     }
     else
     else
     {
     {
-      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);
     }
     }
     goto cleanup;
     goto cleanup;
   }
   }
 
 
-  if ( (NULL != section) && (NULL == value) )
+  if ((NULL != section) && (NULL == value))
   {
   {
     if (NULL == option)
     if (NULL == option)
     {
     {
@@ -219,26 +202,24 @@ run (void *cls,
     {
     {
       if (is_filename)
       if (is_filename)
       {
       {
-        if (GNUNET_OK !=
-            GNUNET_CONFIGURATION_get_value_filename (cfg,
-                                                     section,
-                                                     option,
-                                                     &value))
+        if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+                                                                  section,
+                                                                  option,
+                                                                  &value))
         {
         {
-          GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
-                                     section, option);
+          GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, option);
           global_ret = 3;
           global_ret = 3;
           goto cleanup;
           goto cleanup;
         }
         }
       }
       }
       else
       else
       {
       {
-        if (GNUNET_OK !=
-            GNUNET_CONFIGURATION_get_value_string (cfg, section,
-                                                   option, &value))
+        if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+                                                                section,
+                                                                option,
+                                                                &value))
         {
         {
-          GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
-                                     section, option);
+          GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, option);
           global_ret = 3;
           global_ret = 3;
           goto cleanup;
           goto cleanup;
         }
         }
@@ -250,15 +231,12 @@ run (void *cls,
   {
   {
     if (NULL == option)
     if (NULL == option)
     {
     {
-      fprintf (stderr, _("--option argument required to set value\n"));
+      fprintf (stderr, _ ("--option argument required to set value\n"));
       global_ret = 1;
       global_ret = 1;
       goto cleanup;
       goto cleanup;
     }
     }
     out = GNUNET_CONFIGURATION_dup (cfg);
     out = GNUNET_CONFIGURATION_dup (cfg);
-    GNUNET_CONFIGURATION_set_value_string (out,
-                                           section,
-                                           option,
-                                           value);
+    GNUNET_CONFIGURATION_set_value_string (out, section, option, value);
   }
   }
   cfg_fn = NULL;
   cfg_fn = NULL;
   if (NULL == cfgfile)
   if (NULL == cfgfile)
@@ -274,11 +252,10 @@ run (void *cls,
       cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
       cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
     cfgfile = cfg_fn;
     cfgfile = cfg_fn;
   }
   }
-  if ( (NULL != diff) || (NULL != out) )
+  if ((NULL != diff) || (NULL != out))
   {
   {
     if (GNUNET_OK !=
     if (GNUNET_OK !=
-        GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out,
-                                    cfgfile))
+        GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, cfgfile))
       global_ret = 2;
       global_ret = 2;
   }
   }
   GNUNET_free_non_null (cfg_fn);
   GNUNET_free_non_null (cfg_fn);
@@ -298,62 +275,66 @@ cleanup:
  * @return 0 ok, 1 on error
  * @return 0 ok, 1 on error
  */
  */
 int
 int
-main (int argc,
-      char *const *argv)
+main (int argc, char *const *argv)
 {
 {
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_option_flag ('f',
-      "filename",
-      gettext_noop ("interpret option value as a filename (with $-expansion)"),
-      &is_filename),
-    //GNUNET_GETOPT_option_exclusive
-    (GNUNET_GETOPT_option_string ('b',
-				 "supported-backend",
-				  "BACKEND",
-				  gettext_noop ("test if the current installation supports the specified BACKEND"),
-				  &backend_check)),
-    GNUNET_GETOPT_option_string ('s',
-                                "section",
-                                "SECTION",
-                                gettext_noop ("name of the section to access"),
-                                &section),
-    GNUNET_GETOPT_option_string ('o',
-                                 "option",
-                                 "OPTION",
-                                 gettext_noop ("name of the option to access"),
-                                 &option),
-    GNUNET_GETOPT_option_string ('V',
-                                 "value",
-                                 "VALUE",
-                                 gettext_noop ("value to set"),
-                                 &value),
-    GNUNET_GETOPT_option_flag ('S',
-                       "list-sections",
-                       gettext_noop ("print available configuration sections"),
-                       &list_sections),
-    GNUNET_GETOPT_option_flag ('w',
-                               "rewrite",
-                               gettext_noop ("write configuration file that only contains delta to defaults"),
-                               &rewrite),
-    GNUNET_GETOPT_OPTION_END
-  };
+  struct GNUNET_GETOPT_CommandLineOption options[] =
+    {GNUNET_GETOPT_option_flag (
+       'f',
+       "filename",
+       gettext_noop ("interpret option value as a filename (with $-expansion)"),
+       &is_filename),
+     GNUNET_GETOPT_option_exclusive (GNUNET_GETOPT_option_string (
+       'b',
+       "supported-backend",
+       "BACKEND",
+       gettext_noop (
+         "test if the current installation supports the specified BACKEND"),
+       &backend_check)),
+     GNUNET_GETOPT_option_string ('s',
+                                  "section",
+                                  "SECTION",
+                                  gettext_noop (
+                                    "name of the section to access"),
+                                  &section),
+     GNUNET_GETOPT_option_string ('o',
+                                  "option",
+                                  "OPTION",
+                                  gettext_noop ("name of the option to access"),
+                                  &option),
+     GNUNET_GETOPT_option_string ('V',
+                                  "value",
+                                  "VALUE",
+                                  gettext_noop ("value to set"),
+                                  &value),
+     GNUNET_GETOPT_option_flag ('S',
+                                "list-sections",
+                                gettext_noop (
+                                  "print available configuration sections"),
+                                &list_sections),
+     GNUNET_GETOPT_option_flag (
+       'w',
+       "rewrite",
+       gettext_noop (
+         "write configuration file that only contains delta to defaults"),
+       &rewrite),
+     GNUNET_GETOPT_OPTION_END};
   int ret;
   int ret;
-	  
-  if (GNUNET_OK !=
-      GNUNET_STRINGS_get_utf8_args (argc, argv,
-                                    &argc, &argv))
+
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
     return 2;
     return 2;
 
 
-  ret = GNUNET_PROGRAM_run (argc,
-			    argv,
-			    "gnunet-config [OPTIONS]",
-			    gettext_noop ("Manipulate GNUnet configuration files"),
-			    options,
-			    &run, NULL);
-  GNUNET_free ((void*) argv);
+  ret =
+    GNUNET_PROGRAM_run (argc,
+                        argv,
+                        "gnunet-config [OPTIONS]",
+                        gettext_noop ("Manipulate GNUnet configuration files"),
+                        options,
+                        &run,
+                        NULL);
+  GNUNET_free ((void *) argv);
   if (GNUNET_OK == ret)
   if (GNUNET_OK == ret)
     return global_ret;
     return global_ret;
-  return 1;
+  return ret;
 }
 }
 
 
 /* end of gnunet-config.c */
 /* end of gnunet-config.c */