GNUnet  0.10.x
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 
32 #ifndef GNUNET_GETOPT_LIB_H
33 #define GNUNET_GETOPT_LIB_H
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #if 0 /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41 
43 
48 {
49 
53  const char *binaryName;
54 
58  const char *binaryOptions;
59 
64 
68  char *const *argv;
69 
73  unsigned int argc;
74 
78  unsigned int currentArgument;
79 };
80 
81 
93  void *scls,
94  const char *option,
95  const char *value);
96 
97 
102 {
103 
107  const char shortName;
108 
112  const char *name;
113 
117  const char *argumentHelp;
118 
122  const char *description;
123 
129 
134 
139 
144 
149  void (*cleaner) (void *cls);
150 
154  void *scls;
155 };
156 
157 
165 GNUNET_GETOPT_option_help (const char *about);
166 
167 
175 GNUNET_GETOPT_option_version (const char *version);
176 
177 
184 GNUNET_GETOPT_option_logfile (char **logfn);
185 
186 
198  const char *name,
199  const char *argumentHelp,
200  const char *description,
201  char **str);
202 
214  const char *name,
215  const char *argumentHelp,
216  const char *description,
217  char **str);
218 
219 
233  const char *name,
234  const char *argumentHelp,
235  const char *description,
236  void *val,
237  size_t val_size);
238 
239 
252 #define GNUNET_GETOPT_option_base32_auto(shortName, \
253  name, \
254  argumentHelp, \
255  description, \
256  val) \
257  GNUNET_GETOPT_option_base32_fixed_size (shortName, \
258  name, \
259  argumentHelp, \
260  description, \
261  val, \
262  sizeof (*val))
263 
264 
276  const char *name,
277  const char *description,
278  int *val);
279 
280 
292  const char *name,
293  const char *argumentHelp,
294  const char *description,
295  unsigned int *val);
296 
297 
309  const char *name,
310  const char *argumentHelp,
311  const char *description,
312  uint16_t *val);
313 
314 
326  const char *name,
327  const char *argumentHelp,
328  const char *description,
329  unsigned long long *val);
330 
331 
344  const char *name,
345  const char *argumentHelp,
346  const char *description,
347  struct GNUNET_TIME_Relative *val);
348 
349 
362  const char *name,
363  const char *argumentHelp,
364  const char *description,
365  struct GNUNET_TIME_Absolute *val);
366 
367 
379  const char *name,
380  const char *description,
381  unsigned int *val);
382 
383 
391 GNUNET_GETOPT_option_loglevel (char **level);
392 
393 
401 GNUNET_GETOPT_option_verbose (unsigned int *level);
402 
403 
410 GNUNET_GETOPT_option_logfile (char **logfn);
411 
412 
420 
421 
430 
431 
440 
441 
445 #define GNUNET_GETOPT_OPTION_END \
446  { \
447  '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \
448  }
449 
450 
461 int
462 GNUNET_GETOPT_run (const char *binaryOptions,
464  unsigned int argc,
465  char *const *argv);
466 
467 
468 #if 0 /* keep Emacsens' auto-indent happy */
469 {
470 #endif
471 #ifdef __cplusplus
472 }
473 #endif
474 
475 /* ifndef GNUNET_GETOPT_LIB_H */
476 #endif
477  /* end of group getopt */
479 
480 /* end of gnunet_getopt_lib.h */
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)...
General context for command line processors.
const char * argumentHelp
Name of the argument for the user in help text.
unsigned int argc
Total number of argv&#39;s.
void * scls
Specific closure to pass to the processor.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const char *about)
Defining the option to print the command line help text (-h option).
const char * binaryName
Name of the application.
const char * description
Help text for the option (description)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the &#39;-V&#39; verbosity option.
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.
char *const * argv
Original command line.
const struct GNUNET_GETOPT_CommandLineOption * allOptions
Array with all command line options.
GNUNET_GETOPT_CommandLineOptionProcessor processor
Handler for the option.
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.
Definition of a command line option.
int(* GNUNET_GETOPT_CommandLineOptionProcessor)(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Process a command line option.
const char shortName
Short name of the option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l option)
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
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_version(const char *version)
Define the option to print the version of the application (-v option)
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).
static char * value
Value of the record to add/remove.
static char * fn
Filename of the unique file.
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)...
int option_exclusive
Is the option exclusive?
static char * option
Name of the option.
Definition: gnunet-config.c:38
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the &#39;-L&#39; log level option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
int require_argument
Is an argument required? GNUNET_NO (includes optional) or GNUNET_YES (required)
unsigned int currentArgument
Current argument.
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:893
const char * name
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_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
const char * binaryOptions
Name of application with option summary.
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_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.
Time for absolute times used by GNUnet, in microseconds.
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.
const char * name
Long name of the option (may not be NULL)
Time for relative time used by GNUnet, in microseconds.
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.
int option_mandatory
Is the presence of this option mandatory?