diff options
Diffstat (limited to 'subopt-helper.c')
-rw-r--r-- | subopt-helper.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/subopt-helper.c b/subopt-helper.c index 0cf2299899..9a7332dc13 100644 --- a/subopt-helper.c +++ b/subopt-helper.c @@ -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 @@ int subopt_parse( char const * const str, opt_t * opts ) } 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 @@ static char const * parse_int( char const * const str, int * const valp ) 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 ) { |