GNUnet  0.17.6
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 enum GNUNET_GenericReturnValue 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 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). 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 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. 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 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. 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 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. 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 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_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 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. 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 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. 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 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. 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 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. 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 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. More...
 
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). More...
 
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. 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 int. More...
 
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. 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 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. 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 76 of file getopt_helpers.c.

Function Documentation

◆ print_version()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

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 }
static char * value
Value of the record to add/remove.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
@ GNUNET_NO
Definition: gnunet_common.h:98

◆ format_help()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

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

◆ increment_value()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

226 {
227  unsigned int *val = scls;
228 
229  (void) ctx;
230  (void) option;
231  (void) value;
232  (*val)++;
233  return GNUNET_OK;
234 }
@ GNUNET_OK
Definition: gnunet_common.h:99

◆ set_one()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

290 {
291  int *val = scls;
292 
293  (void) ctx;
294  (void) option;
295  (void) value;
296  *val = 1;
297  return GNUNET_OK;
298 }

◆ set_string()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

338 {
339  char **val = scls;
340 
341  (void) ctx;
342  (void) option;
343  GNUNET_assert (NULL != value);
344  GNUNET_free (*val);
345  *val = GNUNET_strdup (value);
346  return GNUNET_OK;
347 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

◆ set_filename()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

404 {
405  char **val = scls;
406 
407  (void) ctx;
408  (void) option;
409  GNUNET_assert (NULL != value);
410  GNUNET_free (*val);
412  return GNUNET_OK;
413 }
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:495

◆ set_ulong()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

490 {
491  unsigned long long *val = scls;
492  char dummy[2];
493 
494  (void) ctx;
495  if (1 != sscanf (value, "%llu%1s", val, dummy))
496  {
497  fprintf (stderr,
498  _ ("You must pass a number to the `%s' option.\n"),
499  option);
500  return GNUNET_SYSERR;
501  }
502  return GNUNET_OK;
503 }
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
@ GNUNET_SYSERR
Definition: gnunet_common.h:97

◆ set_timetravel_time()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

545 {
546  long long delta;
547  long long minus;
548  struct GNUNET_TIME_Relative rt;
549 
550  (void) scls;
551  (void) ctx;
552  while (isspace (value[0]))
553  value++;
554  minus = 1;
555  if (value[0] == '-')
556  {
557  minus = -1;
558  value++;
559  }
560  else if (value[0] == '+')
561  {
562  value++;
563  }
564  if (GNUNET_OK !=
566  &rt))
567  {
568  fprintf (stderr,
569  _ (
570  "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
571  option);
572  return GNUNET_SYSERR;
573  }
574  if (rt.rel_value_us > LLONG_MAX)
575  {
576  fprintf (stderr,
577  _ ("Value given for time travel `%s' option is too big.\n"),
578  option);
579  return GNUNET_SYSERR;
580  }
581  delta = (long long) rt.rel_value_us;
582  delta *= minus;
584  return GNUNET_OK;
585 }
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.
Definition: strings.c:261
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:48
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

◆ set_relative_time()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

624 {
625  struct GNUNET_TIME_Relative *val = scls;
626 
627  (void) ctx;
629  {
630  fprintf (stderr,
631  _ ("You must pass relative time to the `%s' option.\n"),
632  option);
633  return GNUNET_SYSERR;
634  }
635  return GNUNET_OK;
636 }

◆ set_absolute_time()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

678 {
679  struct GNUNET_TIME_Absolute *val = scls;
680 
681  (void) ctx;
683  {
684  fprintf (stderr,
685  _ ("You must pass absolute time to the `%s' option.\n"),
686  option);
687  return GNUNET_SYSERR;
688  }
689  return GNUNET_OK;
690 }
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.
Definition: strings.c:303
Time for absolute times used by GNUnet, in microseconds.

◆ set_timestamp()

static enum GNUNET_GenericReturnValue set_timestamp ( struct GNUNET_GETOPT_CommandLineProcessorContext ctx,
void *  scls,
const char *  option,
const char *  value 
)
static

Set an option of type 'struct GNUNET_TIME_Timestamp' 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 1 of file getopt_helpers.c.

732 {
733  struct GNUNET_TIME_Timestamp *t = scls;
734  struct GNUNET_TIME_Absolute abs;
735 
736  (void) ctx;
737  if (GNUNET_OK !=
739  &abs))
740  {
741  fprintf (stderr,
742  _ ("You must pass a timestamp to the `%s' option.\n"),
743  option);
744  return GNUNET_SYSERR;
745  }
746  if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
747  {
748  fprintf (stderr,
749  _ ("The maximum precision allowed for timestamps is seconds.\n"));
750  return GNUNET_SYSERR;
751  }
752  t->abs_time = abs;
753  return GNUNET_OK;
754 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_TIME_UNIT_SECONDS
One second.
Rounded time for timestamps used by GNUnet, in seconds.

◆ set_uint()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

796 {
797  unsigned int *val = scls;
798  char dummy[2];
799 
800  (void) ctx;
801  if ('-' == *value)
802  {
803  fprintf (stderr,
804  _ (
805  "Your input for the '%s' option has to be a non negative number\n"),
806  option);
807  return GNUNET_SYSERR;
808  }
809  if (1 != sscanf (value, "%u%1s", val, dummy))
810  {
811  fprintf (stderr,
812  _ ("You must pass a number to the `%s' option.\n"),
813  option);
814  return GNUNET_SYSERR;
815  }
816  return GNUNET_OK;
817 }

◆ set_uint16()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

859 {
860  uint16_t *val = scls;
861  unsigned int v;
862  char dummy[2];
863 
864  (void) ctx;
865  if (1 != sscanf (value, "%u%1s", &v, dummy))
866  {
867  fprintf (stderr,
868  _ ("You must pass a number to the `%s' option.\n"),
869  option);
870  return GNUNET_SYSERR;
871  }
872  if (v > UINT16_MAX)
873  {
874  fprintf (stderr,
875  _ ("You must pass a number below %u to the `%s' option.\n"),
876  (unsigned int) UINT16_MAX,
877  option);
878  return GNUNET_SYSERR;
879  }
880  *val = (uint16_t) v;
881  return GNUNET_OK;
882 }

◆ set_base32()

static enum GNUNET_GenericReturnValue 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 1 of file getopt_helpers.c.

941 {
942  struct Base32Context *bc = scls;
943 
944  (void) ctx;
946  strlen (value),
947  bc->val,
948  bc->val_size))
949  {
950  fprintf (
951  stderr,
952  _ (
953  "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
954  option);
955  return GNUNET_SYSERR;
956  }
957  return GNUNET_OK;
958 }
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.
Definition: strings.c:789
Closure for set_base32().
void * val
Value to initialize (already allocated)
size_t val_size
Number of bytes expected for val.

◆ 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 968 of file getopt_helpers.c.

969 {
970  GNUNET_free (cls);
971 }

References GNUNET_free.