29 #define LOG(kind, ...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__) 47 const char *version = scls;
69 "print the version number"),
70 .option_exclusive = 1,
72 .scls = (
void *) version
99 const char *about =
scls;
116 "Arguments mandatory for long options are also mandatory for short options.\n"));
120 while (NULL != opt[i].description)
122 if (opt[i].shortName ==
'\0')
125 printf (
" -%c, ", opt[i].shortName);
126 printf (
"--%s", opt[i].
name);
127 slen = 8 + strlen (opt[i].name);
128 if (NULL != opt[i].argumentHelp)
130 printf (
"=%s", opt[i].argumentHelp);
131 slen += 1 + strlen (opt[i].argumentHelp);
135 printf (
"\n%*s",
BORDER,
"");
140 printf (
"%*s", (
int) (
BORDER - slen),
"");
143 if (0 < strlen (opt[i].description))
144 trans =
gettext (opt[i].description);
150 while (ml - p > 78 - slen)
152 for (j = p + 78 - slen; j > (int) p; j--)
154 if (isspace ((
unsigned char) trans[j]))
159 printf (
"%s\n%*s", scp,
BORDER + 2,
"");
169 scp[78 - slen] =
'\0';
170 printf (
"%s\n%*s", scp,
BORDER + 2,
"");
177 printf (
"%s\n", &trans[p]);
178 if (strlen (trans) == 0)
183 printf (
"Report bugs to %s.\n" 189 printf (
"General help using GNU software: http://www.gnu.org/gethelp/\n");
209 .option_exclusive = 1,
211 .scls = (
void *) about
238 unsigned int *val =
scls;
290 .scls = (
void *) level
407 .require_argument = 1,
428 .argumentHelp =
"LOGLEVEL",
429 .description =
gettext_noop (
"configure logging to use LOGLEVEL"),
430 .require_argument = 1,
432 .scls = (
void *) level
488 .require_argument = 1,
508 .argumentHelp =
"FILENAME",
510 gettext_noop (
"configure logging to write logs to FILENAME"),
511 .require_argument = 1,
513 .scls = (
void *) logfn
531 .argumentHelp =
"FILENAME",
532 .description =
gettext_noop (
"use configuration file FILENAME"),
533 .require_argument = 1,
561 unsigned long long *val =
scls;
565 if (1 != sscanf (value,
"%llu%1s", val, dummy))
568 _ (
"You must pass a number to the `%s' option.\n"),
590 unsigned long long *val)
597 .require_argument = 1,
631 while (isspace (value[0]))
639 else if (value[0] ==
'+')
649 "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
656 _ (
"Value given for time travel `%s' option is too big.\n"),
683 .argumentHelp =
_ (
"[+/-]MICROSECONDS"),
685 "modify system time by given offset (for debugging/testing only)"),
686 .require_argument = 1,
720 _ (
"You must pass relative time to the `%s' option.\n"),
750 .require_argument = 1,
785 _ (
"You must pass absolute time to the `%s' option.\n"),
815 .require_argument = 1,
844 unsigned int *val =
scls;
852 "Your input for the '%s' option has to be a non negative number\n"),
856 if (1 != sscanf (value,
"%u%1s", val, dummy))
859 _ (
"You must pass a number to the `%s' option.\n"),
888 .require_argument = 1,
916 uint16_t *val =
scls;
921 if (1 != sscanf (value,
"%u%1s", &v, dummy))
924 _ (
"You must pass a number to the `%s' option.\n"),
931 _ (
"You must pass a number below %u to the `%s' option.\n"),
932 (
unsigned int) UINT16_MAX,
962 .require_argument = 1,
1018 "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
1064 .require_argument = 1,
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)...
static int set_absolute_time(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'struct GNUNET_TIME_Absolute' from the command line.
General context for command line processors.
static int increment_value(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'unsigned int' from the command line.
static int print_version(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Print out program version (implements –version).
static int set_relative_time(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'struct GNUNET_TIME_Relative' from the command line.
static int set_timetravel_time(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'struct GNUNET_TIME_Relative' from the command line.
Project-specific data used to help the OS subsystem find installation paths.
const char * argumentHelp
Name of the argument for the user in help text.
uint64_t rel_value_us
The actual value.
static struct GNUNET_TIME_Relative delta
void * scls
Specific closure to pass to the processor.
static int set_one(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'int' from the command line to 1 if the given option is present.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const char *about)
Defining the option to print the command line help text (-h option).
static int format_help(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Print out details on command line options (implements –help).
const char * binaryName
Name of the application.
const char * description
Help text for the option (description)
static int set_string(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'char *' from the command line.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
const struct GNUNET_GETOPT_CommandLineOption * allOptions
Array with all command line options.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
int GNUNET_STRINGS_fancy_time_to_absolute(const char *fancy_time, struct GNUNET_TIME_Absolute *atime)
Convert a given fancy human-readable time to our internal representation.
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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Closure for set_base32().
const char shortName
Short name of the option.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l option)
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
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.
int is_gnu
Non-zero means this project is part of GNU.
const char * bug_email
E-mail address for reporting bugs.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
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).
static struct GNUNET_OS_Process * p
Helper process we started.
static char * value
Value of the record to add/remove.
static char * fn
Filename of the unique file.
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)...
int option_exclusive
Is the option exclusive?
#define BORDER
At what offset does the help text start?
static char * option
Name of the option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the '-L' log level option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
static void free_bc(void *cls)
Helper function to clean up after GNUNET_GETOPT_option_base32_fixed_size.
static int set_uint16(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'uint16_t' from the command line.
size_t val_size
Number of bytes expected for val.
static int set_base32(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'unsigned int' from the command line.
static int set_filename(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'char *' from the command line with filename expansion a la GNUNET_STRINGS_file...
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
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
void * val
Value to initialize (already allocated)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
const char * homepage
Project homepage.
const char * binaryOptions
Name of application with option summary.
static int set_uint(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'unsigned int' from the command line.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_exclusive(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mutually exclusive with other options.
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.
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 t...
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
Time for absolute times used by GNUnet, in microseconds.
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 integer.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
static int set_ulong(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'unsigned long long' from the command line.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
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.
#define gettext_noop(String)
int option_mandatory
Is the presence of this option mandatory?