123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- /**
- * @file cmdline.h
- * @author Olaf Kähler
- */
- #ifndef _CMDLINE_H_
- #define _CMDLINE_H_
- #warning "CmdLine is deprecated ! Please use baselib/Config"
- #ifdef __cplusplus
- #define DEFAULT_ARGUMENT_VALUE(x) = (x)
- extern "C" {
- #else
- #define DEFAULT_ARGUMENT_VALUE(x)
- #endif
- /** This struct describes a singe command line parameter, with help message,
- default values and so on...
- */
- struct CmdLineOption {
- /** The word required on the command line, e.g. "verbose" or "seq"
- NULL means end of a list of parameters
- */
- const char *name;
- /** Description of the parameter in the help message
- NULL means, option is not shown in help
- */
- const char *description;
- /** Default value, e.g. "~/.config" or "0 0 1"
- NULL means no default will be set
- */
- const char *default_value;
- /** scanf-like parameters of the option, e.g. "%s" or "%i %i %i"
- NULL means no parameters follow
- */
- const char *parameters;
- /** Storage place for parameters. If there are no parameters, storage
- will be set to 1 if the option was found, 0 otherwise
- NULL means, nothing is to be stored
- */
- void *storage;
- };
- /** Function to parse the commandline using the structure defined above
- @param argc Number of commandline arguments
- @param argv argv as it is passed to main()
- @param options Array of structures of the options to search for
- @param moreParameters all parameters not recognized are stored here in order of appearance
- @param helpText Text printed in case "help" or "h" is found
- @return 1 if help mode was active
- @return negative number if an error occured
- @return 0 if everything went fine
- */
- int parse_arguments(int argc, const char **argv,
- const struct CmdLineOption *options,
- char **moreParameters DEFAULT_ARGUMENT_VALUE(0),
- const char *helpText DEFAULT_ARGUMENT_VALUE(0));
- /** Function to print help text using the structure defined above */
- int print_help ( const struct CmdLineOption *options, const char *helpText DEFAULT_ARGUMENT_VALUE(0) );
- #ifdef __cplusplus
- } /* extern C */
- #endif
- #undef DEFAULT_ARGUMENT_VALUE
- #endif
|