# HG changeset patch # User joey # Date 1128949004 0 # Node ID f73adf296f1ecb93a367bb790afec96d42e45f54 # Parent 2acb2b765197f9ca82e2773fbfd5ead1e11fac40 support float arguments in subopt helper. diff -r 2acb2b765197 -r f73adf296f1e subopt-helper.c --- a/subopt-helper.c Mon Oct 10 12:56:17 2005 +0000 +++ b/subopt-helper.c Mon Oct 10 12:56:44 2005 +0000 @@ -32,6 +32,7 @@ /* prototypes for argument parsing */ static char const * parse_int( char const * const str, int * const valp ); static char const * parse_str( char const * const str, strarg_t * const valp ); +static char const * parse_float( char const * const str, float * const valp ); /** * \brief Try to parse all options in str and fail if it was not possible. @@ -162,6 +163,10 @@ } break; } + case OPT_ARG_FLOAT: + last = parse_float( &str[parse_pos], + (float *)opts[idx].valp ); + break; default: assert( 0 && "Arg type of suboption doesn't exist!" ); last = NULL; // break parsing! @@ -247,6 +252,20 @@ return endp; } +static char const * parse_float( char const * const str, float * const valp ) +{ + char * endp; + + assert( str && "parse_float(): str == NULL" ); + + *valp = strtof( str, &endp ); + + /* nothing was converted */ + if ( str == endp ) { return NULL; } + + return endp; +} + #define QUOTE_CHAR '%' static char const * parse_str( char const * str, strarg_t * const valp ) { diff -r 2acb2b765197 -r f73adf296f1e subopt-helper.h --- a/subopt-helper.h Mon Oct 10 12:56:17 2005 +0000 +++ b/subopt-helper.h Mon Oct 10 12:56:44 2005 +0000 @@ -13,6 +13,7 @@ #define OPT_ARG_INT 1 #define OPT_ARG_STR 2 #define OPT_ARG_MSTRZ 3 ///< A malloced, zero terminated string, use free()! +#define OPT_ARG_FLOAT 4 typedef int (*opt_test_f)(void *);