]> git.sesse.net Git - vlc/blobdiff - src/video_output/video_text.c
* BeOS icon and MIME resources courtesy of Wade Majors <guru@startrek.com>.
[vlc] / src / video_output / video_text.c
index c36cb0396db74b84ca6eaa829439aab332ce179b..7bf9c6dce55e9c9afc6adc3adc9c73ebe2804158 100644 (file)
@@ -2,8 +2,10 @@
  * video_text.c : text manipulation functions
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
+ * $Id: video_text.c,v 1.23 2001/04/12 01:52:45 sam Exp $
  *
- * Authors:
+ * Authors: Vincent Seguin <seguin@via.ecp.fr>
+ *          Samuel Hocevar <sam@zoy.org>
  *
  * 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
 
 #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() */
 
+#ifdef SYS_BEOS
+#   include "beos_specific.h"
+#endif
+
+#ifdef SYS_DARWIN1_3
+#   include "darwin_specific.h"
+#endif
+
 #include "config.h"
 #include "common.h"
 #include "video_text.h"
@@ -203,16 +214,59 @@ static void PutByte32( u32 *p_pic, int i_byte, byte_t i_char, byte_t i_border,
  *****************************************************************************/
 vout_font_t *vout_LoadFont( const char *psz_name )
 {
+    static char * path[] = { "share", DATA_PATH, NULL, NULL };
+
+    char **             ppsz_path = path;
+    char *              psz_file;
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
+    char *              psz_vlcpath = system_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++ )
+    {
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
+        /* 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 );
     }
 
@@ -228,7 +282,8 @@ vout_font_t *vout_LoadFont( const char *psz_name )
     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 );
     }
@@ -245,7 +300,7 @@ vout_font_t *vout_LoadFont( const char *psz_name )
         /* 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 );
@@ -265,7 +320,8 @@ vout_font_t *vout_LoadFont( const char *psz_name )
         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 );
@@ -274,7 +330,7 @@ vout_font_t *vout_LoadFont( const char *psz_name )
         /* 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 );
@@ -300,7 +356,7 @@ vout_font_t *vout_LoadFont( const char *psz_name )
 
         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 );