]> git.sesse.net Git - vlc/commitdiff
short and list support for vlc_config_set
authorRémi Denis-Courmont <rem@videolan.org>
Sun, 16 Dec 2007 17:36:01 +0000 (17:36 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sun, 16 Dec 2007 17:36:01 +0000 (17:36 +0000)
include/vlc_configuration.h
include/vlc_plugin.h [new file with mode: 0644]
src/config/core.c
src/modules/entry.c

index 53160a6fbc7dc0842deda9f50ab0d2b284a53c39..60177c575e17bd57ba9eabf74e5e3865b0968c0e 100644 (file)
@@ -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, \
diff --git a/include/vlc_plugin.h b/include/vlc_plugin.h
new file mode 100644 (file)
index 0000000..75749fd
--- /dev/null
@@ -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 <vlc_modules.h>
+#include <vlc_configuration.h>
+
+#endif
index 5f8ec50acbe8e5fdf81016f714d93e71beb69a5e..a054cd0b612cdef29773c285d8f5ce0b1eb5fd73 100644 (file)
@@ -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 )
         {
index 3891646c607ccda9d0eb31106e71b38487e34e41..62bb2ecb51ae43431d1b7ecd5806998d0061cc31 100644 (file)
@@ -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);