2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_getopt_lib.h
23 * @brief command line parsing and --help formatting
25 * @author Christian Grothoff
28 #ifndef GNUNET_GETOPT_LIB_H
29 #define GNUNET_GETOPT_LIB_H
34 #if 0 /* keep Emacsens' auto-indent happy */
39 #include "gnunet_configuration_lib.h"
42 * @brief General context for command line processors.
44 struct GNUNET_GETOPT_CommandLineProcessorContext
48 * Name of the application
50 const char *binaryName;
53 * Name of application with option summary
55 const char *binaryOptions;
58 * Array with all command line options.
60 const struct GNUNET_GETOPT_CommandLineOption *allOptions;
63 * Original command line
68 * Total number of argv's.
75 unsigned int currentArgument;
80 * @brief Process a command line option
82 * @param ctx context for all options
83 * @param scls specific closure (for this processor)
84 * @param option long name of the option (i.e. "config" for --config)
85 * @param value argument, NULL if none was given
86 * @return GNUNET_OK to continue processing other options, GNUNET_SYSERR to abort
89 int (*GNUNET_GETOPT_CommandLineOptionProcessor) (struct
90 GNUNET_GETOPT_CommandLineProcessorContext
96 * @brief Definition of a command line option.
98 struct GNUNET_GETOPT_CommandLineOption
102 * Short name of the option (use '\\0' for none).
104 const char shortName;
107 * Long name of the option (may not be NULL)
112 * Name of the argument for the user in help text
114 const char *argumentHelp;
117 * Help text for the option (description)
119 const char *description;
122 * Is an argument required? 0: GNUNET_NO (includes optional), 1: GNUNET_YES.
124 int require_argument;
127 * Handler for the option.
129 GNUNET_GETOPT_CommandLineOptionProcessor processor;
132 * Specific closure to pass to the processor.
139 * Macro defining the option to print the command line
142 * @param about string with brief description of the application
144 #define GNUNET_GETOPT_OPTION_HELP(about) \
145 { 'h', "help", (const char *) NULL, gettext_noop("print this help"), 0, &GNUNET_GETOPT_format_help_, (void *) about }
148 * Macro defining the option to print the version of
151 * @param version string with the version number
153 #define GNUNET_GETOPT_OPTION_VERSION(version) \
154 { 'v', "version", (const char *) NULL, gettext_noop("print the version number"), 0, &GNUNET_GETOPT_print_version_, (void *) version }
159 #define GNUNET_GETOPT_OPTION_LOGFILE(logfn) \
160 { 'l', "logfile", "LOGFILE", gettext_noop("configure logging to write logs to LOGFILE"), 1, &GNUNET_GETOPT_set_string, (void *) logfn }
163 * Set the configuration option for logging.
165 #define GNUNET_GETOPT_OPTION_LOGLEVEL(loglev) \
166 { 'L', "log", "LOGLEVEL", gettext_noop("configure logging to use LOGLEVEL"), 1, &GNUNET_GETOPT_set_string, (void *) loglev }
169 * Get number of verbose flags
171 #define GNUNET_GETOPT_OPTION_VERBOSE(level) \
172 { 'V', "verbose", (const char *) NULL, gettext_noop("be verbose"), 0, &GNUNET_GETOPT_increment_value, (void *) level }
175 * Get configuration file name
177 #define GNUNET_GETOPT_OPTION_CFG_FILE(fn) \
178 { 'c', "config", "FILENAME", gettext_noop("use configuration file FILENAME"), 1, &GNUNET_GETOPT_set_string, (void *) fn }
181 * Marker to end the list of options.
183 #define GNUNET_GETOPT_OPTION_END \
184 { '\0', NULL, NULL, NULL, 0, NULL, NULL }
187 * Parse the command line.
189 * @param binaryOptions Name of application with option summary
190 * @param allOptions defined options and handlers
191 * @param argc number of arguments
192 * @param argv actual arguments
193 * @return index into argv with first non-option
194 * argument, or GNUNET_SYSERR on error
196 int GNUNET_GETOPT_run (const char *binaryOptions,
197 const struct GNUNET_GETOPT_CommandLineOption
198 *allOptions, unsigned int argc, char *const *argv);
203 int GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext
204 *ctx, void *scls, const char *option,
210 int GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext
211 *ctx, void *scls, const char *option,
217 int GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext
218 *ctx, void *scls, const char *option,
224 int GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext
225 *ctx, void *scls, const char *option,
232 GNUNET_GETOPT_increment_value (struct
233 GNUNET_GETOPT_CommandLineProcessorContext *ctx,
234 void *scls, const char *option,
237 /* *************** internal prototypes - use macros above! ************* */
242 int GNUNET_GETOPT_format_help_ (struct
243 GNUNET_GETOPT_CommandLineProcessorContext
244 *ctx, void *scls, const char *option,
250 int GNUNET_GETOPT_print_version_ (struct
251 GNUNET_GETOPT_CommandLineProcessorContext
252 *ctx, void *scls, const char *option,
255 #if 0 /* keep Emacsens' auto-indent happy */
263 /* ifndef GNUNET_GETOPT_LIB_H */
265 /* end of gnunet_getopt_lib.h */