* 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
/*****************************************************************************
* 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 * );
{
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. */
}
/* 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;
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 );
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
/* 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
*****************************************************************************
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;
#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