Commit f6533ac0 authored by Rafaël Carré's avatar Rafaël Carré

Split options parsing from config_ChainCreate

parent 22c24d5a
......@@ -255,6 +255,18 @@ struct config_chain_t
VLC_API void config_ChainParse( vlc_object_t *, const char *psz_prefix, const char *const *ppsz_options, config_chain_t * );
#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)
......
......@@ -175,36 +175,21 @@ 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 )
/* 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;
size_t len;
*ppsz_name = NULL;
*pp_cfg = NULL;
if( !psz_chain )
return NULL;
SKIPSPACE( psz_chain );
/* Look for parameter (a {...} or :...) or end of name (space or nul) */
len = strcspn( psz_chain, "{: \t" );
*ppsz_name = strndup( psz_chain, len );
psz_chain += len;
/* Parse the parameters */
SKIPSPACE( psz_chain );
if( *psz_chain == '{' )
{
/* Parse all name=value[,] elements */
bool first = true;
do
{
psz_chain++; /* skip previous delimiter */
SKIPSPACE( psz_chain );
if (!first)
psz_opts++; /* skip previous delimiter */
SKIPSPACE( psz_opts );
first = false;
/* Look for the end of the name (,={}_space_) */
len = strcspn( psz_chain, "=,{} \t" );
size_t len = strcspn( psz_opts, "=,{} \t" );
if( len == 0 )
continue; /* ignore empty parameter */
......@@ -212,8 +197,8 @@ char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg,
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_name = strndup( psz_opts, len );
psz_opts += len;
p_cfg->psz_value = NULL;
p_cfg->p_next = NULL;
......@@ -221,18 +206,42 @@ char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg,
pp_next = &p_cfg->p_next;
/* Extract the option value */
SKIPSPACE( psz_chain );
if( strchr( "={", *psz_chain ) )
SKIPSPACE( psz_opts );
if( strchr( "={", *psz_opts ) )
{
p_cfg->psz_value = ChainGetValue( &psz_chain );
SKIPSPACE( psz_chain );
p_cfg->psz_value = ChainGetValue( &psz_opts );
SKIPSPACE( psz_opts );
}
}
while( !memchr( "}", *psz_chain, 2 ) );
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 )
{
size_t len;
*ppsz_name = NULL;
*pp_cfg = NULL;
if( *psz_chain ) psz_chain++; /* skip '}' */;
if( !psz_chain )
return NULL;
SKIPSPACE( psz_chain );
}
/* Look for parameter (a {...} or :...) or end of name (space or nul) */
len = strcspn( psz_chain, "{: \t" );
*ppsz_name = strndup( psz_chain, len );
psz_chain += len;
/* Parse the parameters */
SKIPSPACE( psz_chain );
if( *psz_chain == '{' )
psz_chain = config_ChainParseOptions( pp_cfg, psz_chain );
if( *psz_chain == ':' )
return strdup( psz_chain + 1 );
......
......@@ -54,6 +54,7 @@ config_ChainCreate
config_ChainDestroy
config_ChainDuplicate
config_ChainParse
config_ChainParseOptions
config_ExistIntf
config_FindConfig
config_GetConfDir
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment