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,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 );
......
......@@ -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