* modules.c : Built-in and dynamic modules management functions
*****************************************************************************
* Copyright (C) 2001 VideoLAN
+ * $Id: modules.c,v 1.20 2001/04/06 18:18:10 massiot Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Ethan C. Baldridge <BaldridgeE@cadmus.com>
#include "common.h"
#include "threads.h"
+#ifdef SYS_DARWIN1_3
+#include <sys/param.h> /* for MAXPATHLEN */
+#include "main.h"
+extern main_t *p_main;
+#endif
+
#include "intf_msg.h"
#include "modules.h"
#include "modules_core.h"
*****************************************************************************/
void module_InitBank( module_bank_t * p_bank )
{
- static char * path[] = { ".", "lib", PLUGIN_PATH, NULL } ;
+ static char * path[] = { ".", "lib", PLUGIN_PATH, NULL, NULL };
char ** ppsz_path = path;
+ char * psz_fullpath;
char * psz_file;
#ifdef SYS_BEOS
- char * psz_program_path = beos_GetProgramPath();
- int i_programlen = strlen( psz_program_path );
+ char * psz_vlcpath = beos_GetProgramPath();
+ int i_vlclen = strlen( psz_vlcpath );
+ boolean_t b_notinroot;
+#elif defined SYS_DARWIN1_3
+ static char once = 0;
+ static char app_path[ MAXPATHLEN ];
+ // HACK TO CUT OUT trailing 'vlc'
+ int i_pathlen = strlen( p_main->ppsz_argv[0] ) - 3;
#endif
DIR * dir;
struct dirent * file;
intf_WarnMsg( 1, "module: module bank initialized" );
+#ifdef SYS_DARWIN1_3
+ if ( !once )
+ {
+ once = 1;
+ strncpy( app_path, p_main->ppsz_argv[ 0 ], i_pathlen );
+ intf_ErrMsg( "%s", p_main->ppsz_argv[ 0 ] );
+ strcat( app_path, "lib" );
+ path[ 3 ] = app_path ;
+ intf_ErrMsg( "%s", path[ 3 ] );
+ }
+#endif
+
for( ; *ppsz_path != NULL ; ppsz_path++ )
{
- if( (dir = opendir( *ppsz_path )) )
+ /* Store strlen(*ppsz_path) for later use. */
+ int i_dirlen = strlen( *ppsz_path );
+
+#ifdef SYS_BEOS
+ b_notinroot = 0;
+ /* Under BeOS, we need to add beos_GetProgramPath() to access
+ * files under the current directory */
+ if( ( i_dirlen > 1 ) && strncmp( *ppsz_path, "/", 1 ) )
{
- /* Store strlen(*ppsz_path) for later use. */
- int i_dirlen = strlen( *ppsz_path );
+ i_dirlen += i_vlclen + 2;
+ b_notinroot = 1;
+
+ psz_fullpath = malloc( i_dirlen );
+ if( psz_fullpath == NULL )
+ {
+ continue;
+ }
+ sprintf( psz_fullpath, "%s/%s", psz_vlcpath, *ppsz_path );
+ }
+ else
+#endif
+ {
+ psz_fullpath = *ppsz_path;
+ }
+ intf_WarnMsgImm( 2, "module: browsing %s", psz_fullpath );
+
+ if( (dir = opendir( psz_fullpath )) )
+ {
/* Parse the directory and try to load all files it contains. */
while( (file = readdir( dir )) )
{
if( i_filelen > 3
&& !strncmp( file->d_name + i_filelen - 3, ".so", 3 ) )
{
-#ifdef SYS_BEOS
- /* Under BeOS, we need to add beos_GetProgramPath() to
- * access files under the current directory */
- if( strncmp( file->d_name, "/", 1 ) )
- {
- psz_file = malloc( i_programlen + i_dirlen
- + i_filelen + 3 );
- if( psz_file == NULL )
- {
- continue;
- }
- sprintf( psz_file, "%s/%s/%s", psz_programlen,
- *ppsz_path, file->d_name );
- }
- else
-#endif
+ psz_file = malloc( i_dirlen + i_filelen + 2 );
+ if( psz_file == NULL )
{
- psz_file = malloc( i_dirlen + i_filelen + 2 );
- if( psz_file == NULL )
- {
- continue;
- }
- sprintf( psz_file, "%s/%s", *ppsz_path, file->d_name );
+ continue;
}
+ sprintf( psz_file, "%s/%s", psz_fullpath, file->d_name );
+
/* We created a nice filename -- now we just try to load
* it as a dynamic module. */
AllocateDynModule( p_bank, psz_file );
free( psz_file );
}
}
+
+ /* Close the directory if successfully opened */
+ closedir( dir );
}
+
+#ifdef SYS_BEOS
+ if( b_notinroot )
+ {
+ free( psz_fullpath );
+ }
+#endif
}
return;