GNUnet  0.11.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 {
52  const char *binaryName;
53 
57  const char *binaryOptions;
58 
63 
67  char *const *argv;
68 
72  unsigned int argc;
73 
77  unsigned int currentArgument;
78 };
79 
80 
92  void *scls,
93  const char *option,
94  const char *value);
95 
96 
101 {
105  const char shortName;
106 
110  const char *name;
111 
115  const char *argumentHelp;
116 
120  const char *description;
121 
127 
132 
137 
142 
147  void (*cleaner) (void *cls);
148 
152  void *scls;
153 };
154 
155 
163 GNUNET_GETOPT_option_help (const char *about);
164 
165 
173 GNUNET_GETOPT_option_version (const char *version);
174 
175 
182 GNUNET_GETOPT_option_logfile (char **logfn);
183 
184 
196  const char *name,
197  const char *argumentHelp,
198  const char *description,
199  char **str);
200 
212  const char *name,
213  const char *argumentHelp,
214  const char *description,
215  char **str);
216 
217 
231  const char *name,
232  const char *argumentHelp,
233  const char *description,
234  void *val,
235  size_t val_size);
236 
237 
250 #define GNUNET_GETOPT_option_base32_auto(shortName, \
251  name, \
252  argumentHelp, \
253  description, \
254  val) \
255  GNUNET_GETOPT_option_base32_fixed_size (shortName, \
256  name, \
257  argumentHelp, \
258  description, \
259  val, \
260  sizeof(*val))
261 
262 
274  const char *name,
275  const char *description,
276  int *val);
277 
278 
290  const char *name,
291  const char *argumentHelp,
292  const char *description,
293  unsigned int *val);
294 
295 
307  const char *name,
308  const char *argumentHelp,
309  const char *description,
310  uint16_t *val);
311 
312 
324  const char *name,
325  const char *argumentHelp,
326  const char *description,
327  unsigned long long *val);
328 
329 
342  const char *name,
343  const char *argumentHelp,
344  const char *description,
345  struct GNUNET_TIME_Relative *val);
346 
347 
360  const char *name,
361  const char *argumentHelp,
362  const char *description,
363  struct GNUNET_TIME_Absolute *val);
364 
365 
377  const char *name,
378  const char *description,
379  unsigned int *val);
380 
381 
389 GNUNET_GETOPT_option_loglevel (char **level);
390 
391 
399 GNUNET_GETOPT_option_verbose (unsigned int *level);
400 
401 
408 GNUNET_GETOPT_option_logfile (char **logfn);
409 
410 
418 
419 
428 
429 
438 
439 
443 #define GNUNET_GETOPT_OPTION_END \
444  { \
445  '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \
446  }
447 
448 
459 int
460 GNUNET_GETOPT_run (const char *binaryOptions,
462  unsigned int argc,
463  char *const *argv);
464 
465 
466 #if 0 /* keep Emacsens' auto-indent happy */
467 {
468 #endif
469 #ifdef __cplusplus
470 }
471 #endif
472 
473 /* ifndef GNUNET_GETOPT_LIB_H */
474 #endif
475  /* end of group getopt */
477 
478 /* 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:892
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.
const char * name
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?