#ifndef OPTIONS_H #define OPTIONS_H /* What an option can return */ typedef int opttype; #define OPT_INT 1 /* Integer */ #define OPT_FLOAT 2 /* Floating point value */ #define OPT_STRING 3 /* String */ #define OPT_BOOL 4 /* Boolean (integer, value 0 or 1) */ #define OPT_ARRAY 0x100 /* Flag: return an array */ /* Option string, type, and pointer to return variable. */ typedef struct option { char *name; /* Option name without the '-' */ opttype type; /* Option return type, see above */ void *retptr; /* Address of return variable */ int *otherptr; /* Returns other data based on opt. type */ } option; /* Use of otherptr: * OPT_INT, OPT_FLOAT, OPT_STRING, OPT_BOOL: 1 if option was present * OPT_ARRAY: number of elements read * If otherptr == NULL, it is ignored. If an option is not present, its * otherptr's value is not modified. */ /* List of options should be terminated with name == NULL. */ int do_options(int, char **, option *); #endif