tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / util / getopt.c
index 85f67500c85bd0317778287f3ea33934cd873edc..5e8571ee571c7ca8f18250fb7d01ac1921a2b641 100644 (file)
@@ -3,7 +3,7 @@
    "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
    before changing it!
 
-   Copyright Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97
+   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97
      Free Software Foundation, Inc.
 
 NOTE: The canonical source of this file is maintained with the GNU C Library.
@@ -26,7 +26,7 @@ USA.
 
 
 This code was heavily modified for GNUnet.
-Copyright Copyright (C) 2006, 2017 Christian Grothoff
+Copyright (C) 2006, 2017 Christian Grothoff
 */
 
 /**
@@ -866,7 +866,7 @@ GNgetopt_long (int argc,
  * @param argc number of arguments
  * @param argv actual arguments
  * @return index into argv with first non-option
- *   argument, or -1 on error
+ *   argument, or #GNUNET_SYSERR on error
  */
 int
 GNUNET_GETOPT_run (const char *binaryOptions,
@@ -881,6 +881,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
   int spos;
   int cont;
   int c;
+  uint8_t *seen;
 
   GNUNET_assert (argc > 0);
   GNoptind = 0;
@@ -893,6 +894,8 @@ GNUNET_GETOPT_run (const char *binaryOptions,
 
   long_options = GNUNET_new_array (count + 1,
                                    struct GNoption);
+  seen = GNUNET_new_array (count,
+                           uint8_t);
   shorts = GNUNET_malloc (count * 2 + 1);
   spos = 0;
   for (unsigned i = 0; i < count; i++)
@@ -934,6 +937,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
                                         allOptions[i].scls,
                                         allOptions[i].name,
                                         GNoptarg);
+        seen[i] = 1;
         break;
       }
     }
@@ -948,10 +952,24 @@ GNUNET_GETOPT_run (const char *binaryOptions,
   GNUNET_free (shorts);
   GNUNET_free (long_options);
 
+  if (GNUNET_YES == cont)
+  {
+    for (count = 0; NULL != allOptions[count].name; count++)
+      if ( (0 == seen[count]) &&
+           (allOptions[count].option_mandatory) )
+      {
+        FPRINTF (stderr,
+                 _("Missing mandatory option `%s'.\n"),
+                 allOptions[count].name);
+        cont = GNUNET_SYSERR;
+      }
+  }
+  GNUNET_free (seen);
+
   /* call cleaners, if available */
-  for (count = 0; NULL != allOptions[count].name; count++)
-    if (NULL != allOptions[count].cleaner)
-      allOptions[count].cleaner (allOptions[count].scls);
+  for (unsigned int i = 0; NULL != allOptions[i].name; i++)
+    if (NULL != allOptions[i].cleaner)
+      allOptions[i].cleaner (allOptions[i].scls);
 
   if (GNUNET_OK != cont)
     return cont;