changeset 16720:f73adf296f1e

support float arguments in subopt helper.
author joey
date Mon, 10 Oct 2005 12:56:44 +0000
parents 2acb2b765197
children bd815e9973f2
files subopt-helper.c subopt-helper.h
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 )
 {
--- 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 *);