Command line parsing and –help formatting. More...
Data Structures | |
struct | GNUNET_GETOPT_CommandLineProcessorContext |
General context for command line processors. More... | |
struct | GNUNET_GETOPT_CommandLineOption |
Definition of a command line option. More... | |
Macros | |
#define | GNUNET_GETOPT_option_base32_auto(shortName, name, argumentHelp, description, val) |
Allow user to specify a binary value using Crockford Base32 encoding where the size of the binary value is automatically determined from its type. More... | |
#define | GNUNET_GETOPT_OPTION_END |
Marker for the end of the list of options. More... | |
Typedefs | |
typedef int(* | GNUNET_GETOPT_CommandLineOptionProcessor) (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value) |
Process a command line option. More... | |
Functions | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_help (const struct GNUNET_OS_ProjectData *pd, const char *about) |
Defining the option to print the command line help text (-h option). More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_timetravel (char shortName, const char *name) |
Allow user to specify a long long with an offset to add to the current system time to construct the time seen by the application. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_version (const char *version) |
Define the option to print the version of the application (-v option) More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_logfile (char **logfn) |
Allow user to specify log file name (-l option) More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_string (char shortName, const char *name, const char *argumentHelp, const char *description, char **str) |
Allow user to specify a string. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_filename (char shortName, const char *name, const char *argumentHelp, const char *description, char **str) |
Allow user to specify a filename (automatically path expanded). More... | |
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) |
Allow user to specify a binary value using Crockford Base32 encoding. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_flag (char shortName, const char *name, const char *description, int *val) |
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_uint (char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val) |
Allow user to specify an unsigned int . More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_uint16 (char shortName, const char *name, const char *argumentHelp, const char *description, uint16_t *val) |
Allow user to specify an uint16_t. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_ulong (char shortName, const char *name, const char *argumentHelp, const char *description, unsigned long long *val) |
Allow user to specify an unsigned long long . More... | |
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) |
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time). More... | |
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) |
Allow user to specify a struct GNUNET_TIME_Absolute (using human-readable "fancy" time). More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_timestamp (char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Timestamp *val) |
Allow user to specify a struct GNUNET_TIME_Timestamp (using human-readable "fancy" time). More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_increment_uint (char shortName, const char *name, const char *description, unsigned int *val) |
Increment val each time the option flag is given by one. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_loglevel (char **level) |
Define the '-L' log level option. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_verbose (unsigned int *level) |
Define the '-V' verbosity option. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_cfgfile (char **fn) |
Allow user to specify configuration file name (-c option) More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt) |
Make the given option mandatory. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt) |
Make the given option mutually exclusive with other options. More... | |
int | GNUNET_GETOPT_run (const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv) |
Parse the command line. More... | |
Command line parsing and –help formatting.
#define GNUNET_GETOPT_option_base32_auto | ( | shortName, | |
name, | |||
argumentHelp, | |||
description, | |||
val | |||
) |
Allow user to specify a binary value using Crockford Base32 encoding where the size of the binary value is automatically determined from its type.
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | binary value decoded from Crockford Base32-encoded argument; size is determined by type (sizeof (*val)). |
Definition at line 275 of file gnunet_getopt_lib.h.
#define GNUNET_GETOPT_OPTION_END |
Marker for the end of the list of options.
Definition at line 476 of file gnunet_getopt_lib.h.
typedef int(* GNUNET_GETOPT_CommandLineOptionProcessor) (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value) |
Process a command line option.
ctx | context for all options |
scls | specific closure (for this processor) |
option | long name of the option (e.g. "config" for –config) |
value | argument, NULL if none was given |
Definition at line 99 of file gnunet_getopt_lib.h.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help | ( | const struct GNUNET_OS_ProjectData * | pd, |
const char * | about | ||
) |
Defining the option to print the command line help text (-h option).
pd | project data to determine details about the application |
about | string with brief description of the application |
Definition at line 200 of file getopt_helpers.c.
References format_help(), gettext_noop, and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), and main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_timetravel | ( | char | shortName, |
const char * | name | ||
) |
Allow user to specify a long long
with an offset to add to the current system time to construct the time seen by the application.
Used for debugging / testing.
shortName | short name of the option | |
name | long name of the option | |
[out] | val | set to the time specified at the command line |
Definition at line 600 of file getopt_helpers.c.
References _, name, set_timetravel_time(), and GNUNET_GETOPT_CommandLineOption::shortName.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version | ( | const char * | version | ) |
Define the option to print the version of the application (-v option)
version | string with the version number |
Definition at line 60 of file getopt_helpers.c.
References gettext_noop, print_version(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), and main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile | ( | char ** | logfn | ) |
Allow user to specify log file name (-l option)
[out] | logfn | set to the name of the logfile |
Definition at line 449 of file getopt_helpers.c.
References gettext_noop, set_filename(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), and main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string | ( | char | shortName, |
const char * | name, | ||
const char * | argumentHelp, | ||
const char * | description, | ||
char ** | str | ||
) |
Allow user to specify a string.
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | str | set to the string |
Definition at line 362 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_string(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_filename | ( | char | shortName, |
const char * | name, | ||
const char * | argumentHelp, | ||
const char * | description, | ||
char ** | str | ||
) |
Allow user to specify a filename (automatically path expanded).
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | str | set to the string |
Definition at line 428 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_filename(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by main().
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 | ||
) |
Allow user to specify a binary value using Crockford Base32 encoding.
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | binary value decoded from Crockford Base32-encoded argument |
val_size | size of val in bytes |
Definition at line 987 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, free_bc(), GNUNET_new, name, set_base32(), GNUNET_GETOPT_CommandLineOption::shortName, Base32Context::val, and Base32Context::val_size.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag | ( | char | shortName, |
const char * | name, | ||
const char * | description, | ||
int * | val | ||
) |
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
shortName | short name of the option | |
name | long name of the option | |
description | long help text for the option | |
[out] | val | set to 1 if the option is present |
Definition at line 313 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::description, name, set_one(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by GNUNET_PROGRAM_conf_and_options(), GNUNET_SERVICE_run_(), and main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint | ( | char | shortName, |
const char * | name, | ||
const char * | argumentHelp, | ||
const char * | description, | ||
unsigned int * | val | ||
) |
Allow user to specify an unsigned int
.
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | set to the value specified at the command line |
Definition at line 832 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_uint(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint16 | ( | char | shortName, |
const char * | name, | ||
const char * | argumentHelp, | ||
const char * | description, | ||
uint16_t * | val | ||
) |
Allow user to specify an uint16_t.
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | set to the value specified at the command line |
Definition at line 897 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_uint16(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_ulong | ( | char | shortName, |
const char * | name, | ||
const char * | argumentHelp, | ||
const char * | description, | ||
unsigned long long * | val | ||
) |
Allow user to specify an unsigned long long
.
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | set to the value specified at the command line |
Definition at line 518 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_ulong(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by main().
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 | ||
) |
Allow user to specify a struct GNUNET_TIME_Relative
(using human-readable "fancy" time).
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | set to the time specified at the command line |
Definition at line 651 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_relative_time(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by main().
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 | ||
) |
Allow user to specify a struct GNUNET_TIME_Absolute
(using human-readable "fancy" time).
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | set to the time specified at the command line |
Definition at line 705 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_absolute_time(), and GNUNET_GETOPT_CommandLineOption::shortName.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_timestamp | ( | char | shortName, |
const char * | name, | ||
const char * | argumentHelp, | ||
const char * | description, | ||
struct GNUNET_TIME_Timestamp * | val | ||
) |
Allow user to specify a struct GNUNET_TIME_Timestamp
(using human-readable "fancy" time).
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | set to the time specified at the command line |
Definition at line 769 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_timestamp(), and GNUNET_GETOPT_CommandLineOption::shortName.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_increment_uint | ( | char | shortName, |
const char * | name, | ||
const char * | description, | ||
unsigned int * | val | ||
) |
Increment val each time the option flag is given by one.
shortName | short name of the option | |
name | long name of the option | |
description | long help text for the option | |
[out] | val | set to 1 if the option is present |
Definition at line 249 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::description, increment_value(), name, and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel | ( | char ** | level | ) |
Define the '-L' log level option.
Note that we do not check that the log level is valid here.
[out] | level | set to the log level |
Definition at line 383 of file getopt_helpers.c.
References gettext_noop, set_string(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), and main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose | ( | unsigned int * | level | ) |
Define the '-V' verbosity option.
Using the option more than once increments level each time.
[out] | level | set to the verbosity level |
Definition at line 267 of file getopt_helpers.c.
References gettext_noop, increment_value(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile | ( | char ** | fn | ) |
Allow user to specify configuration file name (-c option)
[out] | fn | set to the name of the configuration file |
Definition at line 467 of file getopt_helpers.c.
References gettext_noop, set_filename(), and GNUNET_GETOPT_CommandLineOption::shortName.
Referenced by GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), and main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory | ( | struct GNUNET_GETOPT_CommandLineOption | opt | ) |
Make the given option mandatory.
opt | option to modify |
Definition at line 1013 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::option_mandatory.
Referenced by main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_exclusive | ( | struct GNUNET_GETOPT_CommandLineOption | opt | ) |
Make the given option mutually exclusive with other options.
opt | option to modify |
Definition at line 1021 of file getopt_helpers.c.
References GNUNET_GETOPT_CommandLineOption::option_exclusive.
Referenced by main().
int GNUNET_GETOPT_run | ( | const char * | binaryOptions, |
const struct GNUNET_GETOPT_CommandLineOption * | allOptions, | ||
unsigned int | argc, | ||
char *const * | argv | ||
) |
Parse the command line.
binaryOptions | Name of application with option summary |
allOptions | defined options and handlers |
argc | number of arguments in argv |
argv | actual arguments |
Definition at line 884 of file getopt.c.
References _, GNUNET_GETOPT_CommandLineProcessorContext::allOptions, GNUNET_GETOPT_CommandLineProcessorContext::argc, GNUNET_GETOPT_CommandLineProcessorContext::argv, GNUNET_GETOPT_CommandLineProcessorContext::binaryName, GNUNET_GETOPT_CommandLineProcessorContext::binaryOptions, GNUNET_GETOPT_CommandLineOption::cleaner, GNUNET_GETOPT_CommandLineProcessorContext::currentArgument, GNoption::flag, GNgetopt_long(), GNoptarg, GNoptind, GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_new_array, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNoption::has_arg, name, GNUNET_GETOPT_CommandLineOption::name, GNoption::name, GNUNET_GETOPT_CommandLineOption::processor, GNUNET_GETOPT_CommandLineOption::require_argument, GNUNET_GETOPT_CommandLineOption::shortName, and GNoption::val.
Referenced by GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), and main().