#include <errno.h> /* errno */
#include <stdlib.h> /* free() */
+#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <fcntl.h> /* open() */
#include <unistd.h> /* read(), close() */
*****************************************************************************/
vout_font_t *vout_LoadFont( const char *psz_name )
{
+ static char * path[] = { "share", DATA_PATH, NULL };
+
+ char ** ppsz_path = path;
+ char * psz_file;
+#ifdef SYS_BEOS
+ char * psz_vlcpath = beos_GetProgramPath();
+ int i_vlclen = strlen( psz_vlcpath );
+#endif
int i_char, i_line; /* character and line indexes */
- int i_file; /* source file */
+ int i_file = -1; /* source file */
byte_t pi_buffer[2]; /* file buffer */
vout_font_t * p_font; /* the font itself */
- /* Open file */
- i_file = open( psz_name, O_RDONLY );
+ for( ; *ppsz_path != NULL ; ppsz_path++ )
+ {
+#ifdef SYS_BEOS
+ /* Under BeOS, we need to add beos_GetProgramPath() to access
+ * files under the current directory */
+ if( strncmp( *ppsz_path, "/", 1 ) )
+ {
+ psz_file = malloc( strlen( psz_name ) + strlen( *ppsz_path )
+ + i_vlclen + 3 );
+ if( psz_file == NULL )
+ {
+ continue;
+ }
+ sprintf( psz_file, "%s/%s/%s", psz_vlcpath, *ppsz_path, psz_name );
+ }
+ else
+#endif
+ {
+ psz_file = malloc( strlen( psz_name ) + strlen( *ppsz_path ) + 2 );
+ if( psz_file == NULL )
+ {
+ continue;
+ }
+ sprintf( psz_file, "%s/%s", *ppsz_path, psz_name );
+ }
+
+ /* Open file */
+ i_file = open( psz_file, O_RDONLY );
+ free( psz_file );
+
+ if( i_file != -1 )
+ {
+ break;
+ }
+ }
+
if( i_file == -1 )
{
- intf_DbgMsg("vout: can't open file '%s' (%s)", psz_name, strerror(errno));
+ intf_DbgMsg( "vout error: can't open file '%s' (%s)",
+ psz_name, strerror(errno) );
return( NULL );
}
p_font = malloc( sizeof( vout_font_t ) );
if( p_font == NULL )
{
- intf_ErrMsg("vout error: %s", strerror(ENOMEM));
+ intf_ErrMsg( "vout error: cannot allocate vout_font_t (%s)",
+ strerror(ENOMEM) );
close( i_file );
return( NULL );
}
/* Read font header - two bytes indicate the font properties */
if( read( i_file, pi_buffer, 2 ) != 2)
{
- intf_ErrMsg("error: unexpected end of file '%s'", psz_name );
+ intf_ErrMsg( "vout error: unexpected end of file '%s'", psz_name );
free( p_font );
close( i_file );
return( NULL );
p_font->p_data = malloc( 2 * 256 * pi_buffer[1] );
if( p_font->p_data == NULL )
{
- intf_ErrMsg("error: %s", strerror(ENOMEM));
+ intf_ErrMsg( "vout error: cannot allocate font space (%s)",
+ strerror(ENOMEM) );
free( p_font );
close( i_file );
return( NULL );
/* Copy raw data */
if( read( i_file, p_font->p_data, 256 * pi_buffer[1] ) != 256 * pi_buffer[1] )
{
- intf_ErrMsg("error: unexpected end of file '%s'", psz_name );
+ intf_ErrMsg("vout error: unexpected end of file '%s'", psz_name );
free( p_font->p_data );
free( p_font );
close( i_file );
break;
default:
- intf_ErrMsg("error: file '%s' has an unknown format", psz_name );
+ intf_ErrMsg("vout error: file '%s' has an unknown format", psz_name );
free( p_font );
close( i_file );
return( NULL );