[vlc-devel] [PATCH 1/2] Split key=val, parsing from config_ChainCreate
Rafaël Carré
funman at videolan.org
Fri Mar 2 18:54:28 CET 2012
---
include/vlc_configuration.h | 11 ++++++
src/config/chain.c | 83 ++++++++++++++++++++++++------------------
src/libvlccore.sym | 1 +
3 files changed, 59 insertions(+), 36 deletions(-)
diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h
index e01103b..60358ab 100644
--- a/include/vlc_configuration.h
+++ b/include/vlc_configuration.h
@@ -256,6 +256,17 @@ 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_string)
+ * - set all options for this module in a chained list (*pp_cfg)
+ *
+ * The string format is
+ * option=*,option=*
+ *
+ * The options values are unescaped using config_StringUnescape.
+ */
+VLC_API char *config_ChainParseKeys( config_chain_t **pp_cfg, const char *psz_string ) VLC_USED VLC_MALLOC;
+
+/**
* 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..7952de3 100644
--- a/src/config/chain.c
+++ b/src/config/chain.c
@@ -175,12 +175,50 @@ static char *ChainGetValue( const char **ppsz_string )
return psz_value;
}
-char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg,
- const char *psz_chain )
+char *config_ChainParseKeys( config_chain_t **pp_cfg,
+ const char *psz_chain )
{
config_chain_t **pp_next = pp_cfg;
- size_t len;
+ /* Parse all name=value[,] elements */
+ do
+ {
+ SKIPSPACE( psz_chain );
+
+ /* Look for the end of the name (,={}_space_) */
+ size_t len = strcspn( psz_chain, "=,{} \t" );
+ if( len == 0 )
+ goto next; /* 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 );
+ }
+ next:
+ psz_chain++; /* skip previous delimiter */
+ }
+ while( !memchr( "}", *psz_chain, 2 ) );
+
+ return psz_chain;
+}
+char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg,
+ const char *psz_chain )
+{
*ppsz_name = NULL;
*pp_cfg = NULL;
@@ -189,7 +227,7 @@ char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg,
SKIPSPACE( psz_chain );
/* Look for parameter (a {...} or :...) or end of name (space or nul) */
- len = strcspn( psz_chain, "{: \t" );
+ size_t len = strcspn( psz_chain, "{: \t" );
*ppsz_name = strndup( psz_chain, len );
psz_chain += len;
@@ -197,41 +235,14 @@ char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg,
SKIPSPACE( psz_chain );
if( *psz_chain == '{' )
{
- /* Parse all name=value[,] elements */
- do
- {
- psz_chain++; /* skip previous delimiter */
- SKIPSPACE( psz_chain );
+ psz_chain++; /* skip '{' */
+ psz_chain = config_ChainParseKeys( pp_cfg, 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 */
+ if( *psz_chain )
+ {
+ psz_chain++; /* skip '}' */;
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 );
}
if( *psz_chain == ':' )
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 779d643..3b5295f 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -54,6 +54,7 @@ config_ChainCreate
config_ChainDestroy
config_ChainDuplicate
config_ChainParse
+config_ChainParseKeys
config_ExistIntf
config_FindConfig
config_GetConfDir
--
1.7.9
More information about the vlc-devel
mailing list