[MPlayer-dev-eng] [PATCH] support float types in subopt helper

Joey Parrish joey at nicewarrior.org
Thu Oct 6 18:51:23 CEST 2005


Hello,

Here's a patch to support float arguments in subopt helper.
It's very straight-forward.  I will commit either Friday or this weekend
if there are no objections.

--Joey

-- 
Me: "Isn't Kennedy as real as Colonel Sanders?"
Chad: "... Which Kennedy?"
-------------- next part --------------
Index: subopt-helper.c
===================================================================
RCS file: /cvsroot/mplayer/main/subopt-helper.c,v
retrieving revision 1.8
diff -u -r1.8 subopt-helper.c
--- subopt-helper.c	27 Sep 2005 08:52:40 -0000	1.8
+++ subopt-helper.c	6 Oct 2005 16:35:22 -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 )
 {
Index: subopt-helper.h
===================================================================
RCS file: /cvsroot/mplayer/main/subopt-helper.h,v
retrieving revision 1.5
diff -u -r1.5 subopt-helper.h
--- subopt-helper.h	16 Jun 2005 09:08:07 -0000	1.5
+++ subopt-helper.h	6 Oct 2005 16:35:22 -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 *);
 


More information about the MPlayer-dev-eng mailing list