00001 /* Stuff to process options out of command line. 00002 * 00003 * This file is copyright 2002 Jim Kent, but license is hereby 00004 * granted for all use - public, private or commercial. */ 00005 00006 #ifndef OPTIONS_H 00007 00008 /* Types for options */ 00009 #define OPTION_BOOLEAN 0x01 00010 #define OPTION_STRING 0x02 00011 #define OPTION_INT 0x04 00012 #define OPTION_FLOAT 0x10 00013 #define OPTION_LONG_LONG 0x20 00014 #define OPTION_MULTI 0x40 00015 #define OPTION_DOUBLE 0x80 00016 00017 struct optionSpec 00018 /* Specification of a single option. An array of these are passed 00019 * to optionInit() to validate options. */ 00020 { 00021 char *name; /* option name */ 00022 unsigned flags; /* Flags for option, specifies types */ 00023 }; 00024 00025 char *optionVal(char *name, char *defaultVal); 00026 /* Return named option if in options hash, otherwise default. */ 00027 00028 int optionInt(char *name, int defaultVal); 00029 /* Return integer value of named option, or default value 00030 * if not set. */ 00031 00032 long long optionLongLong(char *name, long long defaultVal); 00033 /* Return long long value of named option, or default value 00034 * if not set. */ 00035 00036 float optionFloat(char *name, float defaultVal); 00037 /* Return floating point value or default value if not set. */ 00038 00039 struct slName *optionMultiVal(char *name, struct slName *defaultVal); 00040 /* Returns a list of the values assocated with a named option if in options hash, otherwise default. */ 00041 00042 double optionDouble(char *name, double defaultVal); 00043 /* Return double value or default value if not set */ 00044 00045 boolean optionExists(char *name); 00046 /* Return TRUE if option has been set. */ 00047 00048 void optionMustExist(char *name); 00049 /* Abort if option has not been set. */ 00050 00051 void optionInit(int *pArgc, char *argv[], struct optionSpec *optionSpecs); 00052 /* Read options in command line into options hash. 00053 * Options come in three forms: 00054 * -option words starting with dash 00055 * option=val words with = in the middle 00056 * -option=val combining the two. 00057 * The resulting hash will be keyed by the option name with the val 00058 * string for value. For '-option' types the value is 'on'. 00059 * The words in argv are parsed in assending order. If a word of 00060 * "--" is encountered, argument parsing stops. 00061 * If optionSpecs is not NULL, it is an array of optionSpec that are 00062 * used to validate the options. An option must exist in the array 00063 * and the value must be convertable to the type specified in flags. 00064 * Boolean options have must no value, all other options must have one. 00065 * Array is terminated by a optionSpec with a NULL name. 00066 * If array NULL, no validation is done. 00067 */ 00068 00069 void optionHash(int *pArgc, char *argv[]); 00070 /* Read options in command line into options hash. 00071 * Options come in three forms: 00072 * -option words starting with dash 00073 * option=val words with = in the middle 00074 * -option=val combining the two. 00075 * The resulting hash will be keyed by the option name with the val 00076 * string for value. For '-option' types the value is 'on'. 00077 * The words in argv are parsed in assending order. If a word of 00078 * "--" is encountered, argument parsing stops. */ 00079 00080 void optionHashSome(int *pArgc, char *argv[], boolean justFirst); 00081 /* Set up option hash from command line, optionally only adding 00082 * up to first non-optional word. */ 00083 00084 struct hash *optionParseIntoHash(int *pArgc, char *argv[], boolean justFirst); 00085 /* Read options in argc/argv into a hash of your own choosing. */ 00086 00087 #endif /* OPTIONS_H */ 00088
1.5.2