[MPlayer-dev-eng] [PATCH] allow subopt parser to receive arbitrary strings

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat May 14 15:49:27 CEST 2005


Hi,
the attached patch add some kind of quoting support for the support
parser, so that e.g. strings containing : are now possible.
I have to admit the way is a bit weird, but two reasons for doing it
like that:
1) simple to use for Guis
2) it can parse the string without having to modify it (so no need for
malloc etc)

It allows for the following string format:
%length%string

e.g. (in reference to a post to mencoder-users):
-ao pcm:file=%11%C:\test.wav


-ao pcm:file=test.wav
is equivalent to
-ao pcm:file=%8%test.wav

This also means that e.g.
-ao pcm:file=%1abd.wav
will stop with an error.

I know this is a non-standard way to do it, but it seems best-suited to
me.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: subopt-helper.c
===================================================================
RCS file: /cvsroot/mplayer/main/subopt-helper.c,v
retrieving revision 1.5
diff -u -r1.5 subopt-helper.c
--- subopt-helper.c	19 Feb 2005 20:14:00 -0000	1.5
+++ subopt-helper.c	14 May 2005 13:34:02 -0000
@@ -247,10 +247,21 @@
   return endp;
 }
 
-static char const * parse_str( char const * const str, strarg_t * const valp )
+#define QUOTE_CHAR '%'
+static char const * parse_str( char const * str, strarg_t * const valp )
 {
   char const * match = strchr( str, ':' );
 
+  if (str[0] == QUOTE_CHAR) {
+    int len = 0;
+    str = &str[1];
+    len = (int)strtol(str, (char **)&str, 0);
+    if (!str || str[0] != QUOTE_CHAR || (len > strlen(str) - 1))
+      return NULL;
+    str = &str[1];
+    match = &str[len];
+  }
+  else
   if ( !match )
     match = &str[strlen(str)];
 


More information about the MPlayer-dev-eng mailing list