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_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 80 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: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:

◆ 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 92 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().

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

233 {
234  unsigned int *val = scls;
235 
236  (void) ctx;
237  (void) option;
238  (void) value;
239  (*val)++;
240  return GNUNET_OK;
241 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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 304 of file getopt_helpers.c.

References GNUNET_OK, and GNUNET_GETOPT_CommandLineOption::scls.

Referenced by GNUNET_GETOPT_option_flag().

308 {
309  int *val = scls;
310 
311  (void) ctx;
312  (void) option;
313  (void) value;
314  *val = 1;
315  return GNUNET_OK;
316 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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 360 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().

364 {
365  char **val = scls;
366 
367  (void) ctx;
368  (void) option;
369  GNUNET_assert (NULL != value);
370  GNUNET_free_non_null (*val);
371  *val = GNUNET_strdup (value);
372  return GNUNET_OK;
373 }
#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:75
#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 438 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().

442 {
443  char **val = scls;
444 
445  (void) ctx;
446  (void) option;
447  GNUNET_assert (NULL != value);
448  GNUNET_free_non_null (*val);
450  return GNUNET_OK;
451 }
#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:75
#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:603
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 539 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_ulong().

543 {
544  unsigned long long *val = scls;
545  char dummy[2];
546 
547  (void) ctx;
548  if (1 != sscanf (value, "%llu%1s", val, dummy))
549  {
550  fprintf (stderr,
551  _ ("You must pass a number to the `%s' option.\n"),
552  option);
553  return GNUNET_SYSERR;
554  }
555  return GNUNET_OK;
556 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:76
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_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 601 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_relative_time().

605 {
606  struct GNUNET_TIME_Relative *val = scls;
607 
608  (void) ctx;
610  {
611  fprintf (stderr,
612  _ ("You must pass relative time to the `%s' option.\n"),
613  option);
614  return GNUNET_SYSERR;
615  }
616  return GNUNET_OK;
617 }
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:351
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:76
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 664 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_absolute_time().

668 {
669  struct GNUNET_TIME_Absolute *val = scls;
670 
671  (void) ctx;
673  {
674  fprintf (stderr,
675  _ ("You must pass absolute time to the `%s' option.\n"),
676  option);
677  return GNUNET_SYSERR;
678  }
679  return GNUNET_OK;
680 }
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:402
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:76
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 727 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_uint().

731 {
732  unsigned int *val = scls;
733  char dummy[2];
734 
735  (void) ctx;
736  if ('-' == *value)
737  {
738  fprintf (stderr,
739  _ (
740  "Your input for the '%s' option has to be a non negative number \n"),
741  option);
742  return GNUNET_SYSERR;
743  }
744  if (1 != sscanf (value, "%u%1s", val, dummy))
745  {
746  fprintf (stderr,
747  _ ("You must pass a number to the `%s' option.\n"),
748  option);
749  return GNUNET_SYSERR;
750  }
751  return GNUNET_OK;
752 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:76
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 797 of file getopt_helpers.c.

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

Referenced by GNUNET_GETOPT_option_uint16().

801 {
802  uint16_t *val = scls;
803  unsigned int v;
804  char dummy[2];
805 
806  (void) ctx;
807  if (1 != sscanf (value, "%u%1s", &v, dummy))
808  {
809  fprintf (stderr,
810  _ ("You must pass a number to the `%s' option.\n"),
811  option);
812  return GNUNET_SYSERR;
813  }
814  if (v > UINT16_MAX)
815  {
816  fprintf (stderr,
817  _ ("You must pass a number below %u to the `%s' option.\n"),
818  (unsigned int) UINT16_MAX,
819  option);
820  return GNUNET_SYSERR;
821  }
822  *val = (uint16_t) v;
823  return GNUNET_OK;
824 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:76
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 886 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().

890 {
891  struct Base32Context *bc = scls;
892 
893  (void) ctx;
895  strlen (value),
896  bc->val,
897  bc->val_size))
898  {
899  fprintf (
900  stderr,
901  _ (
902  "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
903  option);
904  return GNUNET_SYSERR;
905  }
906  return GNUNET_OK;
907 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Closure for set_base32().
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:76
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:952
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 917 of file getopt_helpers.c.

References GNUNET_free.

Referenced by GNUNET_GETOPT_option_base32_fixed_size().

918 {
919  GNUNET_free (cls);
920 }
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: