]> git.sesse.net Git - vlc/commitdiff
* ALL: added a new vlc_list_t common type. vlc_list_find() and vlc_list_release(...
authorGildas Bazin <gbazin@videolan.org>
Fri, 13 Dec 2002 01:56:30 +0000 (01:56 +0000)
committerGildas Bazin <gbazin@videolan.org>
Fri, 13 Dec 2002 01:56:30 +0000 (01:56 +0000)
to use this new type.

14 files changed:
include/variables.h
include/vlc/vlc.h
include/vlc_common.h
include/vlc_objects.h
modules/gui/familiar/familiar.c
modules/gui/gtk/display.c
modules/gui/gtk/preferences.c
modules/gui/kde/preferences.cpp
modules/gui/macosx/prefs.m
modules/gui/win32/preferences.cpp
src/libvlc.c
src/misc/configuration.c
src/misc/modules.c
src/misc/objects.c

index f31793cf98eabe4ad2225630383a49609fdca319..275de0dec1e11dc218994520bbb9a5ed8722adb8 100644 (file)
@@ -2,7 +2,7 @@
  * variables.h: variables handling
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: variables.h,v 1.9 2002/12/07 15:25:26 gbazin Exp $
+ * $Id: variables.h,v 1.10 2002/12/13 01:56:29 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -87,7 +87,9 @@ struct variable_t
 #define VLC_VAR_HASMAX    0x0400
 #define VLC_VAR_HASSTEP   0x0800
 
-#define VLC_VAR_ISCOMMAND 0x1000
+#define VLC_VAR_ISLIST    0x1000
+#define VLC_VAR_ISCOMMAND 0x2000
+#define VLC_VAR_ISCONFIG  0x2000
 
 /*****************************************************************************
  * Variable actions
index 7949f0d9cccf06963b196fab587b03f9ca6173b2..adff93cac62c0e5d1b12649c3e4ed73786caeef4 100644 (file)
@@ -2,7 +2,7 @@
  * vlc.h: global header for vlc
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: vlc.h,v 1.18 2002/12/03 16:29:04 gitan Exp $
+ * $Id: vlc.h,v 1.19 2002/12/13 01:56:29 gbazin Exp $
  *
  * 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
@@ -30,20 +30,30 @@ extern "C" {
  * Our custom types
  *****************************************************************************/
 typedef int vlc_bool_t;
+typedef struct vlc_list_t vlc_list_t;
+typedef struct vlc_object_t vlc_object_t;
 
 typedef union
 {
-    int         i_int;
-    vlc_bool_t  b_bool;
-    float       f_float;
-    char *      psz_string;
-    void *      p_address;
+    int             i_int;
+    vlc_bool_t      b_bool;
+    float           f_float;
+    char *          psz_string;
+    void *          p_address;
+    vlc_object_t *  p_object;
 
     /* Make sure the structure is at least 64bits */
     struct { char a, b, c, d, e, f, g, h; } padding;
 
 } vlc_value_t;
 
+struct vlc_list_t
+{
+    int             i_count;
+    vlc_value_t *   p_values;
+
+};
+
 /*****************************************************************************
  * Error values
  *****************************************************************************/
index a20b8b5f28d889ccaf87041b086c0853bb04ebad..cb5017a1b753104897568490cdfc989a60fc9a36 100644 (file)
@@ -3,7 +3,7 @@
  * Collection of useful common types and macros definitions
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: vlc_common.h,v 1.42 2002/11/28 23:24:14 massiot Exp $
+ * $Id: vlc_common.h,v 1.43 2002/12/13 01:56:29 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@via.ecp.fr>
  *          Vincent Seguin <seguin@via.ecp.fr>
@@ -178,8 +178,6 @@ typedef uint32_t vlc_fourcc_t;
 /* Internal types */
 typedef struct libvlc_t libvlc_t;
 typedef struct vlc_t vlc_t;
-typedef struct vlc_list_t vlc_list_t;
-typedef struct vlc_object_t vlc_object_t;
 typedef struct variable_t variable_t;
 
 /* Messages */
index 23b4bbb09001432c52e7972cff59c0eae5952030..f500bb04626081baa5b837996ee21cb5e973acd1 100644 (file)
@@ -2,7 +2,7 @@
  * vlc_objects.h: vlc_object_t definition.
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: vlc_objects.h,v 1.13 2002/10/14 16:46:55 sam Exp $
+ * $Id: vlc_objects.h,v 1.14 2002/12/13 01:56:29 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -50,19 +50,6 @@ struct vlc_object_t
     VLC_COMMON_MEMBERS
 };
 
-/*****************************************************************************
- * The vlc_list_t object list type
- *****************************************************************************/
-struct vlc_list_t
-{
-    int             i_count;
-    vlc_object_t ** pp_objects;
-
-    /* Private */
-    int             _i_extra;
-    vlc_object_t *  _p_first;
-};  
-
 /*****************************************************************************
  * Prototypes
  *****************************************************************************/
@@ -74,7 +61,7 @@ VLC_EXPORT( void *, __vlc_object_get, ( vlc_object_t *, int ) );
 VLC_EXPORT( void *, __vlc_object_find, ( vlc_object_t *, int, int ) );
 VLC_EXPORT( void, __vlc_object_yield, ( vlc_object_t * ) );
 VLC_EXPORT( void, __vlc_object_release, ( vlc_object_t * ) );
-VLC_EXPORT( vlc_list_t *, __vlc_list_find, ( vlc_object_t *, int, int ) );
+VLC_EXPORT( vlc_list_t, __vlc_list_find, ( vlc_object_t *, int, int ) );
 VLC_EXPORT( void, vlc_list_release, ( vlc_list_t * ) );
 
 #define vlc_object_create(a,b) \
index 169afeeedd32bd4e3faa6353a7877d0394166e75..11eb591415a6c712d4fa9841a56a1e47566eee6f 100644 (file)
@@ -2,7 +2,7 @@
  * familiar.c : familiar plugin for vlc
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: familiar.c,v 1.12 2002/12/12 12:24:23 sam Exp $
+ * $Id: familiar.c,v 1.13 2002/12/13 01:56:29 gbazin Exp $
  *
  * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
  *
@@ -198,36 +198,37 @@ static void Run( intf_thread_t *p_intf )
 void GtkAutoPlayFile( vlc_object_t *p_this )
 {
     GtkWidget *cbautoplay;
-    intf_thread_t **pp_intf;
-    vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
+    intf_thread_t *p_intf;
+    int i_index;
+    vlc_list_t list = vlc_list_find( p_this, VLC_OBJECT_INTF,
                                                 FIND_ANYWHERE );
 
-    for( pp_intf = (intf_thread_t **)p_list->pp_objects ;
-         *pp_intf ;
-         pp_intf++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
-        if( strcmp( MODULE_STRING, (*pp_intf)->p_module->psz_object_name ) )
+        p_intf = (intf_thread_t *)list.p_values[i_index].p_object ;
+
+        if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
         {
             continue;
         }
 
         cbautoplay = GTK_WIDGET( gtk_object_get_data(
-                            GTK_OBJECT( (*pp_intf)->p_sys->p_window ),
+                            GTK_OBJECT( p_intf->p_sys->p_window ),
                             "cbautoplay" ) );
 
         if( !config_GetInt( p_this, "familiar-autoplayfile" ) )
         {
-            (*pp_intf)->p_sys->b_autoplayfile = VLC_FALSE;
+            p_intf->p_sys->b_autoplayfile = VLC_FALSE;
         }
         else
         {
-            (*pp_intf)->p_sys->b_autoplayfile = VLC_TRUE;
+            p_intf->p_sys->b_autoplayfile = VLC_TRUE;
         }
 
         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
-                                      (*pp_intf)->p_sys->b_autoplayfile );
+                                      p_intf->p_sys->b_autoplayfile );
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 }
 
index 0a56dcb99f5cc950f4a50620da6a4e71a5bc434a..bf52c248c428cbb05602c80c32a03bee9b1e7910 100644 (file)
@@ -2,7 +2,7 @@
  * display.c: Gtk+ tools for main interface
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: display.c,v 1.4 2002/09/30 11:05:38 sam Exp $
+ * $Id: display.c,v 1.5 2002/12/13 01:56:29 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Stéphane Borel <stef@via.ecp.fr>
@@ -237,32 +237,33 @@ gint E_(GtkModeManage)( intf_thread_t * p_intf )
  *****************************************************************************/
 void E_(GtkHideTooltips)( vlc_object_t *p_this )
 {
-    intf_thread_t **pp_intf;
-    vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
-                                                FIND_ANYWHERE );
+    intf_thread_t *p_intf;
+    int i_index;
+    vlc_list_t list = vlc_list_find( p_this, VLC_OBJECT_INTF,
+                                             FIND_ANYWHERE );
 
     vlc_bool_t b_enable = config_GetInt( p_this, "gnome-tooltips" );
 
-    for( pp_intf = (intf_thread_t **)p_list->pp_objects ;
-         *pp_intf ;
-         pp_intf++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
-        if( strcmp( MODULE_STRING, (*pp_intf)->p_module->psz_object_name ) )
+        p_intf = (intf_thread_t *)list.p_values[i_index].p_object ;
+
+        if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
         {
             continue;
         }
 
         if( b_enable )
         {
-            gtk_tooltips_enable( (*pp_intf)->p_sys->p_tooltips );
+            gtk_tooltips_enable( p_intf->p_sys->p_tooltips );
         }
         else
         {
-            gtk_tooltips_disable( (*pp_intf)->p_sys->p_tooltips );
+            gtk_tooltips_disable( p_intf->p_sys->p_tooltips );
         }
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 }
 
 #ifdef MODULE_NAME_IS_gnome
@@ -276,28 +277,29 @@ void GtkHideToolbarText( vlc_object_t *p_this )
 {
     GtkToolbarStyle style;
     GtkToolbar * p_toolbar;
-    intf_thread_t **pp_intf;
-    vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
-                                                FIND_ANYWHERE );
+    intf_thread_t *p_intf;
+    int i_index;
+    vlc_list_t list = vlc_list_find( p_this, VLC_OBJECT_INTF,
+                                             FIND_ANYWHERE );
 
     style = config_GetInt( p_this, "gnome-toolbartext" )
             ? GTK_TOOLBAR_BOTH
             : GTK_TOOLBAR_ICONS;
 
-    for( pp_intf = (intf_thread_t **)p_list->pp_objects ;
-         *pp_intf ;
-         pp_intf++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
-        if( strcmp( MODULE_STRING, (*pp_intf)->p_module->psz_object_name ) )
+        p_intf = (module_t *)list.p_values[i_index].p_object ;
+
+        if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
         {
             continue;
         }
 
-        p_toolbar = GTK_TOOLBAR(lookup_widget( (*pp_intf)->p_sys->p_window,
+        p_toolbar = GTK_TOOLBAR(lookup_widget( p_intf->p_sys->p_window,
                                                "toolbar" ));
         gtk_toolbar_set_style( p_toolbar, style );
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 }
 #endif
index 1934cd62c6758497a61332fdaf5d7199221beb2c..1da73898476335da097b4033ecb003303de80d3a 100644 (file)
@@ -2,7 +2,7 @@
  * gtk_preferences.c: functions to handle the preferences dialog box.
  *****************************************************************************
  * Copyright (C) 2000, 2001 VideoLAN
- * $Id: preferences.c,v 1.5 2002/12/06 16:34:07 sam Exp $
+ * $Id: preferences.c,v 1.6 2002/12/13 01:56:29 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *          Loïc Minier <lool@via.ecp.fr>
@@ -118,9 +118,10 @@ void GtkPreferencesShow( GtkMenuItem * menuitem, gpointer user_data )
 static void GtkCreateConfigDialog( char *psz_module_name,
                                    intf_thread_t *p_intf )
 {
-    module_t **pp_parser;
-    vlc_list_t *p_list;
+    module_t *p_parser = NULL;
+    vlc_list_t list;
     module_config_t *p_item;
+    int i_index;
 
     guint rows = 0;
 
@@ -174,23 +175,22 @@ static void GtkCreateConfigDialog( char *psz_module_name,
 
 
     /* Look for the selected module */
-    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
 
         if( psz_module_name
-             && !strcmp( psz_module_name, (*pp_parser)->psz_object_name ) )
+             && !strcmp( psz_module_name, p_parser->psz_object_name ) )
         {
             break;
         }
     }
 
-    if( !(*pp_parser) )
+    if( !p_parser || i_index == list.i_count )
     {
-        vlc_list_release( p_list );
+        vlc_list_release( &list );
         return;
     }
 
@@ -198,12 +198,12 @@ static void GtkCreateConfigDialog( char *psz_module_name,
     /* Create the configuration dialog box */
 
 #ifdef MODULE_NAME_IS_gnome
-    config_dialog = gnome_dialog_new( (*pp_parser)->psz_longname, NULL );
+    config_dialog = gnome_dialog_new( p_parser->psz_longname, NULL );
     config_dialog_vbox = GNOME_DIALOG(config_dialog)->vbox;
 #else
     config_dialog = gtk_dialog_new();
     gtk_window_set_title( GTK_WINDOW(config_dialog),
-                          (*pp_parser)->psz_longname );
+                          p_parser->psz_longname );
     config_dialog_vbox = GTK_DIALOG(config_dialog)->vbox;
 #endif
 
@@ -225,7 +225,7 @@ static void GtkCreateConfigDialog( char *psz_module_name,
     gtk_container_add( GTK_CONTAINER(config_dialog_vbox), config_notebook );
 
     /* Enumerate config options and add corresponding config boxes */
-    p_item = (*pp_parser)->p_config;
+    p_item = p_parser->p_config;
 
     if( p_item ) do
     {
@@ -329,15 +329,16 @@ static void GtkCreateConfigDialog( char *psz_module_name,
             /* build a list of available modules */
             {
                 gchar * entry[2];
-                pp_parser = (module_t **)p_list->pp_objects;
 
-                for( ; *pp_parser ; pp_parser++ )
+                for( i_index = 0; i_index < list.i_count; i_index++ )
                 {
-                    if( !strcmp( (*pp_parser)->psz_capability,
+                    p_parser = (module_t *)list.p_values[i_index].p_object ;
+
+                    if( !strcmp( p_parser->psz_capability,
                                  p_item->psz_type ) )
                     {
-                        entry[0] = (*pp_parser)->psz_object_name;
-                        entry[1] = (*pp_parser)->psz_longname;
+                        entry[0] = p_parser->psz_object_name;
+                        entry[1] = p_parser->psz_longname;
                         gtk_clist_append( GTK_CLIST(module_clist), entry );
                     }
                 }
@@ -515,7 +516,7 @@ static void GtkCreateConfigDialog( char *psz_module_name,
     }
     while( p_item->i_type != CONFIG_HINT_END && p_item++ );
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
 #ifndef MODULE_NAME_IS_gnome
     /* Now let's add the action buttons at the bottom of the page */
@@ -658,9 +659,10 @@ static void GtkModuleHighlighted( GtkCList *module_clist, int row, int column,
 {
     intf_thread_t *p_intf;
     GtkWidget *config_button;
-    module_t **pp_parser;
-    vlc_list_t *p_list;
+    module_t *p_parser;
+    vlc_list_t list;
     char *psz_name;
+    int i_index;
 
     p_intf = (intf_thread_t *)gtk_object_get_data( GTK_OBJECT(module_clist),
                                                    "p_intf" );
@@ -671,19 +673,19 @@ static void GtkModuleHighlighted( GtkCList *module_clist, int row, int column,
     }
 
     /* look for module 'psz_name' */
-    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
-        if( !strcmp( (*pp_parser)->psz_object_name, psz_name ) )
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
+
+        if( !strcmp( p_parser->psz_object_name, psz_name ) )
         {
             gtk_object_set_data( GTK_OBJECT(module_clist),
-                                 "module_highlighted", (*pp_parser) );
+                                 "module_highlighted", p_parser );
             config_button = gtk_object_get_data( GTK_OBJECT(module_clist),
                                                  "config_button" );
-            if( (*pp_parser)->i_config_items )
+            if( p_parser->i_config_items )
                 gtk_widget_set_sensitive( config_button, TRUE );
             else
                 gtk_widget_set_sensitive( config_button, FALSE );
@@ -692,7 +694,7 @@ static void GtkModuleHighlighted( GtkCList *module_clist, int row, int column,
         }
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 }
 
 /****************************************************************************
index 1595c26a73631626cce991b2895a107a1ef64273..597eaf36c91ac6fde8b4b48a2f4f7e66736b56f1 100644 (file)
@@ -2,7 +2,7 @@
  * preferences.cpp: preferences window for the kde gui
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: preferences.cpp,v 1.8 2002/10/16 23:34:27 sigmunau Exp $
+ * $Id: preferences.cpp,v 1.9 2002/12/13 01:56:29 gbazin Exp $
  *
  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no> Mon Aug 12 2002
  *
@@ -52,37 +52,37 @@ KPreferences::KPreferences(intf_thread_t *p_intf, const char *psz_module_name,
     KDialogBase ( Tabbed, caption, Ok| Apply|Cancel|User1, Ok, parent,
                   "vlc preferences", true, false, "Save")
 {
-    module_t **pp_parser;
-    vlc_list_t *p_list;
+    module_t *p_parser;
+    vlc_list_t list;
     module_config_t *p_item;
+    int i_index;
     QVBox *category_table = NULL;
     QString *category_label;
 
     this->p_intf = p_intf;
 
     /* List all modules */
-    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
     /* Look for the selected module */
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
 
         if( psz_module_name
-            && !strcmp( psz_module_name, (*pp_parser)->psz_object_name ) )
+            && !strcmp( psz_module_name, p_parser->psz_object_name ) )
         {
             break;
         }
     }
 
-    if( !(*pp_parser) )
+    if( !p_parser || i_index == list.i_count )
     {
-        vlc_list_release( p_list );
+        vlc_list_release( list );
         return;
     }
 
-    p_item = (*pp_parser)->p_config;
+    p_item = p_parser->p_config;
     if( p_item ) do
     {
         switch( p_item->i_type )
@@ -129,18 +129,18 @@ KPreferences::KPreferences(intf_thread_t *p_intf, const char *psz_module_name,
             connect(item_frame, SIGNAL(selectionChanged(const QString &)),
                     ci, SLOT(setValue(const QString &)));
 
-                
+
             /* build a list of available plugins */
-            for( pp_parser = (module_t **)p_list->pp_objects ;
-                 *pp_parser ;
-                 pp_parser++ )
+            for( i_index = 0; i_index < list.i_count; i_index++ )
             {
-                if( !strcmp( (*pp_parser)->psz_capability,
+                p_parser = (module_t *)list.p_values[i_index].p_object ;
+
+                if( !strcmp( p_parser->psz_capability,
                              p_item->psz_type ) )
                 {
                     new QListViewItem(item_frame->getListView(),
-                                      (*pp_parser)->psz_object_name,
-                                      (*pp_parser)->psz_longname);
+                                      p_parser->psz_object_name,
+                                      p_parser->psz_longname);
                 }
             }
 
@@ -256,7 +256,7 @@ KPreferences::KPreferences(intf_thread_t *p_intf, const char *psz_module_name,
     }
     while( p_item->i_type != CONFIG_HINT_END );
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
     exec();
 }
@@ -273,24 +273,25 @@ KPreferences::~KPreferences()
 */
 bool KPreferences::isConfigureable(QString module)
 {
-    module_t **pp_parser;
-    vlc_list_t *p_list;
+    module_t *p_parser;
+    vlc_list_t list;
+    int i_index;
 
-    p_list = vlc_list_find( this->p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( this->p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
-        if( !module.compare( (*pp_parser)->psz_object_name ) )
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
+
+        if( !module.compare( p_parser->psz_object_name ) )
         {
-            bool ret = (*pp_parser)->i_config_items != 0;
-            vlc_list_release( p_list );
+            bool ret = p_parser->i_config_items != 0;
+            vlc_list_release( &list );
             return ret;
         }
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
     return false;
 }
 
index f1dfd3492dd961d0c12dd3ce52f8bfde2ac0107f..417153baec87d6b89b3d705aec721d6c7898ac91 100644 (file)
@@ -2,7 +2,7 @@
  * prefs.m: MacOS X plugin for vlc
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: prefs.m,v 1.1 2002/11/05 03:57:16 jlj Exp $
+ * $Id: prefs.m,v 1.2 2002/12/13 01:56:30 gbazin Exp $
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> 
  *
 
 - (BOOL)hasPrefs:(NSString *)o_module_name
 {
-    module_t **pp_parser;
-    vlc_list_t *p_list;
+    module_t *p_parser;
+    vlc_list_t list;
     char *psz_module_name;
+    int i_index;
 
     psz_module_name = (char *)[o_module_name lossyCString];
 
     /* look for module */
-    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
-        if( !strcmp( (*pp_parser)->psz_object_name, psz_module_name ) )
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
+
+        if( !strcmp( p_parser->psz_object_name, psz_module_name ) )
         {
-            BOOL b_has_prefs = (*pp_parser)->i_config_items != 0;
-            vlc_list_release( p_list );
+            BOOL b_has_prefs = p_parser->i_config_items != 0;
+            vlc_list_release( &list );
             return( b_has_prefs );
         }
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
     return( NO );
 }
     int i_pos;
     int i_module_tag;
 
-    module_t **pp_parser;
-    vlc_list_t *p_list;
+    module_t *p_parser;
+    vlc_list_t list;
     module_config_t *p_item;
     char *psz_module_name;
+    int i_index;
 
     NSPanel *o_panel;                   /* panel                        */
     NSRect s_panel_rc;                  /* panel rect                   */
     psz_module_name = (char *)[o_module_name lossyCString];
 
     /* Look for the selected module */
-    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
+
         if( psz_module_name
-            && !strcmp( psz_module_name, (*pp_parser)->psz_object_name ) )
+            && !strcmp( psz_module_name, p_parser->psz_object_name ) )
         {
             break;
         }
     }
 
-    if( !(*pp_parser) )
+    if( !p_parser || i_index == list.i_count )
     {
-        vlc_list_release( p_list );
+        vlc_list_release( &list );
         return;
     }
 
                   forKey: o_module_name];
 
     /* Enumerate config options and add corresponding config boxes */
-    p_item = (*pp_parser)->p_config;
+    p_item = p_parser->p_config;
 
     i_pos = 0;
     o_view = nil;
 
             /* build a list of available modules */
             {
-                pp_parser = (module_t **)p_list->pp_objects;
-
-                for( ; *pp_parser ; pp_parser++ )
+                for( i_index = 0; i_index < list.i_count; i_index++ )
                 {
-                    if( !strcmp( (*pp_parser)->psz_capability,
+                    p_parser = (module_t *)list.p_values[i_index].p_object ;
+
+                    if( !strcmp( p_parser->psz_capability,
                                  p_item->psz_type ) )
                     {
                         NSString *o_object_name = [NSString 
-                            stringWithCString: (*pp_parser)->psz_object_name];
+                            stringWithCString: p_parser->psz_object_name];
                         [o_modules addItemWithTitle: o_object_name];
                     }
                 }
     }
     while( p_item->i_type != CONFIG_HINT_END && p_item++ );
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
     [o_toolbars setObject: o_tb_items forKey: o_module_name];
     [o_toolbar setDelegate: self];
index 92ea21ec3dab8d94788d9d6daf3c7473277ef714..51cfd2dd26018c12bf877c6be95d44d11f99f15b 100644 (file)
@@ -248,8 +248,9 @@ __fastcall TPanelPlugin::TPanelPlugin( TComponent* Owner,
 //---------------------------------------------------------------------------\r
 void __fastcall TPanelPlugin::CheckListBoxClick( TObject *Sender )\r
 {\r
-    module_t **pp_parser;\r
-    vlc_list_t *p_list;\r
+    module_t *p_parser;\r
+    vlc_list_t list;\r
+    int i_index;\r
 \r
     /* check that the click is valid (we are on an item, and the click\r
      * started on an item */\r
@@ -262,17 +263,17 @@ void __fastcall TPanelPlugin::CheckListBoxClick( TObject *Sender )
         return;\r
 \r
     /* look for module 'Name' */\r
-    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );\r
+    list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );\r
 \r
-    for( pp_parser = (module_t **)p_list->pp_objects ;\r
-         *pp_parser ;\r
-         pp_parser++ )\r
+    for( i_index = 0; i_index < list.i_count; i_index++ )\r
     {\r
-        if( strcmp( (*pp_parser)->psz_object_name, Name.c_str() ) == 0 )\r
+        p_parser = (module_t *)list.p_values[i_index].p_object ;\r
+\r
+        if( strcmp( p_parser->psz_object_name, Name.c_str() ) == 0 )\r
         {\r
-            ModuleSelected = (*pp_parser);\r
+            ModuleSelected = p_parser;\r
             ButtonConfig->Enabled =\r
-                (*pp_parser)->i_config_items ? true : false;\r
+                p_parser->i_config_items ? true : false;\r
 \r
             break;\r
         }\r
@@ -523,8 +524,9 @@ void __fastcall TPreferencesDlg::FormClose( TObject *Sender,
 \r
 void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )\r
 {\r
-    module_t          **pp_parser;\r
-    vlc_list_t         *p_list;\r
+    module_t           *p_parser;\r
+    vlc_list_t          list;\r
+    int                 i_index;\r
 \r
     module_config_t    *p_item;\r
     int                 i_pages, i_ctrl;\r
@@ -539,21 +541,21 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
     TPanelBool         *PanelBool;\r
 \r
     /* Look for the selected module */\r
-    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );\r
+    list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );\r
 \r
-    for( pp_parser = (module_t **)p_list->pp_objects ;\r
-         *pp_parser ;\r
-         pp_parser++ )\r
+    for( i_index = 0; i_index < list.i_count; i_index++ )\r
     {\r
+        p_parser = (module_t *)list.p_values[i_index].p_object ;\r
+\r
         if( psz_module_name\r
-             && !strcmp( psz_module_name, (*pp_parser)->psz_object_name ) )\r
+             && !strcmp( psz_module_name, p_parser->psz_object_name ) )\r
         {\r
             break;\r
         }\r
     }\r
-    if( !(*pp_parser) )\r
+    if( !p_parser || i_index == list.i_count )\r
     {\r
-        vlc_list_release( p_list );\r
+        vlc_list_release( &list );\r
         return;\r
     }\r
 \r
@@ -562,7 +564,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
      */\r
 \r
     /* Enumerate config options and add corresponding config boxes */\r
-    p_item = (*pp_parser)->p_config;\r
+    p_item = p_parser->p_config;\r
     if( p_item ) do\r
     {\r
         switch( p_item->i_type )\r
@@ -595,29 +597,29 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
             PanelPlugin->Parent = ScrollBox;\r
 \r
             /* Look for valid modules */\r
-            pp_parser = (module_t **)p_list->pp_objects;\r
-\r
-            for( ; *pp_parser ; pp_parser++ )\r
+            for( i_index = 0; i_index < list.i_count; i_index++ )\r
             {\r
-                if( !strcmp( (*pp_parser)->psz_capability, p_item->psz_type ) )\r
+                p_parser = (module_t *)list.p_values[i_index].p_object ;\r
+\r
+                if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )\r
                 {\r
                     AnsiString ModuleDesc;\r
-                    if ( (*pp_parser)->psz_longname != NULL ) {\r
-                        ModuleDesc = AnsiString((*pp_parser)->psz_longname) +\r
-                            " (" + AnsiString((*pp_parser)->psz_object_name) +\r
+                    if ( p_parser->psz_longname != NULL ) {\r
+                        ModuleDesc = AnsiString(p_parser->psz_longname) +\r
+                            " (" + AnsiString(p_parser->psz_object_name) +\r
                             ")";\r
                     }\r
                     else\r
-                        ModuleDesc = AnsiString((*pp_parser)->psz_object_name);\r
+                        ModuleDesc = AnsiString(p_parser->psz_object_name);\r
 \r
                     int item = PanelPlugin->CleanCheckListBox->Items->AddObject(\r
                         ModuleDesc.c_str(),\r
-                        new TObjectString((*pp_parser)->psz_object_name) );\r
+                        new TObjectString(p_parser->psz_object_name) );\r
 \r
                     /* check the box if it's the default module */\r
                     AnsiString Name = p_item->psz_value ?\r
                         p_item->psz_value : "";\r
-                    if( !strcmp( (*pp_parser)->psz_object_name, Name.c_str()) )\r
+                    if( !strcmp( p_parser->psz_object_name, Name.c_str()) )\r
                     {\r
                         PanelPlugin->CleanCheckListBox->Checked[item] = true;\r
                     }\r
@@ -683,7 +685,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
         }\r
     }\r
 \r
-    vlc_list_release( p_list );\r
+    vlc_list_release( &list );\r
 \r
     /* set active tabsheet\r
      * FIXME: i don't know why, but both lines are necessary */\r
index b71eb94b02bfc4224a4b56c24983e137832b6ffe..3642b798122a26e36b42295cf2d864674e0fb534 100644 (file)
@@ -2,7 +2,7 @@
  * libvlc.c: main libvlc source
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: libvlc.c,v 1.50 2002/12/08 00:41:06 massiot Exp $
+ * $Id: libvlc.c,v 1.51 2002/12/13 01:56:30 gbazin Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -1005,11 +1005,12 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
      */
 #define LINE_START 8
 #define PADDING_SPACES 25
-    vlc_list_t *p_list;
-    module_t **pp_parser;
+    vlc_list_t list;
+    module_t *p_parser;
     module_config_t *p_item;
     char psz_spaces[PADDING_SPACES+LINE_START+1];
     char psz_format[sizeof(FORMAT_STRING)];
+    int i_index;
 
     memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
     psz_spaces[PADDING_SPACES+LINE_START] = '\0';
@@ -1021,31 +1022,31 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
 #endif
 
     /* List all modules */
-    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
     /* Enumerate the config for each module */
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
         vlc_bool_t b_help_module;
 
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
+
         if( psz_module_name && strcmp( psz_module_name,
-                                       (*pp_parser)->psz_object_name ) )
+                                       p_parser->psz_object_name ) )
         {
             continue;
         }
 
         /* Ignore modules without config options */
-        if( !(*pp_parser)->i_config_items )
+        if( !p_parser->i_config_items )
         {
             continue;
         }
 
-        b_help_module = !strcmp( "help", (*pp_parser)->psz_object_name );
+        b_help_module = !strcmp( "help", p_parser->psz_object_name );
 
         /* Print module options */
-        for( p_item = (*pp_parser)->p_config;
+        for( p_item = p_parser->p_config;
              p_item->i_type != CONFIG_HINT_END;
              p_item++ )
         {
@@ -1180,7 +1181,7 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
     }
 
     /* Release the module list */
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
         fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
@@ -1196,9 +1197,10 @@ static void Usage( vlc_t *p_this, char const *psz_module_name )
  *****************************************************************************/
 static void ListModules( vlc_t *p_this )
 {
-    vlc_list_t *p_list;
-    module_t **pp_parser;
+    vlc_list_t list;
+    module_t *p_parser;
     char psz_spaces[22];
+    int i_index;
 
     memset( psz_spaces, ' ', 22 );
 
@@ -1213,28 +1215,28 @@ static void ListModules( vlc_t *p_this )
     fprintf( stdout, _("[module]              [description]\n") );
 
     /* List all modules */
-    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
     /* Enumerate each module */
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
         int i;
 
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
+
         /* Nasty hack, but right now I'm too tired to think about a nice
          * solution */
-        i = 22 - strlen( (*pp_parser)->psz_object_name ) - 1;
+        i = 22 - strlen( p_parser->psz_object_name ) - 1;
         if( i < 0 ) i = 0;
         psz_spaces[i] = 0;
 
-        fprintf( stdout, "  %s%s %s\n", (*pp_parser)->psz_object_name,
-                         psz_spaces, (*pp_parser)->psz_longname );
+        fprintf( stdout, "  %s%s %s\n", p_parser->psz_object_name,
+                         psz_spaces, p_parser->psz_longname );
 
         psz_spaces[i] = ' ';
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
         fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
@@ -1283,4 +1285,3 @@ static void ShowConsole( void )
     return;
 }
 #endif
-
index ff3d96743e2c7c204573108029b7bcc948165811..91de98555323cea652ff08cf18d58b626a98af8b 100644 (file)
@@ -2,7 +2,7 @@
  * configuration.c management of the modules configuration
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: configuration.c,v 1.46 2002/11/13 20:51:05 sam Exp $
+ * $Id: configuration.c,v 1.47 2002/12/13 01:56:30 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -271,22 +271,23 @@ void __config_PutFloat( vlc_object_t *p_this,
  *****************************************************************************/
 module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
 {
-    vlc_list_t *p_list; 
-    module_t **pp_parser;
+    vlc_list_t list; 
+    module_t *p_parser;
     module_config_t *p_item;
+    int i_index;
 
     if( !psz_name ) return NULL;
 
-    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
-        if( !(*pp_parser)->i_config_items )
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
+
+        if( !p_parser->i_config_items )
             continue;
 
-        for( p_item = (*pp_parser)->p_config;
+        for( p_item = p_parser->p_config;
              p_item->i_type != CONFIG_HINT_END;
              p_item++ )
         {
@@ -295,13 +296,13 @@ module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
                 continue;
             if( !strcmp( psz_name, p_item->psz_name ) )
             {
-                vlc_list_release( p_list );
+                vlc_list_release( &list );
                 return p_item;
             }
         }
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
     return NULL;
 }
@@ -420,11 +421,11 @@ void config_Free( module_t *p_module )
             free( p_item->psz_value );
 
         if( p_item->ppsz_list )
-       {
-           for( i = 0; p_item->ppsz_list[i]; i++ )
-               free(p_item->ppsz_list[i]);
-           free( p_item->ppsz_list );
-       }
+        {
+            for( i = 0; p_item->ppsz_list[i]; i++ )
+                free(p_item->ppsz_list[i]);
+            free( p_item->ppsz_list );
+        }
     }
 
     free( p_module->p_config );
@@ -470,13 +471,14 @@ void config_UnsetCallbacks( module_config_t *p_new )
  *****************************************************************************/
 int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
 {
-    vlc_list_t *p_list; 
-    module_t **pp_parser;
+    vlc_list_t list; 
+    module_t *p_parser;
     module_config_t *p_item;
     FILE *file;
     char line[1024];
     char *p_index, *psz_option_name, *psz_option_value;
     char *psz_filename, *psz_homedir;
+    int i_index;
 
     psz_homedir = p_this->p_vlc->psz_homedir;
     if( !psz_homedir )
@@ -508,15 +510,14 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
     }
 
     /* Look for the selected module, if NULL then save everything */
-    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
 
         if( psz_module_name
-             && strcmp( psz_module_name, (*pp_parser)->psz_object_name ) )
+             && strcmp( psz_module_name, p_parser->psz_object_name ) )
         {
             continue;
         }
@@ -529,13 +530,13 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
             if( (line[0] == '[')
                && (p_index = strchr(line,']'))
                && (p_index - &line[1]
-                    == (int)strlen((*pp_parser)->psz_object_name))
-               && !memcmp( &line[1], (*pp_parser)->psz_object_name,
-                           strlen((*pp_parser)->psz_object_name) ) )
+                    == (int)strlen(p_parser->psz_object_name))
+               && !memcmp( &line[1], p_parser->psz_object_name,
+                           strlen(p_parser->psz_object_name) ) )
             {
 #if 0
                 msg_Dbg( p_this, "loading config for module \"%s\"",
-                                 (*pp_parser)->psz_object_name );
+                                 p_parser->psz_object_name );
 #endif
 
                 break;
@@ -565,13 +566,13 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
             *p_index = (char)0;
             psz_option_value = p_index + 1;
 
-            if( !(*pp_parser)->i_config_items )
+            if( !p_parser->i_config_items )
             {
                 continue;
             }
 
             /* try to match this option with one of the module's options */
-            for( p_item = (*pp_parser)->p_config;
+            for( p_item = p_parser->p_config;
                  p_item->i_type != CONFIG_HINT_END;
                  p_item++ )
             {
@@ -630,7 +631,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
 
     }
     
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
     fclose( file );
     free( psz_filename );
@@ -661,8 +662,8 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
  *****************************************************************************/
 int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
 {
-    module_t **pp_parser;
-    vlc_list_t *p_list;
+    module_t *p_parser;
+    vlc_list_t list;
     module_config_t *p_item;
     FILE *file;
     char p_line[1024], *p_index2;
@@ -670,6 +671,7 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
     char *p_bigbuffer, *p_index;
     vlc_bool_t b_backup;
     char *psz_filename, *psz_homedir;
+    int i_index;
 
     /* Acquire config file lock */
     vlc_mutex_lock( &p_this->p_vlc->config_lock );
@@ -750,7 +752,7 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
     p_bigbuffer[0] = 0;
 
     /* List all available modules */
-    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
     /* backup file into memory, we only need to backup the sections we won't
      * save later on */
@@ -761,24 +763,24 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
         {
 
             /* we found a section, check if we need to do a backup */
-            for( pp_parser = (module_t **)p_list->pp_objects ;
-                 *pp_parser ;
-                 pp_parser++ )
+            for( i_index = 0; i_index < list.i_count; i_index++ )
             {
+                p_parser = (module_t *)list.p_values[i_index].p_object ;
+
                 if( ((p_index2 - &p_line[1])
-                       == (int)strlen((*pp_parser)->psz_object_name) )
-                    && !memcmp( &p_line[1], (*pp_parser)->psz_object_name,
-                                strlen((*pp_parser)->psz_object_name) ) )
+                       == (int)strlen(p_parser->psz_object_name) )
+                    && !memcmp( &p_line[1], p_parser->psz_object_name,
+                                strlen(p_parser->psz_object_name) ) )
                 {
                     if( !psz_module_name )
                         break;
                     else if( !strcmp( psz_module_name,
-                                      (*pp_parser)->psz_object_name ) )
+                                      p_parser->psz_object_name ) )
                         break;
                 }
             }
 
-            if( !(*pp_parser) )
+            if( i_index == list.i_count )
             {
                 /* we don't have this section in our list so we need to back
                  * it up */
@@ -817,7 +819,7 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
         msg_Warn( p_this, "could not open config file %s for writing",
                           psz_filename );
         free( psz_filename );
-        vlc_list_release( p_list );
+        vlc_list_release( &list );
         vlc_mutex_unlock( &p_this->p_vlc->config_lock );
         return -1;
     }
@@ -825,28 +827,27 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
     fprintf( file, "###\n###  " COPYRIGHT_MESSAGE "\n###\n\n" );
 
     /* Look for the selected module, if NULL then save everything */
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_index = 0; i_index < list.i_count; i_index++ )
     {
+        p_parser = (module_t *)list.p_values[i_index].p_object ;
 
         if( psz_module_name && strcmp( psz_module_name,
-                                       (*pp_parser)->psz_object_name ) )
+                                       p_parser->psz_object_name ) )
             continue;
 
-        if( !(*pp_parser)->i_config_items )
+        if( !p_parser->i_config_items )
             continue;
 
         msg_Dbg( p_this, "saving config for module \"%s\"",
-                         (*pp_parser)->psz_object_name );
+                         p_parser->psz_object_name );
 
-        fprintf( file, "[%s]", (*pp_parser)->psz_object_name );
-        if( (*pp_parser)->psz_longname )
-            fprintf( file, " # %s\n\n", (*pp_parser)->psz_longname );
+        fprintf( file, "[%s]", p_parser->psz_object_name );
+        if( p_parser->psz_longname )
+            fprintf( file, " # %s\n\n", p_parser->psz_longname );
         else
             fprintf( file, "\n\n" );
 
-        for( p_item = (*pp_parser)->p_config;
+        for( p_item = p_parser->p_config;
              p_item->i_type != CONFIG_HINT_END;
              p_item++ )
         {
@@ -885,7 +886,7 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
         fprintf( file, "\n" );
     }
 
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
     /*
      * Restore old settings from the config in file
@@ -913,10 +914,11 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
                           vlc_bool_t b_ignore_errors )
 {
     int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0;
-    module_t **pp_parser;
-    vlc_list_t *p_list;
+    module_t *p_parser;
+    vlc_list_t list;
     module_config_t *p_item;
     struct option *p_longopts;
+    int i_modules_index;
 
     /* Short options */
     module_config_t *pp_shortopts[256];
@@ -949,29 +951,30 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
 #endif
 
     /* List all modules */
-    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
 
     /*
      * Generate the longopts and shortopts structures used by getopt_long
      */
 
     i_opts = 0;
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_modules_index = 0; i_modules_index < list.i_count;
+         i_modules_index++ )
     {
+        p_parser = (module_t *)list.p_values[i_modules_index].p_object ;
+
         /* count the number of exported configuration options (to allocate
          * longopts). We also need to allocate space for too options when
          * dealing with boolean to allow for --foo and --no-foo */
-        i_opts += (*pp_parser)->i_config_items
-                     + 2 * (*pp_parser)->i_bool_items;
+        i_opts += p_parser->i_config_items
+                     + 2 * p_parser->i_bool_items;
     }
 
     p_longopts = malloc( sizeof(struct option) * (i_opts + 1) );
     if( p_longopts == NULL )
     {
         msg_Err( p_this, "out of memory" );
-        vlc_list_release( p_list );
+        vlc_list_release( &list );
         return -1;
     }
 
@@ -980,7 +983,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
     {
         msg_Err( p_this, "out of memory" );
         free( p_longopts );
-        vlc_list_release( p_list );
+        vlc_list_release( &list );
         return -1;
     }
 
@@ -995,7 +998,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
             msg_Err( p_this, "out of memory" );
             free( psz_shortopts );
             free( p_longopts );
-            vlc_list_release( p_list );
+            vlc_list_release( &list );
             return -1;
         }
         memcpy( ppsz_argv, p_this->p_vlc->ppsz_argv,
@@ -1010,14 +1013,15 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
 
     /* Fill the p_longopts and psz_shortopts structures */
     i_index = 0;
-    for( pp_parser = (module_t **)p_list->pp_objects ;
-         *pp_parser ;
-         pp_parser++ )
+    for( i_modules_index = 0; i_modules_index < list.i_count;
+         i_modules_index++ )
     {
-        if( !(*pp_parser)->i_config_items )
+        p_parser = (module_t *)list.p_values[i_modules_index].p_object ;
+
+        if( !p_parser->i_config_items )
             continue;
 
-        for( p_item = (*pp_parser)->p_config;
+        for( p_item = p_parser->p_config;
              p_item->i_type != CONFIG_HINT_END;
              p_item++ )
         {
@@ -1084,7 +1088,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
     }
 
     /* We don't need the module list anymore */
-    vlc_list_release( p_list );
+    vlc_list_release( &list );
 
     /* Close the longopts and shortopts structures */
     memset( &p_longopts[i_index], 0, sizeof(struct option) );
index 779e002e10b07ec71319760495a2986cedf92386..44c5763ebd5066a81484825efd7bb3ec4d16c050 100644 (file)
@@ -2,7 +2,7 @@
  * modules.c : Builtin and plugin modules management functions
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: modules.c,v 1.107 2002/11/19 17:38:07 sam Exp $
+ * $Id: modules.c,v 1.108 2002/12/13 01:56:30 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Ethan C. Baldridge <BaldridgeE@cadmus.com>
@@ -250,13 +250,12 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
     };
 
     module_list_t *p_list, *p_first, *p_tmp;
-    vlc_list_t *p_all;
+    vlc_list_t all;
 
-    int i_index = 0;
+    int i_which_module, i_index = 0;
     vlc_bool_t b_intf = VLC_FALSE;
 
     module_t *p_module;
-    module_t **pp_parser;
 
     int   i_shortcuts = 0;
     char *psz_shortcuts = NULL, *psz_var = NULL;
@@ -296,17 +295,17 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
     }
 
     /* Sort the modules and test them */
-    p_all = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
-    p_list = malloc( p_all->i_count * sizeof( module_list_t ) );
+    all = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    p_list = malloc( all.i_count * sizeof( module_list_t ) );
     p_first = NULL;
 
     /* Parse the module list for capabilities and probe each of them */
-    for( pp_parser = (module_t**)p_all->pp_objects ; *pp_parser ; pp_parser++ )
+    for( i_which_module = 0; i_which_module < all.i_count; i_which_module++ )
     {
         module_t * p_submodule = NULL;
         int i_shortcut_bonus = 0, i_submodule;
 
-        p_module = *pp_parser;
+        p_module = (module_t *)all.p_values[i_which_module].p_object;
 
         /* Test that this module can do what we need */
         if( strcmp( p_module->psz_capability, psz_capability ) )
@@ -449,7 +448,7 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
     }
 
     /* We can release the list, interesting modules were yielded */
-    vlc_list_release( p_all );
+    vlc_list_release( &all );
 
     /* Parse the linked list and use the first successful module */
     p_tmp = p_first;
@@ -977,4 +976,3 @@ static int CallEntry( module_t * p_module )
     return 0;
 }
 #endif /* HAVE_DYNAMIC_PLUGINS */
-
index 61e2e98122a953577a89dddadfda4e7bd61f88f0..f6ae50bde1ff0697af09211c947271d854f5fb61 100644 (file)
@@ -2,7 +2,7 @@
  * objects.c: vlc_object_t handling
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: objects.c,v 1.31 2002/12/07 15:25:27 gbazin Exp $
+ * $Id: objects.c,v 1.32 2002/12/13 01:56:30 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -57,8 +57,9 @@ static void           DumpStructure ( vlc_object_t *, int, char * );
 static int            FindIndex     ( vlc_object_t *, vlc_object_t **, int );
 static void           SetAttachment ( vlc_object_t *, vlc_bool_t );
 
-static vlc_list_t *   NewList       ( void );
-static vlc_list_t *   ListAppend    ( vlc_list_t *, vlc_object_t * );
+static vlc_list_t     NewList       ( int );
+static void           ListReplace   ( vlc_list_t *, vlc_object_t *, int );
+static void           ListAppend    ( vlc_list_t *, vlc_object_t * );
 
 /*****************************************************************************
  * Local structure lock
@@ -486,9 +487,9 @@ void __vlc_object_detach( vlc_object_t *p_this )
  * This function recursively looks for a given object type. i_mode can be one
  * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
  *****************************************************************************/
-vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
+vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
 {
-    vlc_list_t *p_list = NewList();
+    vlc_list_t list;
 
     vlc_mutex_lock( &structure_lock );
 
@@ -496,6 +497,7 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
     if( (i_mode & 0x000f) == FIND_ANYWHERE )
     {
         vlc_object_t **pp_current, **pp_end;
+        int i_count = 0, i_index = 0;
 
         pp_current = p_this->p_libvlc->pp_objects;
         pp_end = pp_current + p_this->p_libvlc->i_objects;
@@ -505,18 +507,32 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
             if( (*pp_current)->b_attached
                  && (*pp_current)->i_object_type == i_type )
             {
-                p_list = ListAppend( p_list, *pp_current );
+                i_count++;
+            }
+        }
+
+        list = NewList( i_count );
+        pp_current = p_this->p_libvlc->pp_objects;
+
+        for( ; pp_current < pp_end ; pp_current++ )
+        {
+            if( (*pp_current)->b_attached
+                 && (*pp_current)->i_object_type == i_type )
+            {
+                ListReplace( &list, *pp_current, i_index );
+                if( i_index < i_count ) i_index++;
             }
         }
     }
     else
     {
         msg_Err( p_this, "unimplemented!" );
+        list = NewList( 0 );
     }
 
     vlc_mutex_unlock( &structure_lock );
 
-    return p_list;
+    return list;
 }
 
 /*****************************************************************************
@@ -592,22 +608,18 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
  *****************************************************************************/
 void vlc_list_release( vlc_list_t *p_list )
 {
-    if( p_list->i_count )
-    {
-        vlc_object_t ** pp_current = p_list->pp_objects;
+    int i_index;
 
+    for( i_index = 0; i_index < p_list->i_count; i_index++ )
+    {
         vlc_mutex_lock( &structure_lock );
 
-        while( pp_current[0] )
-        {
-            pp_current[0]->i_refcount--;
-            pp_current++;
-        }
+        p_list->p_values[i_index].p_object->i_refcount--;
 
         vlc_mutex_unlock( &structure_lock );
     }
 
-    free( p_list );
+    free( p_list->p_values );
 }
 
 /* Following functions are local */
@@ -844,57 +856,62 @@ static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
     }
 }
 
-static vlc_list_t * NewList( void )
+static vlc_list_t NewList( int i_count )
 {
-    vlc_list_t *p_list = malloc( sizeof( vlc_list_t )
-                                     + 3 * sizeof( vlc_object_t * ) );
+    vlc_list_t list;
 
-    if( p_list == NULL )
+    list.i_count = i_count;
+
+    if( i_count == 0 )
     {
-        return NULL;
+        list.p_values = NULL;
+        return list;
     }
 
-    p_list->i_count = 0;
-    p_list->pp_objects = &p_list->_p_first;
+    list.p_values = malloc( i_count * sizeof( vlc_value_t ) );
+    if( list.p_values == NULL )
+    {
+        list.i_count = 0;
+        return list;
+    }
+
+    return list;
+}
+
+static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
+                         int i_index )
+{
+    if( p_list == NULL || i_index >= p_list->i_count )
+    {
+        return;
+    }
 
-    /* We allocated space for NULL and for three extra objects */
-    p_list->_i_extra = 3;
-    p_list->_p_first = NULL;
+    p_object->i_refcount++;
+
+    p_list->p_values[i_index].p_object = p_object;
 
-    return p_list;
+    return;
 }
 
-static vlc_list_t * ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
+static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
 {
     if( p_list == NULL )
     {
-        return NULL;
+        return;
     }
 
-    if( p_list->_i_extra == 0 )
+    p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
+                                * sizeof( vlc_value_t ) );
+    if( p_list->p_values == NULL )
     {
-        /* If we had X objects it means the array has a size of X+1, we
-         * make it size 2X+2, so we alloc 2X+1 because there is already
-         * one allocated in the real structure */
-        p_list = realloc( p_list, sizeof( vlc_list_t )
-                                   + (p_list->i_count * 2 + 1)
-                                       * sizeof( vlc_object_t * ) );
-        if( p_list == NULL ) 
-        {
-            return NULL;
-        }
-
-        /* We have X+1 extra slots */
-        p_list->_i_extra = p_list->i_count + 1;
-        p_list->pp_objects = &p_list->_p_first;
+        p_list->i_count = 0;
+        return;
     }
 
     p_object->i_refcount++;
 
-    p_list->pp_objects[p_list->i_count] = p_object;
+    p_list->p_values[p_list->i_count].p_object = p_object;
     p_list->i_count++;
-    p_list->pp_objects[p_list->i_count] = NULL;
-    p_list->_i_extra--;
 
-    return p_list;
+    return;
 }