[vlc-devel] [PATCH] variables: handle values when parsing bool

Thomas Guillem thomas at gllm.fr
Wed Oct 3 11:53:06 CEST 2018



On Wed, Oct 3, 2018, at 11:45, Thomas Guillem wrote:
> Currently, bool values can be set only without values, that is <varname> for
> true or no-<varname> for false.
> 
> This causes an issue with the var_LocationParse function, that can't support
> the "no-<varname>" bool syntax. This means that you can't set bool to false
> when using this function.
> 
> To workaround this issue, this commit add support for value parsing, that is:
>  - varname=0 for false, != 0 for true, or
>  - varname=true for true, anything different for false.
> ---
>  src/misc/variables.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/src/misc/variables.c b/src/misc/variables.c
> index 8efac4449c..8b84f553da 100644
> --- a/src/misc/variables.c
> +++ b/src/misc/variables.c
> @@ -968,7 +968,23 @@ void var_OptionParse( vlc_object_t *p_obj, const 
> char *psz_option,
>      switch( i_type )
>      {
>      case VLC_VAR_BOOL:
> -        val.b_bool = !b_isno;
> +        if( psz_value )
> +        {
> +            char *endptr;
> +            long long int value = strtoll( psz_value, &endptr, 0 );
> +            if( endptr == psz_value )
> +            {
> +                /* Not an integer */
> +                if( strcasecmp( psz_value, "true" ) == 0 )
Maybe check also for "yes" here.
> +                    val.b_bool = true;
> +                else
> +                    val.b_bool = false;
> +            }
> +            else
> +                val.b_bool = value != 0;
> +        }
> +        else
> +            val.b_bool = !b_isno;
>          break;
>  
>      case VLC_VAR_INTEGER:
> -- 
> 2.19.0
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list