[vlc-commits] Split options parsing from config_ChainCreate

Rafaël Carré git at videolan.org
Wed Mar 14 11:44:00 CET 2012


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Wed Mar 14 06:42:19 2012 -0400| [f6533ac058690b4c9b1405f5ec169829db5aad55] | committer: Rafaël Carré

Split options parsing from config_ChainCreate

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f6533ac058690b4c9b1405f5ec169829db5aad55
---

 include/vlc_configuration.h |   12 ++++++
 src/config/chain.c          |   85 ++++++++++++++++++++++++-------------------
 src/libvlccore.sym          |    1 +
 3 files changed, 60 insertions(+), 38 deletions(-)

diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h
index e01103b..e9ca96b 100644
--- a/include/vlc_configuration.h
+++ b/include/vlc_configuration.h
@@ -256,6 +256,18 @@ VLC_API void config_ChainParse( vlc_object_t *, const char *psz_prefix, const ch
 #define config_ChainParse( a, b, c, d ) config_ChainParse( VLC_OBJECT(a), b, c, d )
 
 /**
+ * This function will parse a configuration string (psz_opts) and
+ * - set all options for this module in a chained list (*pp_cfg)
+ * - returns a pointer on the next module if any.
+ *
+ * The string format is
+ *   module{option=*,option=*}
+ *
+ * The options values are unescaped using config_StringUnescape.
+ */
+VLC_API const char *config_ChainParseOptions( config_chain_t **pp_cfg, const char *ppsz_opts );
+
+/**
  * This function will parse a configuration string (psz_string) and
  * - set the module name (*ppsz_name)
  * - set all options for this module in a chained list (*pp_cfg)
diff --git a/src/config/chain.c b/src/config/chain.c
index c824657..7d0b71d 100644
--- a/src/config/chain.c
+++ b/src/config/chain.c
@@ -175,10 +175,55 @@ static char *ChainGetValue( const char **ppsz_string )
     return psz_value;
 }
 
+/* Parse all name=value[,] elements */
+const char *config_ChainParseOptions( config_chain_t **pp_cfg, const char *psz_opts )
+{
+    config_chain_t **pp_next = pp_cfg;
+    bool first = true;
+    do
+    {
+        if (!first)
+            psz_opts++; /* skip previous delimiter */
+        SKIPSPACE( psz_opts );
+
+        first = false;
+
+        /* Look for the end of the name (,={}_space_) */
+        size_t len = strcspn( psz_opts, "=,{} \t" );
+        if( len == 0 )
+            continue; /* ignore empty parameter */
+
+        /* Append the new parameter */
+        config_chain_t *p_cfg = malloc( sizeof(*p_cfg) );
+        if( !p_cfg )
+            break;
+        p_cfg->psz_name = strndup( psz_opts, len );
+        psz_opts += len;
+        p_cfg->psz_value = NULL;
+        p_cfg->p_next = NULL;
+
+        *pp_next = p_cfg;
+        pp_next = &p_cfg->p_next;
+
+        /* Extract the option value */
+        SKIPSPACE( psz_opts );
+        if( strchr( "={", *psz_opts ) )
+        {
+            p_cfg->psz_value = ChainGetValue( &psz_opts );
+            SKIPSPACE( psz_opts );
+        }
+    }
+    while( !memchr( "}", *psz_opts, 2 ) );
+
+    if( *psz_opts ) psz_opts++; /* skip '}' */;
+    SKIPSPACE( psz_opts );
+
+    return psz_opts;
+}
+
 char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg,
                           const char *psz_chain )
 {
-    config_chain_t **pp_next = pp_cfg;
     size_t len;
 
     *ppsz_name = NULL;
@@ -196,43 +241,7 @@ char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg,
     /* Parse the parameters */
     SKIPSPACE( psz_chain );
     if( *psz_chain == '{' )
-    {
-        /* Parse all name=value[,] elements */
-        do
-        {
-            psz_chain++; /* skip previous delimiter */
-            SKIPSPACE( psz_chain );
-
-            /* Look for the end of the name (,={}_space_) */
-            len = strcspn( psz_chain, "=,{} \t" );
-            if( len == 0 )
-                continue; /* ignore empty parameter */
-
-            /* Append the new parameter */
-            config_chain_t *p_cfg = malloc( sizeof(*p_cfg) );
-            if( !p_cfg )
-                break;
-            p_cfg->psz_name = strndup( psz_chain, len );
-            psz_chain += len;
-            p_cfg->psz_value = NULL;
-            p_cfg->p_next = NULL;
-
-            *pp_next = p_cfg;
-            pp_next = &p_cfg->p_next;
-
-            /* Extract the option value */
-            SKIPSPACE( psz_chain );
-            if( strchr( "={", *psz_chain ) )
-            {
-                p_cfg->psz_value = ChainGetValue( &psz_chain );
-                SKIPSPACE( psz_chain );
-            }
-        }
-        while( !memchr( "}", *psz_chain, 2 ) );
-
-        if( *psz_chain ) psz_chain++; /* skip '}' */;
-        SKIPSPACE( psz_chain );
-    }
+        psz_chain = config_ChainParseOptions( pp_cfg, psz_chain );
 
     if( *psz_chain == ':' )
         return strdup( psz_chain + 1 );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 779d643..5092d30 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -54,6 +54,7 @@ config_ChainCreate
 config_ChainDestroy
 config_ChainDuplicate
 config_ChainParse
+config_ChainParseOptions
 config_ExistIntf
 config_FindConfig
 config_GetConfDir



More information about the vlc-commits mailing list