* modules.c : Builtin and plugin modules management functions
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: modules.c,v 1.100 2002/10/31 11:16:30 sam Exp $
+ * $Id: modules.c,v 1.109 2003/01/02 23:50:55 massiot Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Ethan C. Baldridge <BaldridgeE@cadmus.com>
#include <vlc/vlc.h>
-#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#ifdef HAVE_DIRENT_H
+# include <dirent.h>
+#elif defined( UNDER_CE )
+# include <windows.h> /* GetFileAttributes() */
+#else
+# include "../extras/dirent.h"
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#elif defined(HAVE_IMAGE_H) /* BeOS */
# include <image.h>
# define HAVE_DYNAMIC_PLUGINS
+#elif defined(UNDER_CE)
+# define HAVE_DYNAMIC_PLUGINS
#elif defined(WIN32)
# define HAVE_DYNAMIC_PLUGINS
#else
#include "iso_lang.h"
+#if defined( UNDER_CE )
+# define MYCHAR wchar_t
+#else
+# define MYCHAR char
+#endif
+
#ifdef HAVE_DYNAMIC_PLUGINS
# include "modules_plugin.h"
#endif
-#if !defined( _MSC_VER )
-# include "modules_builtin.h"
-#else
+#if defined( UNDER_CE )
+# include "modules_builtin_evc.h"
+#elif defined( _MSC_VER )
# include "modules_builtin_msvc.h"
+#else
+# include "modules_builtin.h"
#endif
/*****************************************************************************
*****************************************************************************/
#ifdef HAVE_DYNAMIC_PLUGINS
static void AllocateAllPlugins ( vlc_object_t * );
-static void AllocatePluginDir ( vlc_object_t *, const char *, int );
-static int AllocatePluginFile ( vlc_object_t *, char * );
+static void AllocatePluginDir ( vlc_object_t *, const MYCHAR *, int );
+static int AllocatePluginFile ( vlc_object_t *, MYCHAR * );
#endif
static int AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
static int DeleteModule ( module_t * );
};
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;
}
/* 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 ) )
}
/* 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;
}
else if( psz_name != NULL && *psz_name )
{
- msg_Err( p_this, "no %s module matching \"%s\" could be loaded",
- psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
+ msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
+ psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
}
if( psz_shortcuts )
vlc_bool_t b_notinroot;
#endif
+#if defined( UNDER_CE )
+ wchar_t psz_dir[MAX_PATH];
+#endif
+
/* If the user provided a plugin path, we add it to the list */
path[ sizeof(path)/sizeof(char*) - 2 ] = config_GetPsz( p_this,
"plugin-path" );
msg_Dbg( p_this, "recursively browsing `%s'", psz_fullpath );
/* Don't go deeper than 5 subdirectories */
+#if defined( UNDER_CE )
+ MultiByteToWideChar( CP_ACP, 0, psz_fullpath, -1, psz_dir, MAX_PATH );
+ AllocatePluginDir( p_this, psz_dir, 5 );
+#else
AllocatePluginDir( p_this, psz_fullpath, 5 );
+#endif
#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
if( b_notinroot )
/*****************************************************************************
* AllocatePluginDir: recursively parse a directory to look for plugins
*****************************************************************************/
-static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
+static void AllocatePluginDir( vlc_object_t *p_this, const MYCHAR *psz_dir,
int i_maxdepth )
{
+#ifdef UNDER_CE
+ MYCHAR psz_path[MAX_PATH + 256];
+ WIN32_FIND_DATA finddata;
+ HANDLE handle;
+ unsigned int rc;
+#else
int i_dirlen;
DIR * dir;
char * psz_file;
-
struct dirent * file;
+#endif
if( i_maxdepth < 0 )
{
return;
}
- dir = opendir( psz_dir );
+#ifdef UNDER_CE
+ rc = GetFileAttributes( psz_dir );
+ if( !(rc & FILE_ATTRIBUTE_DIRECTORY) )
+ {
+ /* Not a directory */
+ return;
+ }
+ /* Parse all files in the directory */
+ swprintf( psz_path, L"%s\\*.*", psz_dir );
+ handle = FindFirstFile( psz_path, &finddata );
+ if( handle == INVALID_HANDLE_VALUE )
+ {
+ /* Empty directory */
+ return;
+ }
+
+ /* Parse the directory and try to load all files it contains. */
+ do
+ {
+ unsigned int i_len = wcslen( finddata.cFileName );
+
+ swprintf( psz_path, L"%s\\%s", psz_dir, finddata.cFileName );
+
+ if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
+ {
+ AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
+ }
+ else if( i_len > strlen( LIBEXT ) )
+ {
+ AllocatePluginFile( p_this, psz_path );
+ }
+ }
+ while( FindNextFile( handle, &finddata ) );
+
+ /* Close the directory */
+ FindClose( handle );
+
+#else
+ dir = opendir( psz_dir );
if( !dir )
{
return;
while( (file = readdir( dir )) )
{
struct stat statbuf;
- int i_len;
+ unsigned int i_len;
/* Skip ".", ".." and anything starting with "." */
if( !*file->d_name || *file->d_name == '.' )
}
i_len = strlen( file->d_name );
-
- psz_file = malloc( i_dirlen + 1 /* / */ + i_len + 1 /* \0 */ );
+ psz_file = malloc( i_dirlen + 1 + i_len + 1 );
sprintf( psz_file, "%s/%s", psz_dir, file->d_name );
if( !stat( psz_file, &statbuf ) && statbuf.st_mode & S_IFDIR )
/* Close the directory */
closedir( dir );
+
+#endif
}
/*****************************************************************************
* for its information data. The module can then be handled by module_Need
* and module_Unneed. It can be removed by DeleteModule.
*****************************************************************************/
-static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file )
+static int AllocatePluginFile( vlc_object_t * p_this, MYCHAR * psz_file )
{
module_t * p_module;
module_handle_t handle;
+#ifdef UNDER_CE
+ char psz_filename[MAX_PATH];
+ WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_file, -1,
+ psz_filename, MAX_PATH, NULL, NULL );
+#else
+ char * psz_filename = psz_file;
+#endif
+
/* Try to dynamically load the module. */
if( module_load( psz_file, &handle ) )
{
/* The plugin module couldn't be opened */
msg_Warn( p_this, "cannot open `%s' (%s)",
- psz_file, module_error( psz_buffer ) );
+ psz_filename, module_error( psz_buffer ) );
return -1;
}
}
/* We need to fill these since they may be needed by CallEntry() */
- p_module->psz_filename = psz_file;
+ p_module->psz_filename = psz_filename;
p_module->handle = handle;
p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
return 0;
}
#endif /* HAVE_DYNAMIC_PLUGINS */
-