diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-15 11:14:36 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-15 11:14:59 +0100 |
commit | f09c53eb6f8c540cc3bc3730f9e34be596ed3716 (patch) | |
tree | 524957bd395bfca32e006163d44601936bf2afda /src/util/getopt.c | |
parent | dc0d60c9c8a635221c0d656611f8f93e0256ed84 (diff) | |
download | gnunet-f09c53eb6f8c540cc3bc3730f9e34be596ed3716.tar.gz gnunet-f09c53eb6f8c540cc3bc3730f9e34be596ed3716.zip |
add way to mark options as mandatory, get tests to pass again
Diffstat (limited to 'src/util/getopt.c')
-rw-r--r-- | src/util/getopt.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/util/getopt.c b/src/util/getopt.c index 85f67500c..036e0f4be 100644 --- a/src/util/getopt.c +++ b/src/util/getopt.c | |||
@@ -881,6 +881,7 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
881 | int spos; | 881 | int spos; |
882 | int cont; | 882 | int cont; |
883 | int c; | 883 | int c; |
884 | uint8_t *seen; | ||
884 | 885 | ||
885 | GNUNET_assert (argc > 0); | 886 | GNUNET_assert (argc > 0); |
886 | GNoptind = 0; | 887 | GNoptind = 0; |
@@ -893,6 +894,8 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
893 | 894 | ||
894 | long_options = GNUNET_new_array (count + 1, | 895 | long_options = GNUNET_new_array (count + 1, |
895 | struct GNoption); | 896 | struct GNoption); |
897 | seen = GNUNET_new_array (count, | ||
898 | uint8_t); | ||
896 | shorts = GNUNET_malloc (count * 2 + 1); | 899 | shorts = GNUNET_malloc (count * 2 + 1); |
897 | spos = 0; | 900 | spos = 0; |
898 | for (unsigned i = 0; i < count; i++) | 901 | for (unsigned i = 0; i < count; i++) |
@@ -934,6 +937,7 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
934 | allOptions[i].scls, | 937 | allOptions[i].scls, |
935 | allOptions[i].name, | 938 | allOptions[i].name, |
936 | GNoptarg); | 939 | GNoptarg); |
940 | seen[i] = 1; | ||
937 | break; | 941 | break; |
938 | } | 942 | } |
939 | } | 943 | } |
@@ -948,6 +952,20 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
948 | GNUNET_free (shorts); | 952 | GNUNET_free (shorts); |
949 | GNUNET_free (long_options); | 953 | GNUNET_free (long_options); |
950 | 954 | ||
955 | if (GNUNET_YES == cont) | ||
956 | { | ||
957 | for (count = 0; NULL != allOptions[count].name; count++) | ||
958 | if ( (0 == seen[count]) && | ||
959 | (allOptions[count].option_mandatory) ) | ||
960 | { | ||
961 | FPRINTF (stderr, | ||
962 | _("Missing mandatory option `%s'.\n"), | ||
963 | allOptions[count].name); | ||
964 | cont = GNUNET_SYSERR; | ||
965 | } | ||
966 | } | ||
967 | GNUNET_free (seen); | ||
968 | |||
951 | /* call cleaners, if available */ | 969 | /* call cleaners, if available */ |
952 | for (count = 0; NULL != allOptions[count].name; count++) | 970 | for (count = 0; NULL != allOptions[count].name; count++) |
953 | if (NULL != allOptions[count].cleaner) | 971 | if (NULL != allOptions[count].cleaner) |