gettext_noop ("don't let gnunet-service-arm inherit standard error"),
&no_stderr),
GNUNET_GETOPT_OPTION_END};
+ int lret;
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
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);
return ret;
}
GNUNET_free ((void *) argv);
- return 1;
+ return lret;
}
/* end of gnunet-arm.c */
* - channel: logical link between two clients, on the same or different peers.
* have properties like reliability.
*/
-
#include "platform.h"
#include "gnunet_util_lib.h"
#include "cadet.h"
#define GNUNET_GETOPT_LIB_H
#ifdef __cplusplus
-extern "C"
-{
-#if 0 /* keep Emacsens' auto-indent happy */
+extern "C" {
+#if 0 /* keep Emacsens' auto-indent happy */
}
#endif
#endif
* Current argument.
*/
unsigned int currentArgument;
-
};
* @param value argument, NULL if none was given
* @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);
/**
* Function to call on @e scls to clean up after processing all
* the arguments. Can be NULL.
*/
- void (*cleaner)(void *cls);
+ void (*cleaner) (void *cls);
/**
* Specific closure to pass to the processor.
*/
void *scls;
-
};
GNUNET_GETOPT_option_version (const char *version);
-
/**
* Allow user to specify log file name (-l option)
*
* @param[out] val binary value decoded from Crockford Base32-encoded argument;
* 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))
/**
*/
struct GNUNET_GETOPT_CommandLineOption
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);
/**
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.
*/
-#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 \
+ }
/**
char *const *argv);
-#if 0 /* keep Emacsens' auto-indent happy */
+#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
#ifdef __cplusplus
"name of the ego controlling the zone"),
&ego_name),
GNUNET_GETOPT_OPTION_END};
+ int lret;
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
is_public = -1;
is_shadow = -1;
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_CRYPTO_ecdsa_key_clear (&zone_pkey);
- return 1;
+ return lret;
}
GNUNET_free ((void *) argv);
GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
#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. */
#include <windows.h>
-#define getpid() GetCurrentProcessId()
+#define getpid() GetCurrentProcessId ()
#endif
#ifndef _
When compiling libc, the _ macro is predefined. */
#ifdef HAVE_LIBINTL_H
#include <libintl.h>
-#define _(msgid) gettext (msgid)
+#define _(msgid) gettext (msgid)
#else
-#define _(msgid) (msgid)
+#define _(msgid) (msgid)
#endif
#endif
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' 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. */
static char *posixly_correct;
-#ifdef __GNU_LIBRARY__
+#ifdef __GNU_LIBRARY__
/* We want to avoid inclusion of string.h with non-GNU libraries
because there are many ways it can cause trouble.
On some systems, it contains special magic macros that don't work
in GCC. */
#include <string.h>
-#define my_index strchr
+#define my_index strchr
#else
/* Avoid depending on library functions or files
getenv ();
static char *
-my_index (const char *str,
- int chr)
+my_index (const char *str, int chr)
{
while (*str)
{
#ifdef __GNUC__
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
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,
and has done so at least since version 2.4.5. -- rms. */
extern int
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
-#if defined (__STDC__) && __STDC__
+#if defined(__STDC__) && __STDC__
static void
exchange (char **);
#endif
/* Initialize the internal data when the first call is made. */
-#if defined (__STDC__) && __STDC__
+#if defined(__STDC__) && __STDC__
static const char *
_getopt_initialize (int, char *const *, const char *);
#endif
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
* is the program name); the sequence of previously skipped
long-named options. */
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)
{
static int __getopt_initialized = 0;
GNoptarg = NULL;
- if (GNoptind == 0 || !__getopt_initialized)
+ if (GNoptind == 0 || ! __getopt_initialized)
{
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);
__getopt_initialized = 1;
}
* Skip it like a null option,
* then exchange with previous non-options as if it were an option,
* then skip everything else like a non-option. */
- if (GNoptind != argc && !strcmp (argv[GNoptind], "--"))
+ if (GNoptind != argc && ! strcmp (argv[GNoptind], "--"))
{
GNoptind++;
* Skip the initial punctuation. */
nextchar =
- (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
+ (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
}
/* Decode the current option-ARGV-element. */
if (longopts != NULL &&
(argv[GNoptind][1] == '-' ||
(long_only &&
- (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1])))))
+ (argv[GNoptind][2] || ! my_index (optstring, argv[GNoptind][1])))))
{
char *nameend;
const struct GNoption *p;
int option_index;
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
- /* Do nothing. */ ;
+ /* Do nothing. */;
/* Test all long options for either exact match
* or abbreviated matches. */
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) ==
(unsigned int) strlen (p->name))
ambig = 1;
}
- if (ambig && !exact)
+ if (ambig && ! exact)
{
if (GNopterr)
- FPRINTF (stderr, _("%s: option `%s' is ambiguous\n"), argv[0],
+ FPRINTF (stderr,
+ _ ("%s: option `%s' is ambiguous\n"),
+ argv[0],
argv[GNoptind]);
nextchar += strlen (nextchar);
GNoptind++;
if (argv[GNoptind - 1][1] == '-')
/* --option */
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
/* +option or -option */
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);
return '?';
{
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);
return (optstring[0] == ':') ? ':' : '?';
* or the option starts with '--' or is not a valid short
* option, then it's an error.
* Otherwise interpret it as a short option. */
- if (!long_only || argv[GNoptind][1] == '-' ||
+ if (! long_only || argv[GNoptind][1] == '-' ||
my_index (optstring, *nextchar) == NULL)
{
if (GNopterr)
{
if (argv[GNoptind][1] == '-')
/* --option */
- FPRINTF (stderr, _("%s: unrecognized option `--%s'\n"), argv[0],
+ FPRINTF (stderr,
+ _ ("%s: unrecognized option `--%s'\n"),
+ argv[0],
nextchar);
else
/* +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 *) "";
GNoptind++;
{
if (posixly_correct)
/* 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
- FPRINTF (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
+ FPRINTF (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
}
return '?';
}
if (GNopterr)
{
/* 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] == ':')
c = ':';
for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
nameend++)
- /* Do nothing. */ ;
+ /* Do nothing. */;
/* Test all long options for either exact match
* or abbreviated matches. */
if (longopts != NULL)
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))
{
/* Second or later nonexact match found. */
ambig = 1;
}
- if (ambig && !exact)
+ if (ambig && ! exact)
{
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]);
nextchar += strlen (nextchar);
GNoptind++;
else
{
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);
return '?';
else
{
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);
return optstring[0] == ':' ? ':' : '?';
}
return pfound->val;
}
nextchar = NULL;
- return 'W'; /* Let the application handle it. */
+ return 'W'; /* Let the application handle it. */
}
if (temp[1] == ':')
{
if (GNopterr)
{
/* 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] == ':')
c = ':';
char *shorts;
int spos;
int cont;
- int c;
uint8_t *seen;
+ unsigned int optmatch = 0;
+ const char *have_exclusive = NULL;
GNUNET_assert (argc > 0);
GNoptind = 0;
clpc.allOptions = allOptions;
clpc.argv = argv;
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);
spos = 0;
for (unsigned i = 0; i < count; i++)
cont = GNUNET_OK;
/* main getopt loop */
- while (GNUNET_OK == cont)
+ while (1)
{
int option_index = 0;
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)
- 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++)
{
clpc.currentArgument = GNoptind - 1;
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;
break;
}
}
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;
}
}
GNUNET_free (shorts);
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)
{
- 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,
- _("Missing mandatory option `%s'.\n"),
+ _ ("Missing mandatory option `%s'.\n"),
allOptions[count].name);
cont = GNUNET_SYSERR;
}
#include "platform.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__)
/**
(void) option;
(void) value;
- printf ("%s v%s\n",
- ctx->binaryName,
- version);
+ printf ("%s v%s\n", ctx->binaryName, version);
return GNUNET_NO;
}
struct GNUNET_GETOPT_CommandLineOption
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;
}
(void) value;
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;
opt = ctx->allOptions;
trans = "";
ml = strlen (trans);
p = 0;
-OUTER:
+ OUTER:
while (ml - p > 78 - slen)
{
for (j = p + 78 - slen; j > (int) p; j--)
struct GNUNET_GETOPT_CommandLineOption
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;
}
*/
struct GNUNET_GETOPT_CommandLineOption
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;
}
struct GNUNET_GETOPT_CommandLineOption
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;
}
*/
struct GNUNET_GETOPT_CommandLineOption
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;
}
const char *description,
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;
}
struct GNUNET_GETOPT_CommandLineOption
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;
}
*/
struct GNUNET_GETOPT_CommandLineOption
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;
}
struct GNUNET_GETOPT_CommandLineOption
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;
}
struct GNUNET_GETOPT_CommandLineOption
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;
}
char dummy[2];
(void) ctx;
- if (1 != SSCANF (value,
- "%llu%1s",
- val,
- dummy))
+ if (1 != SSCANF (value, "%llu%1s", val, dummy))
{
FPRINTF (stderr,
- _("You must pass a number to the `%s' option.\n"),
+ _ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
}
*/
struct GNUNET_GETOPT_CommandLineOption
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;
}
const char *value)
{
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,
- _("You must pass relative time to the `%s' option.\n"),
+ _ ("You must pass relative time to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
}
*/
struct GNUNET_GETOPT_CommandLineOption
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;
}
struct GNUNET_TIME_Absolute *val = scls;
(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,
- _("You must pass absolute time to the `%s' option.\n"),
+ _ ("You must pass absolute time to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
}
*/
struct GNUNET_GETOPT_CommandLineOption
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;
}
char dummy[2];
(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,
- _("You must pass a number to the `%s' option.\n"),
+ _ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
}
*/
struct GNUNET_GETOPT_CommandLineOption
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;
}
-
/**
* Set an option of type 'uint16_t' from the command line.
* A pointer to this function should be passed as part of the
*/
static int
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;
unsigned int v;
char dummy[2];
-
+
(void) ctx;
- if (1 != SSCANF (value,
- "%u%1s",
- &v,
- dummy))
+ if (1 != SSCANF (value, "%u%1s", &v, dummy))
{
FPRINTF (stderr,
- _("You must pass a number to the `%s' option.\n"),
+ _ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
}
if (v > UINT16_MAX)
{
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);
return GNUNET_SYSERR;
}
*/
struct GNUNET_GETOPT_CommandLineOption
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;
}
struct Base32Context *bc = scls;
(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_OK;
*/
struct GNUNET_GETOPT_CommandLineOption
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 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_size = val_size;
}
+/**
+ * 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 */
fn = value_fn;
else
GNUNET_free (value_fn);
- fprintf (stdout,
- "%s = %s\n",
- option,
- fn);
+ fprintf (stdout, "%s = %s\n", option, fn);
GNUNET_free (fn);
}
else
{
- fprintf (stdout,
- "%s = %s\n",
- option,
- value);
+ fprintf (stdout, "%s = %s\n", option, value);
}
}
* @param section a section in the configuration file
*/
static void
-print_section_name (void *cls,
- const char *section)
+print_section_name (void *cls, const char *section)
{
(void) cls;
- fprintf (stdout,
- "%s\n",
- section);
+ fprintf (stdout, "%s\n", section);
}
{
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;
GNUNET_free (name);
return;
struct GNUNET_CONFIGURATION_Handle *def;
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;
return;
}
- diff = GNUNET_CONFIGURATION_get_diff (def,
- cfg);
+ diff = GNUNET_CONFIGURATION_get_diff (def, cfg);
cfg = diff;
}
- if ( ((! rewrite) && (NULL == section)) || list_sections)
+ if (((! rewrite) && (NULL == section)) || list_sections)
{
if (! list_sections)
{
fprintf (stderr,
- _("%s or %s argument is required\n"),
+ _ ("%s or %s argument is required\n"),
"--section",
"--list-sections");
global_ret = 1;
}
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;
}
- if ( (NULL != section) && (NULL == value) )
+ if ((NULL != section) && (NULL == value))
{
if (NULL == option)
{
{
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;
goto cleanup;
}
}
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;
goto cleanup;
}
{
if (NULL == option)
{
- fprintf (stderr, _("--option argument required to set value\n"));
+ fprintf (stderr, _ ("--option argument required to set value\n"));
global_ret = 1;
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);
}
cfg_fn = NULL;
if (NULL == cfgfile)
cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
cfgfile = cfg_fn;
}
- if ( (NULL != diff) || (NULL != out) )
+ if ((NULL != diff) || (NULL != out))
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out,
- cfgfile))
+ GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, cfgfile))
global_ret = 2;
}
GNUNET_free_non_null (cfg_fn);
* @return 0 ok, 1 on error
*/
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"),
- §ion),
- 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"),
+ §ion),
+ 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;
-
- 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;
- 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)
return global_ret;
- return 1;
+ return ret;
}
/* end of gnunet-config.c */