[MPlayer-cvslog] CVS: main subopt-helper.c, 1.2, 1.3 subopt-helper.h, 1.2, 1.3

Reimar Döffinger CVS syncmail at mplayerhq.hu
Wed Jan 19 18:10:22 CET 2005


CVS change done by Reimar Döffinger CVS

Update of /cvsroot/mplayer/main
In directory mail:/var2/tmp/cvs-serv11220

Modified Files:
	subopt-helper.c subopt-helper.h 
Log Message:
New suboption type: malloc'ed, zero terminated string


Index: subopt-helper.c
===================================================================
RCS file: /cvsroot/mplayer/main/subopt-helper.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- subopt-helper.c	1 Jan 2005 19:03:22 -0000	1.2
+++ subopt-helper.c	19 Jan 2005 17:10:20 -0000	1.3
@@ -22,6 +22,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
 #include <assert.h>
 
 #ifndef MPDEBUG
@@ -144,6 +145,23 @@
                 last = parse_str( &str[parse_pos],
                                   (strarg_t *)opts[idx].valp );
                 break;
+              case OPT_ARG_MSTRZ:
+                {
+                  char **valp = opts[idx].valp;
+                  strarg_t tmp;
+                  tmp.str = NULL;
+                  tmp.len = 0;
+                  last = parse_str( &str[parse_pos], &tmp );
+                  if (*valp)
+                    free(*valp);
+                  *valp = NULL;
+                  if (tmp.str && tmp.len > 0) {
+                    *valp = malloc(tmp.len + 1);
+                    memcpy(*valp, tmp.str, tmp.len);
+                    *valp[tmp.len] = 0;
+                  }
+                  break;
+                }
               default:
                 assert( 0 && "Arg type of suboption doesn't exist!" );
                 last = NULL; // break parsing!
@@ -237,7 +255,7 @@
     match = &str[strlen(str)];
 
   // empty string or too long
-  if ((match == str) || (match - str > 255))
+  if ((match == str) || (match - str > INT_MAX))
     return NULL;
 
   valp->len = match - str;

Index: subopt-helper.h
===================================================================
RCS file: /cvsroot/mplayer/main/subopt-helper.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- subopt-helper.h	31 Dec 2004 14:57:12 -0000	1.2
+++ subopt-helper.h	19 Jan 2005 17:10:20 -0000	1.3
@@ -12,6 +12,7 @@
 #define OPT_ARG_BOOL 0
 #define OPT_ARG_INT  1
 #define OPT_ARG_STR  2
+#define OPT_ARG_MSTRZ 3 ///< A malloced, zero terminated string, use free()!
 
 typedef int (*opt_test_f)(void *);
 
@@ -34,7 +35,7 @@
 /*------------------ arg specific types and declaration -------------------*/
 typedef struct strarg_s
 {
-  unsigned char len; ///< length of the string determined by the parser
+  int len; ///< length of the string determined by the parser
   char const * str;  ///< pointer to position inside the parse string
 } strarg_t;
 




More information about the MPlayer-cvslog mailing list