From 326361b18e368e11f08c9ac1f05c4fc6d514f76e Mon Sep 17 00:00:00 2001 From: joey Date: Mon, 10 Oct 2005 12:56:44 +0000 Subject: support float arguments in subopt helper. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@16721 b3059339-0415-0410-9bf9-f77b7e298cf2 --- subopt-helper.c | 19 +++++++++++++++++++ subopt-helper.h | 1 + 2 files changed, 20 insertions(+) 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 ) { diff --git a/subopt-helper.h b/subopt-helper.h index 37ea6d6790..29e7461b9c 100644 --- a/subopt-helper.h +++ b/subopt-helper.h @@ -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 *); -- cgit v1.2.3