shhopt.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef SHHOPT_H
  2. #define SHHOPT_H
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. /* constants for recognized option types. */
  8. typedef enum
  9. {
  10. OPT_END, /* nothing. used as ending element. */
  11. OPT_FLAG, /* no argument following. sets variable to 1. */
  12. OPT_STRING, /* string argument. */
  13. OPT_INT, /* signed integer argument. */
  14. OPT_UINT, /* unsigned integer argument. */
  15. OPT_LONG, /* signed long integer argument. */
  16. OPT_ULONG, /* unsigned long integer argument. */
  17. OPT_FLOAT /* floating point argument. */
  18. } optArgType;
  19. /* flags modifying the default way options are handeled. */
  20. #define OPT_CALLFUNC 1 /* pass argument to a function. */
  21. typedef struct
  22. {
  23. char shortName; /* short option name. */
  24. const char *longName; /* long option name, not including '--'. */
  25. optArgType type; /* option type. */
  26. void *arg; /* pointer to variable to fill with argument,
  27. * or pointer to function if type == OPT_FUNC. */
  28. int flags; /* modifier flags. */
  29. } optStruct;
  30. typedef struct
  31. {
  32. unsigned char short_allowed; /* boolean */
  33. /* The syntax may include short (i.e. one-character) options.
  34. These options may be stacked within a single token (e.g.
  35. -abc = -a -b -c). If this value is not true, the short option
  36. member of the option table entry is meaningless and long
  37. options may have either one or two dashes.
  38. */
  39. unsigned char allowNegNum; /* boolean */
  40. /* Anything that starts with - and then a digit is a numeric
  41. parameter, not an option
  42. */
  43. optStruct *opt_table;
  44. } optStruct2;
  45. void optSetFatalFunc(void (*f) (const char *, ...));
  46. void optParseOptions(int *argc, char *argv[],
  47. optStruct opt[], int allowNegNum);
  48. void optParseOptions2(int *const argc_p, char *argv[],
  49. const optStruct2 opt, const unsigned long flags);
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif