cmdline.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @file cmdline.h
  3. * @author Olaf Kähler
  4. */
  5. #ifndef _CMDLINE_H_
  6. #define _CMDLINE_H_
  7. #warning "CmdLine is deprecated ! Please use baselib/Config"
  8. #ifdef __cplusplus
  9. #define DEFAULT_ARGUMENT_VALUE(x) = (x)
  10. extern "C" {
  11. #else
  12. #define DEFAULT_ARGUMENT_VALUE(x)
  13. #endif
  14. /** This struct describes a singe command line parameter, with help message,
  15. default values and so on...
  16. */
  17. struct CmdLineOption {
  18. /** The word required on the command line, e.g. "verbose" or "seq"
  19. NULL means end of a list of parameters
  20. */
  21. const char *name;
  22. /** Description of the parameter in the help message
  23. NULL means, option is not shown in help
  24. */
  25. const char *description;
  26. /** Default value, e.g. "~/.config" or "0 0 1"
  27. NULL means no default will be set
  28. */
  29. const char *default_value;
  30. /** scanf-like parameters of the option, e.g. "%s" or "%i %i %i"
  31. NULL means no parameters follow
  32. */
  33. const char *parameters;
  34. /** Storage place for parameters. If there are no parameters, storage
  35. will be set to 1 if the option was found, 0 otherwise
  36. NULL means, nothing is to be stored
  37. */
  38. void *storage;
  39. };
  40. /** Function to parse the commandline using the structure defined above
  41. @param argc Number of commandline arguments
  42. @param argv argv as it is passed to main()
  43. @param options Array of structures of the options to search for
  44. @param moreParameters all parameters not recognized are stored here in order of appearance
  45. @param helpText Text printed in case "help" or "h" is found
  46. @return 1 if help mode was active
  47. @return negative number if an error occured
  48. @return 0 if everything went fine
  49. */
  50. int parse_arguments(int argc, const char **argv,
  51. const struct CmdLineOption *options,
  52. char **moreParameters DEFAULT_ARGUMENT_VALUE(0),
  53. const char *helpText DEFAULT_ARGUMENT_VALUE(0));
  54. /** Function to print help text using the structure defined above */
  55. int print_help ( const struct CmdLineOption *options, const char *helpText DEFAULT_ARGUMENT_VALUE(0) );
  56. #ifdef __cplusplus
  57. } /* extern C */
  58. #endif
  59. #undef DEFAULT_ARGUMENT_VALUE
  60. #endif