From 64ea683969472b60ebc2b4e15e552f7bf23d017a Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 16 Dec 2007 17:36:01 +0000 Subject: [PATCH] short and list support for vlc_config_set --- include/vlc_configuration.h | 35 +++++++++++----- include/vlc_plugin.h | 28 +++++++++++++ src/config/core.c | 40 ------------------- src/modules/entry.c | 79 +++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 50 deletions(-) create mode 100644 include/vlc_plugin.h diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h index 53160a6fbc..60177c575e 100644 --- a/include/vlc_configuration.h +++ b/include/vlc_configuration.h @@ -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 *, 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, \ diff --git a/include/vlc_plugin.h b/include/vlc_plugin.h new file mode 100644 index 0000000000..75749fd595 --- /dev/null +++ b/include/vlc_plugin.h @@ -0,0 +1,28 @@ +/***************************************************************************** + * 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 +#include + +#endif diff --git a/src/config/core.c b/src/config/core.c index 5f8ec50acb..a054cd0b61 100644 --- a/src/config/core.c +++ b/src/config/core.c @@ -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 ) { diff --git a/src/modules/entry.c b/src/modules/entry.c index 3891646c60..62bb2ecb51 100644 --- a/src/modules/entry.c +++ b/src/modules/entry.c @@ -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); -- 2.39.2