GNUnet  0.11.x
Data Structures | Macros | Functions
getopt_helpers.c File Reference

implements command line that sets option More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for getopt_helpers.c:

Go to the source code of this file.

Data Structures

struct  Base32Context
 Closure for set_base32(). More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)
 
#define BORDER   29
 At what offset does the help text start? More...
 

Functions

static int print_version (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
 Print out program version (implements –version). 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...
 
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). More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help (const char *about)
 Defining the option to print the command line help text (-h option). More...
 
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. 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_verbose (unsigned int *level)
 Define the '-V' verbosity option. More...
 
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. 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...
 
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. 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_loglevel (char **level)
 Define the '-L' log level option. More...
 
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_filename_expand(). 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_logfile (char **logfn)
 Allow user to specify log file name (-l option) More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile (char **fn)
 Allow user to specify configuration file name (-c option) More...
 
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. 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...
 
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. 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...
 
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. 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...
 
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. 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...
 
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. 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 integer. More...
 
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. 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...
 
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. More...
 
static void free_bc (void *cls)
 Helper function to clean up after GNUNET_GETOPT_option_base32_fixed_size. 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_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...
 

Detailed Description

implements command line that sets option

Author
Christian Grothoff

Definition in file getopt_helpers.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-getopt", __VA_ARGS__)

Definition at line 29 of file getopt_helpers.c.

◆ BORDER

#define BORDER   29

At what offset does the help text start?

Definition at line 82 of file getopt_helpers.c.

Referenced by format_help().

Function Documentation

◆ print_version()

static int print_version ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Print out program version (implements –version).

Parameters
ctxcommand line processing context
sclsadditional closure (points to version string)
optionname of the option
valuenot used (NULL)
Returns
GNUNET_NO (do not continue, not an error)

Definition at line 42 of file getopt_helpers.c.

References GNUNET_GETOPT_CommandLineProcessorContext::binaryName, and GNUNET_NO.

Referenced by GNUNET_GETOPT_option_version().

46 {
47  const char *version = scls;
48 
49  (void) option;
50  (void) value;
51  printf ("%s v%s\n", ctx->binaryName, version);
52  return GNUNET_NO;
53 }
const char * binaryName
Name of the application.
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
Here is the caller graph for this function:

◆ format_help()

static int format_help ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Print out details on command line options (implements –help).

Parameters
ctxcommand line processing context
sclsadditional closure (points to about text)
optionname of the option
valuenot used (NULL)
Returns
GNUNET_NO (do not continue, not an error)

Definition at line 94 of file getopt_helpers.c.

References _, GNUNET_GETOPT_CommandLineProcessorContext::allOptions, GNUNET_GETOPT_CommandLineProcessorContext::binaryOptions, BORDER, GNUNET_OS_ProjectData::bug_email, gettext, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OS_project_data_get(), GNUNET_OS_ProjectData::homepage, GNUNET_OS_ProjectData::is_gnu, name, p, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_help().

98 {
99  const char *about = scls;
100  size_t slen;
101  unsigned int i;
102  int j;
103  size_t ml;
104  size_t p;
105  char *scp;
106  const char *trans;
107  const struct GNUNET_GETOPT_CommandLineOption *opt;
108  const struct GNUNET_OS_ProjectData *pd;
109 
110  (void) option;
111  (void) value;
112  if (NULL != about)
113  {
114  printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
115  printf (_ (
116  "Arguments mandatory for long options are also mandatory for short options.\n"));
117  }
118  i = 0;
119  opt = ctx->allOptions;
120  while (NULL != opt[i].description)
121  {
122  if (opt[i].shortName == '\0')
123  printf (" ");
124  else
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)
129  {
130  printf ("=%s", opt[i].argumentHelp);
131  slen += 1 + strlen (opt[i].argumentHelp);
132  }
133  if (slen > BORDER)
134  {
135  printf ("\n%*s", BORDER, "");
136  slen = BORDER;
137  }
138  if (slen < BORDER)
139  {
140  printf ("%*s", (int) (BORDER - slen), "");
141  slen = BORDER;
142  }
143  if (0 < strlen (opt[i].description))
144  trans = gettext (opt[i].description);
145  else
146  trans = "";
147  ml = strlen (trans);
148  p = 0;
149 OUTER:
150  while (ml - p > 78 - slen)
151  {
152  for (j = p + 78 - slen; j > (int) p; j--)
153  {
154  if (isspace ((unsigned char) trans[j]))
155  {
156  scp = GNUNET_malloc (j - p + 1);
157  GNUNET_memcpy (scp, &trans[p], j - p);
158  scp[j - p] = '\0';
159  printf ("%s\n%*s", scp, BORDER + 2, "");
160  GNUNET_free (scp);
161  p = j + 1;
162  slen = BORDER + 2;
163  goto OUTER;
164  }
165  }
166  /* could not find space to break line */
167  scp = GNUNET_malloc (78 - slen + 1);
168  GNUNET_memcpy (scp, &trans[p], 78 - slen);
169  scp[78 - slen] = '\0';
170  printf ("%s\n%*s", scp, BORDER + 2, "");
171  GNUNET_free (scp);
172  slen = BORDER + 2;
173  p = p + 78 - slen;
174  }
175  /* print rest */
176  if (p < ml)
177  printf ("%s\n", &trans[p]);
178  if (strlen (trans) == 0)
179  printf ("\n");
180  i++;
181  }
183  printf ("Report bugs to %s.\n"
184  "Home page: %s\n",
185  pd->bug_email,
186  pd->homepage);
187 
188  if (0 != pd->is_gnu)
189  printf ("General help using GNU software: http://www.gnu.org/gethelp/\n");
190 
191  return GNUNET_NO;
192 }
Project-specific data used to help the OS subsystem find installation paths.
#define gettext(Msgid)
Definition: gettext.h:45
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.
Definition of a command line option.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int is_gnu
Non-zero means this project is part of GNU.
const char * bug_email
E-mail address for reporting bugs.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * value
Value of the record to add/remove.
#define BORDER
At what offset does the help text start?
static char * option
Name of the option.
Definition: gnunet-config.c:38
const char * homepage
Project homepage.
const char * binaryOptions
Name of application with option summary.
const char * name
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ increment_value()

static int increment_value ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'unsigned int' from the command line.

Each time the option flag is given, the value is incremented by one. A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'int'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned int')
optionname of the option
valuenot used (NULL)
Returns
GNUNET_OK

Definition at line 233 of file getopt_helpers.c.

References GNUNET_OK, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_increment_uint(), and GNUNET_GETOPT_option_verbose().

237 {
238  unsigned int *val = scls;
239 
240  (void) ctx;
241  (void) option;
242  (void) value;
243  (*val)++;
244  return GNUNET_OK;
245 }
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
Here is the caller graph for this function:

◆ set_one()

static int set_one ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'int' from the command line to 1 if the given option is present.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'int'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'int')
optionname of the option
valuenot used (NULL)
Returns
GNUNET_OK

Definition at line 312 of file getopt_helpers.c.

References GNUNET_OK, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_flag().

316 {
317  int *val = scls;
318 
319  (void) ctx;
320  (void) option;
321  (void) value;
322  *val = 1;
323  return GNUNET_OK;
324 }
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
Here is the caller graph for this function:

◆ set_string()

static int set_string ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'char *' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'char *', which will be allocated with the requested string.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'char *', which will be allocated)
optionname of the option
valueactual value of the option (a string)
Returns
GNUNET_OK

Definition at line 370 of file getopt_helpers.c.

References GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_strdup, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_loglevel(), and GNUNET_GETOPT_option_string().

374 {
375  char **val = scls;
376 
377  (void) ctx;
378  (void) option;
379  GNUNET_assert (NULL != value);
380  GNUNET_free (*val);
381  *val = GNUNET_strdup (value);
382  return GNUNET_OK;
383 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ set_filename()

static int set_filename ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'char *' from the command line with filename expansion a la GNUNET_STRINGS_filename_expand().

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the char *, which will be allocated)
optionname of the option
valueactual value of the option (a string)
Returns
GNUNET_OK

Definition at line 451 of file getopt_helpers.c.

References GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_STRINGS_filename_expand(), and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_cfgfile(), GNUNET_GETOPT_option_filename(), and GNUNET_GETOPT_option_logfile().

455 {
456  char **val = scls;
457 
458  (void) ctx;
459  (void) option;
460  GNUNET_assert (NULL != value);
461  GNUNET_free (*val);
463  return GNUNET_OK;
464 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_ulong()

static int set_ulong ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'unsigned long long' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'unsigned long long'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned long long')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 556 of file getopt_helpers.c.

References _, dummy, GNUNET_OK, GNUNET_SYSERR, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_ulong().

560 {
561  unsigned long long *val = scls;
562  char dummy[2];
563 
564  (void) ctx;
565  if (1 != sscanf (value, "%llu%1s", val, dummy))
566  {
567  fprintf (stderr,
568  _ ("You must pass a number to the `%s' option.\n"),
569  option);
570  return GNUNET_SYSERR;
571  }
572  return GNUNET_OK;
573 }
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
Here is the caller graph for this function:

◆ set_timetravel_time()

static int set_timetravel_time ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'struct GNUNET_TIME_Relative' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'struct GNUNET_TIME_Relative'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'struct GNUNET_TIME_Relative')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 620 of file getopt_helpers.c.

References _, delta, GNUNET_OK, GNUNET_STRINGS_fancy_time_to_relative(), GNUNET_SYSERR, GNUNET_TIME_set_offset(), and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_GETOPT_option_timetravel().

624 {
625  long long delta;
626  long long minus;
627  struct GNUNET_TIME_Relative rt;
628 
629  (void) scls;
630  (void) ctx;
631  while (isspace (value[0]))
632  value++;
633  minus = 1;
634  if (value[0] == '-')
635  {
636  minus = -1;
637  value++;
638  }
639  else if (value[0] == '+')
640  {
641  value++;
642  }
643  if (GNUNET_OK !=
645  &rt))
646  {
647  fprintf (stderr,
648  _ (
649  "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
650  option);
651  return GNUNET_SYSERR;
652  }
653  if (rt.rel_value_us > LLONG_MAX)
654  {
655  fprintf (stderr,
656  _ ("Value given for time travel `%s' option is too big.\n"),
657  option);
658  return GNUNET_SYSERR;
659  }
660  delta = (long long) rt.rel_value_us;
661  delta *= minus;
662  GNUNET_TIME_set_offset (delta);
663  return GNUNET_OK;
664 }
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
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.
Definition: strings.c:356
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:53
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_relative_time()

static int set_relative_time ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'struct GNUNET_TIME_Relative' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'struct GNUNET_TIME_Relative'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'struct GNUNET_TIME_Relative')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 709 of file getopt_helpers.c.

References _, GNUNET_OK, GNUNET_STRINGS_fancy_time_to_relative(), and GNUNET_SYSERR.

Referenced by GNUNET_GETOPT_option_relative_time().

713 {
714  struct GNUNET_TIME_Relative *val = scls;
715 
716  (void) ctx;
718  {
719  fprintf (stderr,
720  _ ("You must pass relative time to the `%s' option.\n"),
721  option);
722  return GNUNET_SYSERR;
723  }
724  return GNUNET_OK;
725 }
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.
Definition: strings.c:356
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_absolute_time()

static int set_absolute_time ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'struct GNUNET_TIME_Absolute' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'struct GNUNET_TIME_Absolute'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the struct GNUNET_TIME_Absolute)
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 774 of file getopt_helpers.c.

References _, GNUNET_OK, GNUNET_STRINGS_fancy_time_to_absolute(), and GNUNET_SYSERR.

Referenced by GNUNET_GETOPT_option_absolute_time().

778 {
779  struct GNUNET_TIME_Absolute *val = scls;
780 
781  (void) ctx;
783  {
784  fprintf (stderr,
785  _ ("You must pass absolute time to the `%s' option.\n"),
786  option);
787  return GNUNET_SYSERR;
788  }
789  return GNUNET_OK;
790 }
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.
Definition: strings.c:407
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
Time for absolute times used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_uint()

static int set_uint ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'unsigned int' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'unsigned int'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned int')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 839 of file getopt_helpers.c.

References _, dummy, GNUNET_OK, GNUNET_SYSERR, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_uint().

843 {
844  unsigned int *val = scls;
845  char dummy[2];
846 
847  (void) ctx;
848  if ('-' == *value)
849  {
850  fprintf (stderr,
851  _ (
852  "Your input for the '%s' option has to be a non negative number\n"),
853  option);
854  return GNUNET_SYSERR;
855  }
856  if (1 != sscanf (value, "%u%1s", val, dummy))
857  {
858  fprintf (stderr,
859  _ ("You must pass a number to the `%s' option.\n"),
860  option);
861  return GNUNET_SYSERR;
862  }
863  return GNUNET_OK;
864 }
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
Here is the caller graph for this function:

◆ set_uint16()

static int set_uint16 ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'uint16_t' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'uint16_t'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned int')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 911 of file getopt_helpers.c.

References _, dummy, GNUNET_OK, GNUNET_SYSERR, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_uint16().

915 {
916  uint16_t *val = scls;
917  unsigned int v;
918  char dummy[2];
919 
920  (void) ctx;
921  if (1 != sscanf (value, "%u%1s", &v, dummy))
922  {
923  fprintf (stderr,
924  _ ("You must pass a number to the `%s' option.\n"),
925  option);
926  return GNUNET_SYSERR;
927  }
928  if (v > UINT16_MAX)
929  {
930  fprintf (stderr,
931  _ ("You must pass a number below %u to the `%s' option.\n"),
932  (unsigned int) UINT16_MAX,
933  option);
934  return GNUNET_SYSERR;
935  }
936  *val = (uint16_t) v;
937  return GNUNET_OK;
938 }
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
Here is the caller graph for this function:

◆ set_base32()

static int set_base32 ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'unsigned int' from the command line.

A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type. It should be followed by a pointer to a value of type 'unsigned int'.

Parameters
ctxcommand line processing context
sclsadditional closure (will point to the 'unsigned int')
optionname of the option
valueactual value of the option as a string.
Returns
GNUNET_OK if parsing the value worked

Definition at line 1002 of file getopt_helpers.c.

References _, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, Base32Context::val, and Base32Context::val_size.

Referenced by GNUNET_GETOPT_option_base32_fixed_size().

1006 {
1007  struct Base32Context *bc = scls;
1008 
1009  (void) ctx;
1011  strlen (value),
1012  bc->val,
1013  bc->val_size))
1014  {
1015  fprintf (
1016  stderr,
1017  _ (
1018  "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
1019  option);
1020  return GNUNET_SYSERR;
1021  }
1022  return GNUNET_OK;
1023 }
Closure for set_base32().
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
size_t val_size
Number of bytes expected for val.
void * val
Value to initialize (already allocated)
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_bc()

static void free_bc ( void *  cls)
static

Helper function to clean up after GNUNET_GETOPT_option_base32_fixed_size.

Parameters
clsvalue to GNUNET_free()

Definition at line 1033 of file getopt_helpers.c.

References GNUNET_free.

Referenced by GNUNET_GETOPT_option_base32_fixed_size().

1034 {
1035  GNUNET_free (cls);
1036 }
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: