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 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:94

◆ 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 ("Report bugs to %s.\n"
178  "Home page: %s\n",
179  pd->bug_email,
180  pd->homepage);
181 
182  if (0 != pd->is_gnu)
183  printf ("General help using GNU software: http://www.gnu.org/gethelp/\n");
184 
185  return GNUNET_NO;
186 }
#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.

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

◆ 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.

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

◆ 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.

337 {
338  char **val = scls;
339 
340  (void) ctx;
341  (void) option;
342  GNUNET_assert (NULL != value);
343  GNUNET_free (*val);
344  *val = GNUNET_strdup (value);
345  return GNUNET_OK;
346 }
#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.

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

◆ 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.

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

◆ 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.

544 {
545  long long delta;
546  long long minus;
547  struct GNUNET_TIME_Relative rt;
548 
549  (void) scls;
550  (void) ctx;
551  while (isspace (value[0]))
552  value++;
553  minus = 1;
554  if (value[0] == '-')
555  {
556  minus = -1;
557  value++;
558  }
559  else if (value[0] == '+')
560  {
561  value++;
562  }
563  if (GNUNET_OK !=
565  &rt))
566  {
567  fprintf (stderr,
568  _ (
569  "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
570  option);
571  return GNUNET_SYSERR;
572  }
573  if (rt.rel_value_us > LLONG_MAX)
574  {
575  fprintf (stderr,
576  _ ("Value given for time travel `%s' option is too big.\n"),
577  option);
578  return GNUNET_SYSERR;
579  }
580  delta = (long long) rt.rel_value_us;
581  delta *= minus;
583  return GNUNET_OK;
584 }
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.

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

◆ 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.

677 {
678  struct GNUNET_TIME_Absolute *val = scls;
679 
680  (void) ctx;
682  {
683  fprintf (stderr,
684  _ ("You must pass absolute time to the `%s' option.\n"),
685  option);
686  return GNUNET_SYSERR;
687  }
688  return GNUNET_OK;
689 }
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.

731 {
732  struct GNUNET_TIME_Timestamp *t = scls;
733  struct GNUNET_TIME_Absolute abs;
734 
735  (void) ctx;
736  if (GNUNET_OK !=
738  &abs))
739  {
740  fprintf (stderr,
741  _ ("You must pass a timestamp to the `%s' option.\n"),
742  option);
743  return GNUNET_SYSERR;
744  }
745  if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
746  {
747  fprintf (stderr,
748  _ ("The maximum precision allowed for timestamps is seconds.\n"));
749  return GNUNET_SYSERR;
750  }
751  t->abs_time = abs;
752  return GNUNET_OK;
753 }
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.

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

◆ 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.

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

◆ 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.

940 {
941  struct Base32Context *bc = scls;
942 
943  (void) ctx;
945  strlen (value),
946  bc->val,
947  bc->val_size))
948  {
949  fprintf (
950  stderr,
951  _ (
952  "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"),
953  option);
954  return GNUNET_SYSERR;
955  }
956  return GNUNET_OK;
957 }
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:762
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 967 of file getopt_helpers.c.

968 {
969  GNUNET_free (cls);
970 }

References GNUNET_free.