]> git.sesse.net Git - vlc/blobdiff - src/libvlc.c
* ALL: libvlc now compiles and run under WinCE. I haven't ported any modules
[vlc] / src / libvlc.c
index f07c7e9166d5acea1816b3c5065a8cab58f2ada3..4439ed00ec5e6a86f3a46aafa0dcb856c6242a1b 100644 (file)
@@ -2,7 +2,7 @@
  * libvlc.c: main libvlc source
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: libvlc.c,v 1.39 2002/10/14 16:46:55 sam Exp $
+ * $Id: libvlc.c,v 1.46 2002/11/10 23:41:53 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>                                                 /* ENOMEM */
+#include <vlc/vlc.h>
+
+#ifdef HAVE_ERRNO_H
+#   include <errno.h>                                              /* ENOMEM */
+#endif
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                            /* strerror() */
 #include <stdlib.h>                                                /* free() */
 
-#include <vlc/vlc.h>
-
 #ifndef WIN32
 #   include <netinet/in.h>                            /* BSD: struct in_addr */
 #endif
 
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
-#elif defined( _MSC_VER ) && defined( _WIN32 )
+#elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
 #   include <io.h>
 #endif
 
 #ifdef WIN32                       /* optind, getopt(), included in unistd.h */
-#   include "extras/GNUgetopt/getopt.h"
+#   include "extras/getopt.h"
 #endif
 
 #ifdef HAVE_LOCALE_H
@@ -86,6 +88,7 @@ static vlc_t *  p_static_vlc;
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
+static void SetLanguage   ( char const * );
 static int  GetFilenames  ( vlc_t *, int, char *[] );
 static void Usage         ( vlc_t *, char const *psz_module_name );
 static void ListModules   ( vlc_t * );
@@ -125,7 +128,7 @@ int VLC_Create( void )
 {
     int i_ret;
     vlc_t * p_vlc = NULL;
-    vlc_mutex_t * p_libvlc_lock;
+    vlc_value_t lockval;
 
     /* vlc_threads_init *must* be the first internal call! No other call is
      * allowed before the thread system has been initialized. */
@@ -136,9 +139,10 @@ int VLC_Create( void )
     }
 
     /* Now that the thread system is initialized, we don't have much, but
-     * at least we have vlc_mutex_need */
-    p_libvlc_lock = vlc_mutex_need( &libvlc, "libvlc" );
-    vlc_mutex_lock( p_libvlc_lock );
+     * at least we have var_Create */
+    var_Create( &libvlc, "libvlc", VLC_VAR_MUTEX );
+    var_Get( &libvlc, "libvlc", &lockval );
+    vlc_mutex_lock( lockval.p_address );
     if( !libvlc.b_ready )
     {
         char *psz_env;
@@ -172,8 +176,8 @@ int VLC_Create( void )
 
         libvlc.b_ready = VLC_TRUE;
     }
-    vlc_mutex_unlock( p_libvlc_lock );
-    vlc_mutex_unneed( &libvlc, "libvlc" );
+    vlc_mutex_unlock( lockval.p_address );
+    var_Destroy( &libvlc, "libvlc" );
 
     /* Allocate a vlc object */
     p_vlc = vlc_object_create( &libvlc, VLC_OBJECT_VLC );
@@ -221,25 +225,10 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         return VLC_ENOOBJ;
     }
 
-    /* Support for gettext */
-#if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
-#   if defined( HAVE_LOCALE_H ) && defined( HAVE_LC_MESSAGES )
-    if( !setlocale( LC_MESSAGES, "" ) )
-    {
-        fprintf( stderr, "warning: unsupported locale settings\n" );
-    }
-
-    setlocale( LC_CTYPE, "" );
-#   endif
-
-    if( !bindtextdomain( PACKAGE, LOCALEDIR ) )
-    {
-        fprintf( stderr, "warning: no domain %s in directory %s\n",
-                 PACKAGE, LOCALEDIR );
-    }
-
-    textdomain( PACKAGE );
-#endif
+    /*
+     * Support for gettext
+     */
+    SetLanguage( "" );
 
     /*
      * System specific initialization code
@@ -916,6 +905,49 @@ int VLC_FullScreen( int i_object )
 
 /* following functions are local */
 
+/*****************************************************************************
+ * SetLanguage: set the interface language.
+ *****************************************************************************
+ * We set the LC_MESSAGES locale category for interface messages and buttons,
+ * as well as the LC_CTYPE category for string sorting and possible wide
+ * character support.
+ *****************************************************************************/
+static void SetLanguage ( char const *psz_lang )
+{
+#if defined( ENABLE_NLS ) \
+     && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
+
+#   if defined( HAVE_INCLUDED_GETTEXT ) && !defined( HAVE_LC_MESSAGES )
+    if( *psz_lang )
+    {
+        /* We set LC_ALL manually because it is the only way to set
+         * the language at runtime under eg. Windows. Beware that this
+         * makes the environment unconsistent when libvlc is unloaded and
+         * should probably be moved to a safer place like vlc.c. */
+        static char psz_lcall[20];
+        snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
+        psz_lcall[19] = '\0';
+        putenv( psz_lcall );
+    }
+#   endif
+
+#   if defined( HAVE_LC_MESSAGES )
+    setlocale( LC_MESSAGES, psz_lang );
+#   endif
+    setlocale( LC_CTYPE, psz_lang );
+
+    /* Specify where to find the locales for current domain */
+    if( !bindtextdomain( PACKAGE, LOCALEDIR ) )
+    {
+        fprintf( stderr, "warning: no domain %s in directory %s\n",
+                 PACKAGE, LOCALEDIR );
+    }
+
+    /* Set the default domain */
+    textdomain( PACKAGE );
+#endif
+}
+
 /*****************************************************************************
  * GetFilenames: parse command line options which are not flags
  *****************************************************************************
@@ -926,12 +958,19 @@ static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
     int i_opt;
 
     /* We assume that the remaining parameters are filenames */
-    for( i_opt = optind; i_opt < i_argc; i_opt++ )
+    for( i_opt = i_argc - 1; i_opt > optind; i_opt-- )
     {
         /* TODO: write an internal function of this one, to avoid
          *       unnecessary lookups. */
         VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
-                          PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
+                       PLAYLIST_INSERT, 0 );
+    }
+
+    /* If there is at least one target, play it */
+    if( i_argc > optind )
+    {
+        VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ optind ],
+                       PLAYLIST_INSERT | PLAYLIST_GO, 0 );
     }
 
     return VLC_SUCCESS;
@@ -1226,10 +1265,12 @@ static void Version( void )
 #ifdef WIN32 /*  */
 static void ShowConsole( void )
 {
+#   ifndef UNDER_CE
     AllocConsole();
     freopen( "CONOUT$", "w", stdout );
     freopen( "CONOUT$", "w", stderr );
     freopen( "CONIN$", "r", stdin );
+#   endif
     return;
 }
 #endif