30#define LOG(kind, ...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
48 const char *version = scls;
66 "print the version number"),
67 .option_exclusive = 1,
69 .scls = (
void *) version
97 const char *about = NULL;
109 opt =
ctx->allOptions;
122 "Arguments mandatory for long options are also mandatory for short options.\n"));
130 printf (
"--%s", opt[i].
name);
131 slen = 8 + strlen (opt[i].
name);
140 printf (
"\n%*s",
BORDER,
"");
145 printf (
"%*s", (
int) (
BORDER - slen),
"");
155 while (ml -
p > 78 - slen)
157 for (j =
p + 78 - slen; j > (
int)
p; j--)
159 if (isspace ((
unsigned char) trans[j]))
164 printf (
"%s\n%*s", scp,
BORDER + 2,
"");
174 scp[78 - slen] =
'\0';
175 printf (
"%s\n%*s", scp,
BORDER + 2,
"");
182 printf (
"%s\n", &trans[
p]);
183 if (strlen (trans) == 0)
187 "Report bugs to %s.\n"
193 printf (
"General help using GNU software: http://www.gnu.org/gethelp/\n");
206 .argumentHelp = about,
209 .option_exclusive = 1,
238 unsigned int *val =
scls;
275 .scls = (
void *) level
373 .require_argument = 1,
388 .argumentHelp =
"LOGLEVEL",
389 .description =
gettext_noop (
"configure logging to use LOGLEVEL"),
390 .require_argument = 1,
392 .scls = (
void *) level
439 .require_argument = 1,
454 .argumentHelp =
"FILENAME",
456 gettext_noop (
"configure logging to write logs to FILENAME"),
457 .require_argument = 1,
459 .scls = (
void *) logfn
472 .argumentHelp =
"FILENAME",
473 .description =
gettext_noop (
"use configuration file FILENAME"),
474 .require_argument = 1,
502 unsigned long long *val =
scls;
506 if (1 != sscanf (
value,
"%llu%1s", val,
dummy))
509 _ (
"You must pass a number to the `%s' option.\n"),
522 unsigned long long *val)
529 .require_argument = 1,
563 while (isspace (
value[0]))
571 else if (
value[0] ==
'+')
581 "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
588 _ (
"Value given for time travel `%s' option is too big.\n"),
606 .argumentHelp =
_ (
"[+/-]MICROSECONDS"),
608 "modify system time by given offset (for debugging/testing only)"),
609 .require_argument = 1,
642 _ (
"You must pass relative time to the `%s' option.\n"),
662 .require_argument = 1,
696 _ (
"You must pass absolute time to the `%s' option.\n"),
716 .require_argument = 1,
753 _ (
"You must pass a timestamp to the `%s' option.\n"),
760 _ (
"The maximum precision allowed for timestamps is seconds.\n"));
780 .require_argument = 1,
808 unsigned int *val =
scls;
816 "Your input for the '%s' option has to be a non negative number\n"),
823 _ (
"You must pass a number to the `%s' option.\n"),
843 .require_argument = 1,
871 uint16_t *val =
scls;
879 _ (
"You must pass a number to the `%s' option.\n"),
886 _ (
"You must pass a number below %u to the `%s' option.\n"),
887 (
unsigned int) UINT16_MAX,
908 .require_argument = 1,
964 "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n")
1000 .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_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_help(const struct GNUNET_OS_ProjectData *pd, const char *about)
Defining the option to print the command line help text (-h option).
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.
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.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.