-#define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
-/* go accross " " and { } */
-static char *_get_chain_end( char *str )
-{
- char *p = str;
-
- SKIPSPACE( p );
-
- for( ;; )
- {
- if( *p == '{' || *p == '"' || *p == '\'')
- {
- char c;
-
- if( *p == '{' )
- {
- c = '}';
- }
- else
- {
- c = *p;
- }
- p++;
-
- for( ;; )
- {
- if( *p == '\0' )
- {
- return p;
- }
-
- if( *p == c )
- {
- p++;
- return p;
- }
- else if( *p == '{' && c == '}' )
- {
- p = _get_chain_end( p );
- }
- else
- {
- p++;
- }
- }
- }
- else if( *p == '\0' || *p == ',' || *p == '}' || *p == ' ' || *p == '\t' )
- {
- return p;
- }
- else
- {
- p++;
- }
- }
-}
-
-char * sout_cfg_parser( char **ppsz_name, sout_cfg_t **pp_cfg, char *psz_chain )
-{
- sout_cfg_t *p_cfg = NULL;
- char *p = psz_chain;
-
- *ppsz_name = NULL;
- *pp_cfg = NULL;
-
- if( p == NULL )
- {
- return NULL;
- }
-
- SKIPSPACE( p );
-
- while( *p && *p != '{' && *p != ':' && *p != ' ' && *p != '\t' )
- {
- p++;
- }
-
- if( p == psz_chain )
- {
- return NULL;
- }
-
- *ppsz_name = _strndup( psz_chain, p - psz_chain );
-
- SKIPSPACE( p );
-
- if( *p == '{' )
- {
- char *psz_name;
-
- p++;
-
- for( ;; )
- {
- sout_cfg_t cfg;
-
- SKIPSPACE( p );
-
- psz_name = p;
-
- while( *p && *p != '=' && *p != ',' && *p != '}' && *p != ' ' && *p != '\t' )
- {
- p++;
- }
-
- /* fprintf( stderr, "name=%s - rest=%s\n", psz_name, p ); */
- if( p == psz_name )
- {
- fprintf( stderr, "invalid options (empty)" );
- break;
- }
-
- cfg.psz_name = _strndup( psz_name, p - psz_name );
-
- SKIPSPACE( p );
-
- if( *p == '=' )
- {
- char *end;
-
- p++;
-
- end = _get_chain_end( p );
- if( end <= p )
- {
- cfg.psz_value = NULL;
- }
- else
- {
- if( *p == '\'' || *p =='"' || *p == '{' )
- {
- p++;
- end--;
- }
- if( end <= p )
- {
- cfg.psz_value = NULL;
- }
- else
- {
- cfg.psz_value = _strndup( p, end - p );
- }
- }
-
- p = end;
- SKIPSPACE( p );
- }
- else
- {
- cfg.psz_value = NULL;
- }
-
- cfg.p_next = NULL;
- if( p_cfg )
- {
- p_cfg->p_next = malloc( sizeof( sout_cfg_t ) );
- memcpy( p_cfg->p_next, &cfg, sizeof( sout_cfg_t ) );
-
- p_cfg = p_cfg->p_next;
- }
- else
- {
- p_cfg = malloc( sizeof( sout_cfg_t ) );
- memcpy( p_cfg, &cfg, sizeof( sout_cfg_t ) );
-
- *pp_cfg = p_cfg;
- }
-
- if( *p == ',' )
- {
- p++;
- }
-
- if( *p == '}' )
- {
- p++;
-
- break;
- }
- }
- }
-
- if( *p == ':' )
- {
- return( strdup( p + 1 ) );
- }
-
- return( NULL );
-}
-
-static void sout_cfg_free( sout_cfg_t *p_cfg )
-{
- while( p_cfg != NULL )
- {
- sout_cfg_t *p_next;
-
- p_next = p_cfg->p_next;
-
- FREE( p_cfg->psz_name );
- FREE( p_cfg->psz_value );
- free( p_cfg );
-
- p_cfg = p_next;
- }
-}
-