30#define LOG(kind, ...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
48 const char *version = scls;
52 printf (
"%s v%s\n",
ctx->binaryName, version);
64 "print the version number"),
65 .option_exclusive = 1,
67 .scls = (
void *) version
94 const char *about =
scls;
109 printf (
"%s\n%s\n",
ctx->binaryOptions,
gettext (about));
111 "Arguments mandatory for long options are also mandatory for short options.\n"));
114 opt =
ctx->allOptions;
115 while (NULL != opt[i].description)
117 if (opt[i].shortName ==
'\0')
120 printf (
" -%c, ", opt[i].shortName);
121 printf (
"--%s", opt[i].
name);
122 slen = 8 + strlen (opt[i].
name);
123 if (NULL != opt[i].argumentHelp)
125 printf (
"=%s", opt[i].argumentHelp);
126 slen += 1 + strlen (opt[i].argumentHelp);
130 printf (
"\n%*s",
BORDER,
"");
135 printf (
"%*s", (
int) (
BORDER - slen),
"");
138 if (0 < strlen (opt[i].description))
139 trans =
gettext (opt[i].description);
145 while (ml -
p > 78 - slen)
147 for (j =
p + 78 - slen; j > (
int)
p; j--)
149 if (isspace ((
unsigned char) trans[j]))
154 printf (
"%s\n%*s", scp,
BORDER + 2,
"");
164 scp[78 - slen] =
'\0';
165 printf (
"%s\n%*s", scp,
BORDER + 2,
"");
172 printf (
"%s\n", &trans[
p]);
173 if (strlen (trans) == 0)
179 "Report bugs to %s.\n"
185 printf (
"General help using GNU software: http://www.gnu.org/gethelp/\n");
199 .option_exclusive = 1,
201 .scls = (
void *) about
228 unsigned int *val =
scls;
265 .scls = (
void *) level
363 .require_argument = 1,
378 .argumentHelp =
"LOGLEVEL",
379 .description =
gettext_noop (
"configure logging to use LOGLEVEL"),
380 .require_argument = 1,
382 .scls = (
void *) level
429 .require_argument = 1,
444 .argumentHelp =
"FILENAME",
446 gettext_noop (
"configure logging to write logs to FILENAME"),
447 .require_argument = 1,
449 .scls = (
void *) logfn
462 .argumentHelp =
"FILENAME",
463 .description =
gettext_noop (
"use configuration file FILENAME"),
464 .require_argument = 1,
492 unsigned long long *val =
scls;
496 if (1 != sscanf (
value,
"%llu%1s", val,
dummy))
499 _ (
"You must pass a number to the `%s' option.\n"),
512 unsigned long long *val)
519 .require_argument = 1,
553 while (isspace (
value[0]))
561 else if (
value[0] ==
'+')
571 "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
578 _ (
"Value given for time travel `%s' option is too big.\n"),
596 .argumentHelp =
_ (
"[+/-]MICROSECONDS"),
598 "modify system time by given offset (for debugging/testing only)"),
599 .require_argument = 1,
632 _ (
"You must pass relative time to the `%s' option.\n"),
652 .require_argument = 1,
686 _ (
"You must pass absolute time to the `%s' option.\n"),
706 .require_argument = 1,
743 _ (
"You must pass a timestamp to the `%s' option.\n"),
750 _ (
"The maximum precision allowed for timestamps is seconds.\n"));
770 .require_argument = 1,
798 unsigned int *val =
scls;
806 "Your input for the '%s' option has to be a non negative number\n"),
813 _ (
"You must pass a number to the `%s' option.\n"),
833 .require_argument = 1,
861 uint16_t *val =
scls;
869 _ (
"You must pass a number to the `%s' option.\n"),
876 _ (
"You must pass a number below %u to the `%s' option.\n"),
877 (
unsigned int) UINT16_MAX,
898 .require_argument = 1,
954 "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
989 .require_argument = 1,
static enum GNUNET_GenericReturnValue 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.
static enum GNUNET_GenericReturnValue 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.
static enum GNUNET_GenericReturnValue 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.
static enum GNUNET_GenericReturnValue 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.
static enum GNUNET_GenericReturnValue 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...
static enum GNUNET_GenericReturnValue set_timestamp(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option of type 'struct GNUNET_TIME_Timestamp' from the command line.
static enum GNUNET_GenericReturnValue 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.
#define BORDER
At what offset does the help text start?
static enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue format_help(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Print out details on command line options (implements –help).
static enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue print_version(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Print out program version (implements –version).
static enum GNUNET_GenericReturnValue 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.
static enum GNUNET_GenericReturnValue 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 void free_bc(void *cls)
Helper function to clean up after GNUNET_GETOPT_option_base32_fixed_size.
static enum GNUNET_GenericReturnValue 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.
#define gettext_noop(String)
static struct GNUNET_FS_Handle * ctx
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
static struct GNUNET_OS_Process * p
Helper process we started.
static struct GNUNET_SCHEDULER_Task * t
Main task.
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).
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l 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).
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_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const char *about)
Defining the option to print the command line help text (-h option).
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...
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.
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.
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).
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).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the '-L' log level option.
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
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_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
enum GNUNET_GenericReturnValue 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.
#define GNUNET_TIME_UNIT_SECONDS
One second.
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
enum GNUNET_GenericReturnValue 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.
static struct GNUNET_TIME_Relative delta
Closure for set_base32().
void * val
Value to initialize (already allocated)
size_t val_size
Number of bytes expected for val.
Definition of a command line option.
const char * description
Help text for the option (description)
const char * argumentHelp
Name of the argument for the user in help text.
int option_exclusive
Is the option exclusive?
int option_mandatory
Is the presence of this option mandatory?
void * scls
Specific closure to pass to the processor.
const char shortName
Short name of the option.
General context for command line processors.
Project-specific data used to help the OS subsystem find installation paths.
const char * bug_email
E-mail address for reporting bugs.
int is_gnu
Non-zero means this project is part of GNU.
const char * homepage
Project homepage.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Rounded time for timestamps used by GNUnet, in seconds.