X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Finclude%2Fgnunet_getopt_lib.h;h=ddeeffef4325c0007ac142531e8a4fbc4dd07ac9;hb=2bbb2934dbbe471640c67c3bc672120f35708fd1;hp=cd546905efa62fc51830f164c6f0d7856c6b6761;hpb=9284f998cb1f3e8fafcfd338b328f3d0c35ac179;p=oweals%2Fgnunet.git diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h index cd546905e..ddeeffef4 100644 --- a/src/include/gnunet_getopt_lib.h +++ b/src/include/gnunet_getopt_lib.h @@ -2,20 +2,20 @@ This file is part of GNUnet. Copyright (C) 2001-2013 GNUnet e.V. - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + SPDX-License-Identifier: AGPL3.0-or-later */ /** @@ -130,11 +130,22 @@ struct GNUNET_GETOPT_CommandLineOption */ int require_argument; + /** + * Is the presence of this option mandatory? + */ + int option_mandatory; + /** * Handler for the option. */ GNUNET_GETOPT_CommandLineOptionProcessor processor; + /** + * Function to call on @e scls to clean up after processing all + * the arguments. Can be NULL. + */ + void (*cleaner)(void *cls); + /** * Specific closure to pass to the processor. */ @@ -150,7 +161,7 @@ struct GNUNET_GETOPT_CommandLineOption * @param about string with brief description of the application */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_HELP (const char *about); +GNUNET_GETOPT_option_help (const char *about); /** @@ -160,7 +171,7 @@ GNUNET_GETOPT_OPTION_HELP (const char *about); * @param version string with the version number */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_VERSION (const char *version); +GNUNET_GETOPT_option_version (const char *version); @@ -170,7 +181,7 @@ GNUNET_GETOPT_OPTION_VERSION (const char *version); * @param[out] logfn set to the name of the logfile */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_LOGFILE (char **logfn); +GNUNET_GETOPT_option_logfile (char **logfn); /** @@ -183,7 +194,7 @@ GNUNET_GETOPT_OPTION_LOGFILE (char **logfn); * @param[out] str set to the string */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_STRING (char shortName, +GNUNET_GETOPT_option_string (char shortName, const char *name, const char *argumentHelp, const char *description, @@ -199,13 +210,49 @@ GNUNET_GETOPT_OPTION_STRING (char shortName, * @param[out] str set to the string */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_FILENAME (char shortName, +GNUNET_GETOPT_option_filename (char shortName, const char *name, const char *argumentHelp, const char *description, char **str); +/** + * Allow user to specify a binary value using Crockford + * Base32 encoding. + * + * @param shortName short name of the option + * @param name long name of the option + * @param argumentHelp help text for the option argument + * @param description long help text for the option + * @param[out] val binary value decoded from Crockford Base32-encoded argument + * @param val_size size of @a val in bytes + */ +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 where the size of the binary value is + * automatically determined from its type. + * + * @param shortName short name of the option + * @param name long name of the option + * @param argumentHelp help text for the option argument + * @param description long help text for the option + * @param[out] val binary value decoded from Crockford Base32-encoded argument; + * size is determined by type (sizeof (*val)). + */ +#define GNUNET_GETOPT_option_base32_auto(shortName,name,argumentHelp,description,val) \ + GNUNET_GETOPT_option_base32_fixed_size(shortName,name,argumentHelp,description,val,sizeof(*val)) + + /** * Allow user to specify a flag (which internally means setting * an integer to 1/#GNUNET_YES/#GNUNET_OK. @@ -216,10 +263,10 @@ GNUNET_GETOPT_OPTION_FILENAME (char shortName, * @param[out] val set to 1 if the option is present */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_SET_ONE (char shortName, - const char *name, - const char *description, - int *val); +GNUNET_GETOPT_option_flag (char shortName, + const char *name, + const char *description, + int *val); /** @@ -232,11 +279,28 @@ GNUNET_GETOPT_OPTION_SET_ONE (char shortName, * @param[out] val set to the value specified at the command line */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_SET_UINT (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - unsigned int *val); +GNUNET_GETOPT_option_uint (char shortName, + const char *name, + const char *argumentHelp, + const char *description, + unsigned int *val); + + +/** + * Allow user to specify an uint16_t. + * + * @param shortName short name of the option + * @param name long name of the option + * @param argumentHelp help text for the option argument + * @param description long help text for the option + * @param[out] val set to the value specified at the command line + */ +struct GNUNET_GETOPT_CommandLineOption +GNUNET_GETOPT_option_uint16 (char shortName, + const char *name, + const char *argumentHelp, + const char *description, + uint16_t *val); /** @@ -249,11 +313,11 @@ GNUNET_GETOPT_OPTION_SET_UINT (char shortName, * @param[out] val set to the value specified at the command line */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_SET_ULONG (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - unsigned long long *val); +GNUNET_GETOPT_option_ulong (char shortName, + const char *name, + const char *argumentHelp, + const char *description, + unsigned long long *val); /** @@ -267,11 +331,29 @@ GNUNET_GETOPT_OPTION_SET_ULONG (char shortName, * @param[out] val set to the time specified at the command line */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_SET_RELATIVE_TIME (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - struct GNUNET_TIME_Relative *val); +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_Absolute` + * (using human-readable "fancy" time). + * + * @param shortName short name of the option + * @param name long name of the option + * @param argumentHelp help text for the option argument + * @param description long help text for the option + * @param[out] val set to the time specified at the command line + */ +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); /** @@ -284,10 +366,10 @@ GNUNET_GETOPT_OPTION_SET_RELATIVE_TIME (char shortName, * @param[out] val set to 1 if the option is present */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_INCREMENT_VALUE (char shortName, - const char *name, - const char *description, - unsigned int *val); +GNUNET_GETOPT_option_increment_uint (char shortName, + const char *name, + const char *description, + unsigned int *val); /** @@ -297,7 +379,7 @@ GNUNET_GETOPT_OPTION_INCREMENT_VALUE (char shortName, * @param[out] level set to the log level */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_LOGLEVEL (char **level); +GNUNET_GETOPT_option_loglevel (char **level); /** @@ -307,7 +389,7 @@ GNUNET_GETOPT_OPTION_LOGLEVEL (char **level); * @param[out] level set to the verbosity level */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_VERBOSE (int *level); +GNUNET_GETOPT_option_verbose (unsigned int *level); /** @@ -316,7 +398,7 @@ GNUNET_GETOPT_OPTION_VERBOSE (int *level); * @param[out] logfn set to the name of the logfile */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_LOGFILE (char **logfn); +GNUNET_GETOPT_option_logfile (char **logfn); /** @@ -325,14 +407,24 @@ GNUNET_GETOPT_OPTION_LOGFILE (char **logfn); * @param[out] fn set to the name of the configuration file */ struct GNUNET_GETOPT_CommandLineOption -GNUNET_GETOPT_OPTION_CFG_FILE (char **fn); +GNUNET_GETOPT_option_cfgfile (char **fn); + + +/** + * Make the given option mandatory. + * + * @param opt option to modify + * @return @a opt with the mandatory flag set. + */ +struct GNUNET_GETOPT_CommandLineOption +GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt); /** * Marker for the end of the list of options. */ #define GNUNET_GETOPT_OPTION_END \ - { '\0', NULL, NULL, NULL, 0, NULL, NULL } + { '\0', NULL, NULL, NULL, 0, 0, NULL, NULL, NULL } /**