[vlc-devel] Re: CVS Commit (sam)
Samuel Hocevar
sam at zoy.org
Mon Oct 28 22:06:30 CET 2002
On Mon, Oct 28, 2002, cvs at videolan.org wrote:
> * ./include/variables.h, ./src/misc/variables.c: list variables.
Here is a quick usage guide:
vlc_value_t val;
var_Create( p_this, "myvar", VLC_VAR_STRING | VLC_VAR_ISLIST );
val.psz_string = "foo";
var_Change( p_this, "myvar", VLC_VAR_ADDCHOICE, &val );
val.psz_string = "bar";
var_Change( p_this, "myvar", VLC_VAR_ADDCHOICE, &val );
val.psz_string = "baz";
var_Change( p_this, "myvar", VLC_VAR_ADDCHOICE, &val );
"myvar" contains "foo" because it was the first entered value. To remove
a value, do this:
val.psz_string = "baz";
var_Change( p_this, "myvar", VLC_VAR_DELCHOICE, &val );
If you want to set a default value, use this:
val.psz_string = "bar";
var_Change( p_this, "myvar", VLC_VAR_SETDEFAULT, &val );
Now consider this:
val.psz_string = "foo";
var_Set( p_this, "myvar", val );
This is valid, and "myvar" contains "foo". If you do this:
val.psz_string = "INVALID";
var_Set( p_this, "myvar", val );
"myvar" now contains "bar" because it is the default value.
To retrieve the possible values, use VLC_VAR_GETLIST, which puts an
array of values in val.p_address, the first of them containing the
number of variables in its i_int field. The next values are of the same
type as val. To free the list, don't forget to use VLC_VAR_FREELIST:
vlc_value_t val;
int i, i_vals;
vlc_value_t *p_vals;
var_Change( p_this, "myvar", VLC_VAR_GETLIST, &val );
i_vals = ((vlc_value_t*)val.p_address)[0].i_int;
p_vals = &((vlc_value_t*)val.p_address)[1]; /* Starts at index 1 */
for( i = 0 ; i < i_vals ; i++ )
{
printf( "value %i: %s\n", i, p_vals[i].psz_string );
}
var_Change( p_this, "myvar", VLC_VAR_FREELIST, &val );
Strings are alphabetically sorted, numberals are numerically sorted.
HTH,
--
Sam.
--
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://www.videolan.org/lists.html
If you are in trouble, please contact <postmaster at videolan.org>
More information about the vlc-devel
mailing list