GNUnet  0.10.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_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 79 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.
#define GNUNET_NO
Definition: gnunet_common.h:81
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 91 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, name, p, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_help().

95 {
96  const char *about = scls;
97  size_t slen;
98  unsigned int i;
99  int j;
100  size_t ml;
101  size_t p;
102  char *scp;
103  const char *trans;
104  const struct GNUNET_GETOPT_CommandLineOption *opt;
105  const struct GNUNET_OS_ProjectData *pd;
106 
107  (void) option;
108  (void) value;
109  if (NULL != about)
110  {
111  printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
112  printf (_ (
113  "Arguments mandatory for long options are also mandatory for short options.\n"));
114  }
115  i = 0;
116  opt = ctx->allOptions;
117  while (NULL != opt[i].description)
118  {
119  if (opt[i].shortName == '\0')
120  printf (" ");
121  else
122  printf (" -%c, ", opt[i].shortName);
123  printf ("--%s", opt[i].name);
124  slen = 8 + strlen (opt[i].name);
125  if (NULL != opt[i].argumentHelp)
126  {
127  printf ("=%s", opt[i].argumentHelp);
128  slen += 1 + strlen (opt[i].argumentHelp);
129  }
130  if (slen > BORDER)
131  {
132  printf ("\n%*s", BORDER, "");
133  slen = BORDER;
134  }
135  if (slen < BORDER)
136  {
137  printf ("%*s", (int) (BORDER - slen), "");
138  slen = BORDER;
139  }
140  if (0 < strlen (opt[i].description))
141  trans = gettext (opt[i].description);
142  else
143  trans = "";
144  ml = strlen (trans);
145  p = 0;
146  OUTER:
147  while (ml - p > 78 - slen)
148  {
149  for (j = p + 78 - slen; j > (int) p; j--)
150  {
151  if (isspace ((unsigned char) trans[j]))
152  {
153  scp = GNUNET_malloc (j - p + 1);
154  GNUNET_memcpy (scp, &trans[p], j - p);
155  scp[j - p] = '\0';
156  printf ("%s\n%*s", scp, BORDER + 2, "");
157  GNUNET_free (scp);
158  p = j + 1;
159  slen = BORDER + 2;
160  goto OUTER;
161  }
162  }
163  /* could not find space to break line */
164  scp = GNUNET_malloc (78 - slen + 1);
165  GNUNET_memcpy (scp, &trans[p], 78 - slen);
166  scp[78 - slen] = '\0';
167  printf ("%s\n%*s", scp, BORDER + 2, "");
168  GNUNET_free (scp);
169  slen = BORDER + 2;
170  p = p + 78 - slen;
171  }
172  /* print rest */
173  if (p < ml)
174  printf ("%s\n", &trans[p]);
175  if (strlen (trans) == 0)
176  printf ("\n");
177  i++;
178  }
180  printf ("Report bugs to %s.\n"
181  "GNUnet home page: %s\n"
182  "General help using GNU software: http://www.gnu.org/gethelp/\n",
183  pd->bug_email,
184  pd->homepage);
185  return GNUNET_NO;
186 }
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_NO
Definition: gnunet_common.h:81
Definition of a command line option.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
const char * bug_email
E-mail address for reporting bugs.
#define GNUNET_memcpy(dst, src, n)
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 * name
const char * homepage
Project homepage.
const char * binaryOptions
Name of application with option summary.
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 225 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().

229 {
230  unsigned int *val = scls;
231 
232  (void) ctx;
233  (void) option;
234  (void) value;
235  (*val)++;
236  return GNUNET_OK;
237 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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 300 of file getopt_helpers.c.

References GNUNET_OK, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_flag().

304 {
305  int *val = scls;
306 
307  (void) ctx;
308  (void) option;
309  (void) value;
310  *val = 1;
311  return GNUNET_OK;
312 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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 356 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_loglevel(), and GNUNET_GETOPT_option_string().

360 {
361  char **val = scls;
362 
363  (void) ctx;
364  (void) option;
365  GNUNET_assert (NULL != value);
366  GNUNET_free_non_null (*val);
367  *val = GNUNET_strdup (value);
368  return GNUNET_OK;
369 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#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
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 434 of file getopt_helpers.c.

References GNUNET_assert, GNUNET_free_non_null, 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().

438 {
439  char **val = scls;
440 
441  (void) ctx;
442  (void) option;
443  GNUNET_assert (NULL != value);
444  GNUNET_free_non_null (*val);
446  return GNUNET_OK;
447 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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:602
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 535 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_ulong().

539 {
540  unsigned long long *val = scls;
541  char dummy[2];
542 
543  (void) ctx;
544  if (1 != SSCANF (value, "%llu%1s", val, dummy))
545  {
546  FPRINTF (stderr,
547  _ ("You must pass a number to the `%s' option.\n"),
548  option);
549  return GNUNET_SYSERR;
550  }
551  return GNUNET_OK;
552 }
static struct in_addr dummy
Target "dummy" address.
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define SSCANF
Definition: plibc.h:691
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 597 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_relative_time().

601 {
602  struct GNUNET_TIME_Relative *val = scls;
603 
604  (void) ctx;
606  {
607  FPRINTF (stderr,
608  _ ("You must pass relative time to the `%s' option.\n"),
609  option);
610  return GNUNET_SYSERR;
611  }
612  return GNUNET_OK;
613 }
#define FPRINTF
Definition: plibc.h:683
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:353
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 659 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_absolute_time().

663 {
664  struct GNUNET_TIME_Absolute *val = scls;
665 
666  (void) ctx;
668  {
669  FPRINTF (stderr,
670  _ ("You must pass absolute time to the `%s' option.\n"),
671  option);
672  return GNUNET_SYSERR;
673  }
674  return GNUNET_OK;
675 }
#define FPRINTF
Definition: plibc.h:683
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:408
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 721 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_uint().

725 {
726  unsigned int *val = scls;
727  char dummy[2];
728 
729  (void) ctx;
730  if ('-' == *value)
731  {
732  FPRINTF (stderr,
733  _ (
734  "Your input for the '%s' option has to be a non negative number \n"),
735  option);
736  return GNUNET_SYSERR;
737  }
738  if (1 != SSCANF (value, "%u%1s", val, dummy))
739  {
740  FPRINTF (stderr,
741  _ ("You must pass a number to the `%s' option.\n"),
742  option);
743  return GNUNET_SYSERR;
744  }
745  return GNUNET_OK;
746 }
static struct in_addr dummy
Target "dummy" address.
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define SSCANF
Definition: plibc.h:691
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 791 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_uint16().

795 {
796  uint16_t *val = scls;
797  unsigned int v;
798  char dummy[2];
799 
800  (void) ctx;
801  if (1 != SSCANF (value, "%u%1s", &v, dummy))
802  {
803  FPRINTF (stderr,
804  _ ("You must pass a number to the `%s' option.\n"),
805  option);
806  return GNUNET_SYSERR;
807  }
808  if (v > UINT16_MAX)
809  {
810  FPRINTF (stderr,
811  _ ("You must pass a number below %u to the `%s' option.\n"),
812  (unsigned int) UINT16_MAX,
813  option);
814  return GNUNET_SYSERR;
815  }
816  *val = (uint16_t) v;
817  return GNUNET_OK;
818 }
static struct in_addr dummy
Target "dummy" address.
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define SSCANF
Definition: plibc.h:691
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 880 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().

884 {
885  struct Base32Context *bc = scls;
886 
887  (void) ctx;
889  strlen (value),
890  bc->val,
891  bc->val_size))
892  {
893  fprintf (
894  stderr,
895  _ (
896  "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
897  option);
898  return GNUNET_SYSERR;
899  }
900  return GNUNET_OK;
901 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Closure for set_base32().
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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:1021
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 911 of file getopt_helpers.c.

References GNUNET_free.

Referenced by GNUNET_GETOPT_option_base32_fixed_size().

912 {
913  GNUNET_free (cls);
914 }
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: