procconf.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifdef __cplusplus
  2. extern "C" {
  3. #endif
  4. #include <limits.h> /* for UINT_MAX */
  5. typedef enum {
  6. CF_CHAR,
  7. CF_STRING,
  8. CF_NE_STRING,
  9. CF_INT,
  10. CF_NON_NEG_INT,
  11. CF_POS_INT,
  12. CF_FLOAT,
  13. CF_NON_NEG_FLOAT,
  14. CF_POS_FLOAT,
  15. CF_SWITCH,
  16. CF_NOCONF, /* option to specify that config file should not be read */
  17. CF_PDEBUG, /* option to turn on debugging, with positive integer value */
  18. CF_SDEBUG, /* option to turn on debugging, without a value */
  19. CF_ENDLIST /* End of option list */
  20. } cf_type;
  21. typedef enum {
  22. CF_NONE, CF_ARGS, CF_FILE
  23. } cf_source;
  24. #define CF_NOTFLAG (UINT_MAX & ~(UINT_MAX >> 1))
  25. /*
  26. * Structure for passing varname/value pairs.
  27. * This gives the variable names to search for, and allows variable names to
  28. * mapped to characters so that the characters may be used as indexes into the
  29. * results array.
  30. */
  31. typedef struct {
  32. unsigned outind; /* Single-character option, or option output index */
  33. char *varname; /* Long name, for config file and eventually long option */
  34. cf_type type; /* Option type */
  35. const void *addr; /* Address of variable associated with this option */
  36. int value; /* Value to assign to switch options */
  37. } confvar_t;
  38. /*
  39. * Structure for returning assigned values.
  40. */
  41. typedef struct confval_struct {
  42. const char *strval; /* String form of value */
  43. cf_source source; /* Where value was taken from */
  44. unsigned index; /* Relative position of this instance */
  45. union {
  46. int intval;
  47. unsigned int nnint;
  48. double floatval;
  49. const char *string;
  50. int switchval;
  51. char charval;
  52. } value;
  53. struct confval_struct *next;
  54. } confval;
  55. /* Information about the values assigned to a particular option */
  56. typedef struct {
  57. int num; /* number of instances of this option */
  58. confvar_t *confvar; /* which option descriptor this corresponds to */
  59. confval **values; /* Start of pointers to values for this option */
  60. } cf_option;
  61. typedef struct {
  62. cf_option *optVals; /* All option values */
  63. cf_option **map; /* Option values indexed by option-char / option-index */
  64. } confdata_t;
  65. const char *
  66. procOpts(int *argc, char **argv[], const confvar_t optConf[], confdata_t *confdata, const char confFile[], const char name[],
  67. const char usage[]);
  68. #ifdef __cplusplus
  69. }
  70. #endif