[vlc-commits] variables: handle values when parsing bool

Thomas Guillem git at videolan.org
Thu Oct 4 08:54:35 CEST 2018


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Oct  3 14:19:51 2018 +0200| [3c52e9210feac3b49ace255ff14edae81ddd86d9] | committer: Thomas Guillem

variables: handle values when parsing bool

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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3c52e9210feac3b49ace255ff14edae81ddd86d9
---

 src/misc/variables.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/misc/variables.c b/src/misc/variables.c
index 8efac4449c..0fff2c82d6 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -968,7 +968,18 @@ 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 */
+                val.b_bool = strcasecmp( psz_value, "true" ) == 0
+                          || strcasecmp( psz_value, "yes" ) == 0;
+            else
+                val.b_bool = value != 0;
+        }
+        else
+            val.b_bool = !b_isno;
         break;
 
     case VLC_VAR_INTEGER:



More information about the vlc-commits mailing list