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 
51  const char *binaryName;
52 
56  const char *binaryOptions;
57 
62 
66  char *const *argv;
67 
71  unsigned int argc;
72 
76  unsigned int currentArgument;
77 };
78 
79 
91  void *scls,
92  const char *option,
93  const char *value);
94 
95 
103  const char shortName;
104 
108  const char *name;
109 
113  const char *argumentHelp;
114 
118  const char *description;
119 
125 
130 
135 
140 
145  void (*cleaner) (void *cls);
146 
150  void *scls;
151 };
152 
153 
161 GNUNET_GETOPT_option_help(const char *about);
162 
163 
171 GNUNET_GETOPT_option_version(const char *version);
172 
173 
180 GNUNET_GETOPT_option_logfile(char **logfn);
181 
182 
194  const char *name,
195  const char *argumentHelp,
196  const char *description,
197  char **str);
198 
210  const char *name,
211  const char *argumentHelp,
212  const char *description,
213  char **str);
214 
215 
229  const char *name,
230  const char *argumentHelp,
231  const char *description,
232  void *val,
233  size_t val_size);
234 
235 
248 #define GNUNET_GETOPT_option_base32_auto(shortName, \
249  name, \
250  argumentHelp, \
251  description, \
252  val) \
253  GNUNET_GETOPT_option_base32_fixed_size(shortName, \
254  name, \
255  argumentHelp, \
256  description, \
257  val, \
258  sizeof(*val))
259 
260 
272  const char *name,
273  const char *description,
274  int *val);
275 
276 
288  const char *name,
289  const char *argumentHelp,
290  const char *description,
291  unsigned int *val);
292 
293 
305  const char *name,
306  const char *argumentHelp,
307  const char *description,
308  uint16_t *val);
309 
310 
322  const char *name,
323  const char *argumentHelp,
324  const char *description,
325  unsigned long long *val);
326 
327 
340  const char *name,
341  const char *argumentHelp,
342  const char *description,
343  struct GNUNET_TIME_Relative *val);
344 
345 
358  const char *name,
359  const char *argumentHelp,
360  const char *description,
361  struct GNUNET_TIME_Absolute *val);
362 
363 
375  const char *name,
376  const char *description,
377  unsigned int *val);
378 
379 
387 GNUNET_GETOPT_option_loglevel(char **level);
388 
389 
397 GNUNET_GETOPT_option_verbose(unsigned int *level);
398 
399 
406 GNUNET_GETOPT_option_logfile(char **logfn);
407 
408 
416 
417 
426 
427 
436 
437 
441 #define GNUNET_GETOPT_OPTION_END \
442  { \
443  '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \
444  }
445 
446 
457 int
458 GNUNET_GETOPT_run(const char *binaryOptions,
460  unsigned int argc,
461  char *const *argv);
462 
463 
464 #if 0 /* keep Emacsens' auto-indent happy */
465 {
466 #endif
467 #ifdef __cplusplus
468 }
469 #endif
470 
471 /* ifndef GNUNET_GETOPT_LIB_H */
472 #endif
473  /* end of group getopt */
475 
476 /* 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:886
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?