inc/options.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  optionSpec

Defines

#define OPTION_BOOLEAN   0x01
#define OPTION_STRING   0x02
#define OPTION_INT   0x04
#define OPTION_FLOAT   0x10
#define OPTION_LONG_LONG   0x20
#define OPTION_MULTI   0x40
#define OPTION_DOUBLE   0x80

Functions

char * optionVal (char *name, char *defaultVal)
int optionInt (char *name, int defaultVal)
long long optionLongLong (char *name, long long defaultVal)
float optionFloat (char *name, float defaultVal)
slNameoptionMultiVal (char *name, struct slName *defaultVal)
double optionDouble (char *name, double defaultVal)
boolean optionExists (char *name)
void optionMustExist (char *name)
void optionInit (int *pArgc, char *argv[], struct optionSpec *optionSpecs)
void optionHash (int *pArgc, char *argv[])
void optionHashSome (int *pArgc, char *argv[], boolean justFirst)
hashoptionParseIntoHash (int *pArgc, char *argv[], boolean justFirst)


Define Documentation

#define OPTION_BOOLEAN   0x01

Definition at line 9 of file options.h.

Referenced by validateOption().

#define OPTION_DOUBLE   0x80

Definition at line 15 of file options.h.

Referenced by validateOption().

#define OPTION_FLOAT   0x10

Definition at line 12 of file options.h.

Referenced by validateOption().

#define OPTION_INT   0x04

Definition at line 11 of file options.h.

Referenced by validateOption().

#define OPTION_LONG_LONG   0x20

Definition at line 13 of file options.h.

Referenced by validateOption().

#define OPTION_MULTI   0x40

Definition at line 14 of file options.h.

Referenced by optionVal(), and parseAnOption().

#define OPTION_STRING   0x02

Definition at line 10 of file options.h.

Referenced by parseMultiOption(), and validateOption().


Function Documentation

double optionDouble ( char *  name,
double  defaultVal 
)

Definition at line 379 of file options.c.

References errAbort(), and optGet().

00381 {
00382 char *s = optGet(name);
00383 char *valEnd;
00384 double val;
00385 if (s == NULL)
00386     return defaultVal;
00387 
00388 val = strtod(s, &valEnd);
00389 if ((*s == '\0') || (*valEnd != '\0'))
00390     errAbort("value of -%s is not a valid double: \"%s\"", name, s);
00391 return val;
00392 }

Here is the call graph for this function:

boolean optionExists ( char *  name  ) 

Definition at line 394 of file options.c.

References optGet().

Referenced by gfClient(), logDaemonize(), main(), searchOneStrand(), and setOptions().

00396 {
00397 return optGet(name) != NULL;
00398 }

Here is the call graph for this function:

Here is the caller graph for this function:

float optionFloat ( char *  name,
float  defaultVal 
)

Definition at line 350 of file options.c.

References errAbort(), and optGet().

Referenced by main().

00352 {
00353 char *s = optGet(name);
00354 char *valEnd;
00355 float val;
00356 if (s == NULL)
00357     return defaultVal;
00358 
00359 val = strtod(s, &valEnd);
00360 if ((*s == '\0') || (*valEnd != '\0'))
00361     errAbort("value of -%s is not a valid float: \"%s\"", name, s);
00362 return val;
00363 }

Here is the call graph for this function:

Here is the caller graph for this function:

void optionHash ( int *  pArgc,
char *  argv[] 
)

Definition at line 253 of file options.c.

References FALSE, and optionHashSome().

00255                               :
00256  *      -option         words starting with dash
00257  *      option=val      words with = in the middle
00258  *      -option=val     combining the two.
00259  * The resulting hash will be keyed by the option name with the val
00260  * string for value.  For '-option' types the value is 'on'. */
00261 {
00262 optionHashSome(pArgc, argv, FALSE);
00263 }

Here is the call graph for this function:

void optionHashSome ( int *  pArgc,
char *  argv[],
boolean  justFirst 
)

Definition at line 242 of file options.c.

References options, parseOptions(), and setOptions().

Referenced by optionHash().

00245 {
00246 if (options == NULL)
00247     {
00248     struct hash *hash = parseOptions(pArgc, argv, justFirst, NULL);
00249     setOptions(hash);
00250     }
00251 }

Here is the call graph for this function:

Here is the caller graph for this function:

void optionInit ( int *  pArgc,
char *  argv[],
struct optionSpec optionSpecs 
)

Definition at line 265 of file options.c.

References FALSE, options, optionSpecification, optionSpecs, parseOptions(), and setOptions().

Referenced by main().

00267                               :
00268  *      -option         words starting with dash
00269  *      option=val      words with = in the middle
00270  *      -option=val     combining the two.
00271  * The resulting hash will be keyed by the option name with the val
00272  * string for value.  For '-option' types the value is 'on'.
00273  * The words in argv are parsed in assending order.  If a word of
00274  * "--" is encountered, argument parsing stops.
00275  * If optionSpecs is not NULL, it is an array of optionSpec that are
00276  * used to validate the options.  An option must exist in the array
00277  * and the value must be convertable to the type specified in flags.
00278  * Boolean options must no value, all other options must have one.
00279  * Array is terminated by a optionSpec with a NULL name.
00280  * If array NULL, no validation is done.
00281  */
00282 {
00283 if (options == NULL)
00284     {
00285     struct hash *hash = parseOptions(pArgc, argv, FALSE, optionSpecs);
00286     setOptions(hash);
00287     optionSpecification = optionSpecs;
00288     }
00289 }

Here is the call graph for this function:

Here is the caller graph for this function:

int optionInt ( char *  name,
int  defaultVal 
)

Definition at line 316 of file options.c.

References errAbort(), optGet(), and sameString.

Referenced by main(), and setOptions().

00319 {
00320 char *s = optGet(name);
00321 char *valEnd;
00322 int val;
00323 if (s == NULL)
00324     return defaultVal;
00325 if (sameString(s,"on"))
00326     return defaultVal;
00327 val = strtol(s, &valEnd, 10);
00328 if ((*s == '\0') || (*valEnd != '\0'))
00329     errAbort("value of -%s is not a valid integer: \"%s\"", name, s);
00330 return val;
00331 }

Here is the call graph for this function:

Here is the caller graph for this function:

long long optionLongLong ( char *  name,
long long  defaultVal 
)

Definition at line 333 of file options.c.

References errAbort(), optGet(), and sameString.

00336 {
00337 char *s = optGet(name);
00338 char *valEnd;
00339 long long val;
00340 if (s == NULL)
00341     return defaultVal;
00342 if (sameString(s,"on"))
00343     return defaultVal;
00344 val = strtoll(s, &valEnd, 10);
00345 if ((*s == '\0') || (*valEnd != '\0'))
00346     errAbort("value of -%s is not a valid long long: \"%s\"", name, s);
00347 return val;
00348 }

Here is the call graph for this function:

struct slName* optionMultiVal ( char *  name,
struct slName defaultVal 
) [read]

Definition at line 365 of file options.c.

References errAbort(), hashFindVal(), options, and optionSpecification.

00367 {
00368 struct slName *ret;
00369 if(optionSpecification == NULL)
00370     errAbort("ERROR: optionMultiVal can only be used after optionInit is called "
00371              "with a non-NULL optionSpecs");
00372 
00373 ret = hashFindVal(options, name);
00374 if (ret == NULL)
00375      ret = defaultVal;
00376 return ret;
00377 }

Here is the call graph for this function:

void optionMustExist ( char *  name  ) 

Definition at line 400 of file options.c.

References errAbort(), and optGet().

00402 {
00403 if (optGet(name) == NULL)
00404     errAbort("Missing required command line flag %s", name);
00405 }

Here is the call graph for this function:

struct hash* optionParseIntoHash ( int *  pArgc,
char *  argv[],
boolean  justFirst 
) [read]

Definition at line 218 of file options.c.

References parseOptions().

00220                                               :
00221  *      -option         words starting with dash
00222  *      option=val      words with = in the middle
00223  *      -option=val     combining the two.
00224  * The resulting hash will be keyed by the option name with the val
00225  * string for value.  For '-option' types the value is 'on'. */
00226 {
00227 return parseOptions(pArgc, argv, justFirst, NULL);
00228 }

Here is the call graph for this function:

char* optionVal ( char *  name,
char *  defaultVal 
)

Definition at line 299 of file options.c.

References errAbort(), optionSpec::flags, matchingOption(), optGet(), OPTION_MULTI, and optionSpecification.

Referenced by logDaemonize(), and main().

00301 {
00302 char *ret;
00303 /* if a optionSpec was used, make sure this option is not a multi option */
00304 if(optionSpecification != NULL) {
00305     struct optionSpec *spec = matchingOption(name, optionSpecification);
00306     if(spec != NULL && (spec->flags & OPTION_MULTI))    
00307         errAbort("ERROR: optionVal cannot be used to get the value of an OPTION_MULTI");
00308 }
00309 
00310 ret = optGet(name);
00311 if (ret == NULL)
00312      ret = defaultVal;
00313 return ret;
00314 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Tue Dec 25 19:09:31 2007 for blat by  doxygen 1.5.2