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 
177  const char *name);
178 
179 
187 GNUNET_GETOPT_option_version (const char *version);
188 
189 
196 GNUNET_GETOPT_option_logfile (char **logfn);
197 
198 
210  const char *name,
211  const char *argumentHelp,
212  const char *description,
213  char **str);
214 
226  const char *name,
227  const char *argumentHelp,
228  const char *description,
229  char **str);
230 
231 
245  const char *name,
246  const char *argumentHelp,
247  const char *description,
248  void *val,
249  size_t val_size);
250 
251 
264 #define GNUNET_GETOPT_option_base32_auto(shortName, \
265  name, \
266  argumentHelp, \
267  description, \
268  val) \
269  GNUNET_GETOPT_option_base32_fixed_size (shortName, \
270  name, \
271  argumentHelp, \
272  description, \
273  val, \
274  sizeof(*val))
275 
276 
288  const char *name,
289  const char *description,
290  int *val);
291 
292 
304  const char *name,
305  const char *argumentHelp,
306  const char *description,
307  unsigned int *val);
308 
309 
321  const char *name,
322  const char *argumentHelp,
323  const char *description,
324  uint16_t *val);
325 
326 
338  const char *name,
339  const char *argumentHelp,
340  const char *description,
341  unsigned long long *val);
342 
343 
356  const char *name,
357  const char *argumentHelp,
358  const char *description,
359  struct GNUNET_TIME_Relative *val);
360 
361 
374  const char *name,
375  const char *argumentHelp,
376  const char *description,
377  struct GNUNET_TIME_Absolute *val);
378 
379 
391  const char *name,
392  const char *description,
393  unsigned int *val);
394 
395 
403 GNUNET_GETOPT_option_loglevel (char **level);
404 
405 
413 GNUNET_GETOPT_option_verbose (unsigned int *level);
414 
415 
422 GNUNET_GETOPT_option_logfile (char **logfn);
423 
424 
432 
433 
442 
443 
452 
453 
457 #define GNUNET_GETOPT_OPTION_END \
458  { \
459  '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \
460  }
461 
462 
473 int
474 GNUNET_GETOPT_run (const char *binaryOptions,
476  unsigned int argc,
477  char *const *argv);
478 
479 
480 #if 0 /* keep Emacsens' auto-indent happy */
481 {
482 #endif
483 #ifdef __cplusplus
484 }
485 #endif
486 
487 /* ifndef GNUNET_GETOPT_LIB_H */
488 #endif
489  /* end of group getopt */
491 
492 /* 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:883
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.
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...
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?