Commit 64ea6839 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

short and list support for vlc_config_set

parent f9a54b04
......@@ -165,14 +165,14 @@ struct module_config_t
void *p_callback_data;
/* Values list */
const char **ppsz_list; /* List of possible values for the option */
char ** ppsz_list; /* List of possible values for the option */
int *pi_list; /* Idem for integers */
const char **ppsz_list_text; /* Friendly names for list values */
char **ppsz_list_text; /* Friendly names for list values */
int i_list; /* Options list size */
/* Actions list */
vlc_callback_t *ppf_action; /* List of possible actions for a config */
const char **ppsz_action_text; /* Friendly names for actions */
char **ppsz_action_text; /* Friendly names for actions */
int i_action; /* actions list size */
/* Misc */
......@@ -268,6 +268,13 @@ enum vlc_config_properties
VLC_CONFIG_CAPABILITY,
/* capability for a module or list thereof (args=const char*) */
VLC_CONFIG_SHORTCUT,
/* one-character (short) command line option name (args=char) */
VLC_CONFIG_LIST,
/* possible values list
* (args=size_t, const <type> *, const char *const *) */
};
......@@ -430,17 +437,25 @@ VLC_EXPORT( int, vlc_config_set, (module_config_t *, int, ...) );
/* Modifier macros for the config options (used for fine tuning) */
#define change_short( ch ) \
p_config[i_config].i_short = ch;
vlc_config_set (p_config + i_config, VLC_CONFIG_SHORTCUT, (int)(ch))
#define change_string_list( list, list_text, list_update_func ) \
p_config[i_config].i_list = sizeof(list)/sizeof(char *); \
p_config[i_config].ppsz_list = list; \
p_config[i_config].ppsz_list_text = list_text;
vlc_config_set (p_config + i_config, VLC_CONFIG_LIST, \
(size_t)(sizeof (list) / sizeof (char *)), \
(const char *const *)(list), \
(const char *const *)(list_text))
#define change_integer_list( list, list_text, list_update_func ) \
p_config[i_config].i_list = sizeof(list)/sizeof(int); \
p_config[i_config].pi_list = (int *)list; \
p_config[i_config].ppsz_list_text = list_text;
vlc_config_set (p_config + i_config, VLC_CONFIG_LIST, \
(size_t)(sizeof (list) / sizeof (int)), \
(const int *)(list), \
(const char *const *)(list_text))
#define change_float_list( list, list_text, list_update_func ) \
vlc_config_set (p_config + i_config, VLC_CONFIG_LIST, \
(size_t)(sizeof (list) / sizeof (float)), \
(const float *)(list), \
(const char *const *)(list_text))
#define change_integer_range( minv, maxv ) \
vlc_config_set (p_config + i_config, VLC_CONFIG_RANGE, \
......
/*****************************************************************************
* plugin.h: LibVLC plugin macros
*****************************************************************************
* Copyright © 2007 Rémi Denis-Courmont
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef _VLC_PLUGIN_H
# define _VLC_PLUGIN_H 1
#include <vlc_modules.h>
#include <vlc_configuration.h>
#endif
......@@ -522,46 +522,6 @@ int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
p_module->p_config[i] = p_orig[i];
p_module->p_config[i].p_lock = &p_module->object_lock;
/* duplicate the string list */
if( p_orig[i].i_list )
{
if( p_orig[i].ppsz_list )
{
p_module->p_config[i].ppsz_list =
malloc( (p_orig[i].i_list + 1) * sizeof(char *) );
if( p_module->p_config[i].ppsz_list )
{
for( j = 0; j < p_orig[i].i_list; j++ )
p_module->p_config[i].ppsz_list[j] =
strdupnull (p_orig[i].ppsz_list[j]);
p_module->p_config[i].ppsz_list[j] = NULL;
}
}
if( p_orig[i].ppsz_list_text )
{
p_module->p_config[i].ppsz_list_text =
calloc( (p_orig[i].i_list + 1), sizeof(char *) );
if( p_module->p_config[i].ppsz_list_text )
{
for( j = 0; j < p_orig[i].i_list; j++ )
p_module->p_config[i].ppsz_list_text[j] =
strdupnull (_(p_orig[i].ppsz_list_text[j]));
p_module->p_config[i].ppsz_list_text[j] = NULL;
}
}
if( p_orig[i].pi_list )
{
p_module->p_config[i].pi_list =
malloc( (p_orig[i].i_list + 1) * sizeof(int) );
if( p_module->p_config[i].pi_list )
{
for( j = 0; j < p_orig[i].i_list; j++ )
p_module->p_config[i].pi_list[j] =
p_orig[i].pi_list[j];
}
}
}
/* duplicate the actions list */
if( p_orig[i].i_action )
{
......
......@@ -158,6 +158,9 @@ module_config_t *vlc_config_create (module_t *module, int type)
module->confsize++;
memset (tab + confsize, 0, sizeof (tab[confsize]));
tab[confsize].i_type = type;
tab[confsize].p_lock = &module->object_lock;
return tab + confsize;
}
......@@ -276,6 +279,82 @@ int vlc_config_set (module_config_t *restrict item, int id, ...)
ret = 0;
break;
}
case VLC_CONFIG_SHORTCUT:
item->i_short = va_arg (ap, int);
ret = 0;
break;
case VLC_CONFIG_LIST:
{
size_t len = va_arg (ap, size_t);
char **dtext = malloc (sizeof (char *) * (len + 1));
if (dtext == NULL)
break;
/* Copy values */
if (IsConfigIntegerType (item->i_type))
{
const int *src = va_arg (ap, const int *);
int *dst = malloc (sizeof (int) * (len + 1));
if (dst != NULL)
{
memcpy (dst, src, sizeof (int) * len);
dst[len] = 0;
}
item->pi_list = dst;
}
else
#if 0
if (IsConfigFloatType (item->i_type))
{
const float *src = va_arg (ap, const float *);
float *dst = malloc (sizeof (float) * (len + 1));
if (dst != NULL)
{
memcpy (dst, src, sizeof (float) * len);
dst[len] = 0.;
}
item->pf_list = dst;
}
else
#endif
if (IsConfigStringType (item->i_type))
{
const char *const *src = va_arg (ap, const char *const *);
char **dst = malloc (sizeof (char *) * (len + 1));
if (dst != NULL)
{
for (size_t i = 0; i < len; i++)
dst[i] = src[i] ? strdup (src[i]) : NULL;
dst[len] = NULL;
}
item->ppsz_list = dst;
}
else
break;
/* Copy textual descriptions */
const char *const *text = va_arg (ap, const char *const *);
if (text != NULL)
{
for (size_t i = 0; i < len; i++)
dtext[i] = text[i] ? strdup (gettext (text[i])) : NULL;
dtext[len] = NULL;
item->ppsz_list_text = dtext;
}
else
item->ppsz_list_text = NULL;
item->i_list = len;
ret = 0;
break;
}
}
va_end (ap);
......
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