GNUnet  0.19.4
gnunet_getopt_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2001-2013 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
36 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37 #error "Only <gnunet_util_lib.h> can be included directly."
38 #endif
39 
40 #ifndef GNUNET_GETOPT_LIB_H
41 #define GNUNET_GETOPT_LIB_H
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #if 0 /* keep Emacsens' auto-indent happy */
46 }
47 #endif
48 #endif
49 
50 
52 
57 {
61  const char *binaryName;
62 
66  const char *binaryOptions;
67 
72 
76  char *const *argv;
77 
81  unsigned int argc;
82 
86  unsigned int currentArgument;
87 };
88 
89 
101  void *scls,
102  const char *option,
103  const char *value);
104 
105 
110 {
114  const char shortName;
115 
119  const char *name;
120 
124  const char *argumentHelp;
125 
129  const char *description;
130 
136 
141 
146 
151 
156  void (*cleaner) (void *cls);
157 
161  void *scls;
162 };
163 
164 
172 GNUNET_GETOPT_option_help (const char *about);
173 
174 
186  const char *name);
187 
188 
196 GNUNET_GETOPT_option_version (const char *version);
197 
198 
205 GNUNET_GETOPT_option_logfile (char **logfn);
206 
207 
219  const char *name,
220  const char *argumentHelp,
221  const char *description,
222  char **str);
223 
235  const char *name,
236  const char *argumentHelp,
237  const char *description,
238  char **str);
239 
240 
254  const char *name,
255  const char *argumentHelp,
256  const char *description,
257  void *val,
258  size_t val_size);
259 
260 
273 #define GNUNET_GETOPT_option_base32_auto(shortName, \
274  name, \
275  argumentHelp, \
276  description, \
277  val) \
278  GNUNET_GETOPT_option_base32_fixed_size (shortName, \
279  name, \
280  argumentHelp, \
281  description, \
282  val, \
283  sizeof(*val))
284 
285 
297  const char *name,
298  const char *description,
299  int *val);
300 
301 
313  const char *name,
314  const char *argumentHelp,
315  const char *description,
316  unsigned int *val);
317 
318 
330  const char *name,
331  const char *argumentHelp,
332  const char *description,
333  uint16_t *val);
334 
335 
347  const char *name,
348  const char *argumentHelp,
349  const char *description,
350  unsigned long long *val);
351 
352 
365  const char *name,
366  const char *argumentHelp,
367  const char *description,
368  struct GNUNET_TIME_Relative *val);
369 
370 
383  const char *name,
384  const char *argumentHelp,
385  const char *description,
386  struct GNUNET_TIME_Absolute *val);
387 
388 
401  const char *name,
402  const char *argumentHelp,
403  const char *description,
404  struct GNUNET_TIME_Timestamp *val);
405 
406 
417  const char *name,
418  const char *description,
419  unsigned int *val);
420 
421 
429 GNUNET_GETOPT_option_loglevel (char **level);
430 
431 
439 GNUNET_GETOPT_option_verbose (unsigned int *level);
440 
441 
448 GNUNET_GETOPT_option_logfile (char **logfn);
449 
450 
457 GNUNET_GETOPT_option_cfgfile (char **fn);
458 
459 
468 
469 
478 
479 
483 #define GNUNET_GETOPT_OPTION_END \
484  { \
485  '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \
486  }
487 
488 
499 int
500 GNUNET_GETOPT_run (const char *binaryOptions,
501  const struct GNUNET_GETOPT_CommandLineOption *allOptions,
502  unsigned int argc,
503  char *const *argv);
504 
505 
506 #if 0 /* keep Emacsens' auto-indent happy */
507 {
508 #endif
509 #ifdef __cplusplus
510 }
511 #endif
512 
513 /* ifndef GNUNET_GETOPT_LIB_H */
514 #endif
515  /* end of group getopt */
517  /* end of group addition */
519 
520 /* end of gnunet_getopt_lib.h */
static char * value
Value of the record to add/remove.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
Configuration API.
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).
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l option)
int GNUNET_GETOPT_run(const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv)
Parse the command line.
Definition: getopt.c:884
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).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_exclusive(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mutually exclusive with other options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
int(* GNUNET_GETOPT_CommandLineOptionProcessor)(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Process a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const char *about)
Defining the option to print the command line help text (-h option).
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 t...
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.
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.
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).
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).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the '-L' log level option.
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
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.
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.
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
const char * name
Definition of a command line option.
int require_argument
Is an argument required? GNUNET_NO (includes optional) or GNUNET_YES (required)
const char * description
Help text for the option (description)
const char * argumentHelp
Name of the argument for the user in help text.
int option_exclusive
Is the option exclusive?
int option_mandatory
Is the presence of this option mandatory?
const char * name
Long name of the option (may not be NULL)
void * scls
Specific closure to pass to the processor.
GNUNET_GETOPT_CommandLineOptionProcessor processor
Handler for the option.
const char shortName
Short name of the option.
void(* cleaner)(void *cls)
Function to call on scls to clean up after processing all the arguments.
General context for command line processors.
const char * binaryName
Name of the application.
const char * binaryOptions
Name of application with option summary.
const struct GNUNET_GETOPT_CommandLineOption * allOptions
Array with all command line options.
char *const * argv
Original command line.
unsigned int argc
Total number of argv's.
unsigned int currentArgument
Current argument.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Rounded time for timestamps used by GNUnet, in seconds.