Exemple #1
0
double optionDouble(char *name, double defaultVal)
/* Return double value or default value if not set */
{
char *s = optGet(name);
char *valEnd;
double val;
if (s == NULL)
    return defaultVal;

val = strtod(s, &valEnd);
if ((*s == '\0') || (*valEnd != '\0'))
    errAbort("value of -%s is not a valid double: \"%s\"", name, s);
return val;
}
Exemple #2
0
float optionFloat(char *name, float defaultVal)
/* Return floating point value or default value if not set. */
{
char *s = optGet(name);
char *valEnd;
float val;
if (s == NULL)
    return defaultVal;

val = strtod(s, &valEnd);
if ((*s == '\0') || (*valEnd != '\0'))
    errAbort("value of -%s is not a valid float: \"%s\"", name, s);
return val;
}
Exemple #3
0
long long optionLongLong(char *name, long long defaultVal)
/* Return long long value of named option, or default value
 * if not set. */
{
char *s = optGet(name);
char *valEnd;
long long val;
if (s == NULL)
    return defaultVal;
if (sameString(s,"on"))
    return defaultVal;
val = strtoll(s, &valEnd, 10);
if ((*s == '\0') || (*valEnd != '\0'))
    errAbort("value of -%s is not a valid long long: \"%s\"", name, s);
return val;
}
Exemple #4
0
int optionInt(char *name, int defaultVal)
/* Return integer value of named option, or default value
 * if not set. */
{
char *s = optGet(name);
char *valEnd;
int val;
if (s == NULL)
    return defaultVal;
if (sameString(s,"on"))
    return defaultVal;
val = strtol(s, &valEnd, 10);
if ((*s == '\0') || (*valEnd != '\0'))
    errAbort("value of -%s is not a valid integer: \"%s\"", name, s);
return val;
}
Exemple #5
0
char *optionVal(char *name, char *defaultVal)
/* Return named option if in options hash, otherwise default. */
{
char *ret;
/* if a optionSpec was used, make sure this option is not a multi option */
if(optionSpecification != NULL) {
    struct optionSpec *spec = matchingOption(name, optionSpecification);
    if(spec != NULL && (spec->flags & OPTION_MULTI))    
        errAbort("ERROR: optionVal cannot be used to get the value of an OPTION_MULTI");
}

ret = optGet(name);
if (ret == NULL)
     ret = defaultVal;
return ret;
}
Exemple #6
0
int optionInt(char *name, int defaultVal)
/* Return integer value of named option, or default value
 * if not set. */
{
char *s = optGet(name);
char *valEnd;
long lval;
if (s == NULL)
    return defaultVal;
if (sameString(s,"on"))
    return defaultVal;
lval = strtol(s, &valEnd, 10);  // use strtol since strtoi does not exist
if ((*s == '\0') || (*valEnd != '\0'))
    errAbort("value of -%s is not a valid integer: \"%s\"", name, s);
if (lval > INT_MAX)
    errAbort("value of -%s is is too large: %ld, integer maximum is %d", name, lval, INT_MAX);
if (lval < INT_MIN)
    errAbort("value of -%s is is too small: %ld, integer minimum is %d", name, lval, INT_MIN);
return lval;
}
Exemple #7
0
void optExitOnInvalid()
{
    const char *val = optGet("help", 'h', 0, 0, "", "");
    if(val[0] != '\0' || g_opts.isInvalid)
    {
        int i;
        printf("Usage: %s [options]\r\n\r\nOptions:\r\n", g_opts.argv[0]);
        for(i = 0; i < g_opts.nCount; i++){
            OptCmdOptions *opt = &g_opts.opts[i];
            char *arg, *must;
            arg = (opt->has_argument) ? "argument" : "";
            must = (opt->is_mandated) ? "MUST" : "";
            if(opt->short_name != 0)
                printf("  -%c, --%s %s\t%s\t%s\r\n", opt->short_name, opt->long_name, arg, must, opt->description);
            else
                printf("  --%s %s\t%s\t%s\r\n", opt->long_name, arg, must, opt->description);
        }
        if(g_opts.isInvalid)
            printf("\r\n\r\nError: Some mandated option(s) are not set");
        exit(0);
    }
    optFreeOptions();
}
Exemple #8
0
void optionMustExist(char *name)
/* Abort if option has not been set. */
{
if (optGet(name) == NULL)
    errAbort("Missing required command line flag %s", name);
}
Exemple #9
0
boolean optionExists(char *name)
/* Return TRUE if option has been set. */
{
return optGet(name) != NULL;
}