procconf.h 2.4 KB

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