]> git.sesse.net Git - vlc/blobdiff - src/libvlc-common.c
Support non-ANSI CP characters from command line / click on media file
[vlc] / src / libvlc-common.c
index 87b2cbea26669ef8904dc79cf1fb2c43ce118072..510f8ca79afabc630d98f82fb79b3321594afc64 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * libvlc-common.c: libvlc instances creation and deletion
+ * libvlc-common.c: libvlc instances creation and deletion, interfaces handling
  *****************************************************************************
  * Copyright (C) 1998-2006 the VideoLAN team
  * $Id$
@@ -111,6 +111,8 @@ static void Version       ( void );
 #ifdef WIN32
 static void ShowConsole   ( vlc_bool_t );
 static void PauseConsole  ( void );
+extern void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenviron,
+                           int expand_wildcards, int *startupinfo);
 #endif
 static int  ConsoleWidth  ( void );
 
@@ -145,6 +147,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
     int i_ret;
     libvlc_int_t * p_libvlc = NULL;
     vlc_value_t lockval;
+    char *psz_env;
 
     /* &libvlc_global never changes,
      * so we can safely call this multiple times. */
@@ -165,30 +168,9 @@ libvlc_int_t * libvlc_InternalCreate( void )
 
     if( !libvlc_global.b_ready )
     {
-        char *psz_env;
-
         /* Guess what CPU we have */
         libvlc_global.i_cpu = CPUCapabilities();
-
-        /* Find verbosity from VLC_VERBOSE environment variable */
-        psz_env = getenv( "VLC_VERBOSE" );
-        libvlc_global.i_verbose = psz_env ? atoi( psz_env ) : -1;
-
-#if defined( HAVE_ISATTY ) && !defined( WIN32 )
-        libvlc_global.b_color = isatty( 2 ); /* 2 is for stderr */
-#else
-        libvlc_global.b_color = VLC_FALSE;
-#endif
-
-        /* Initialize message queue */
-        msg_Create( p_libvlc_global );
-
-        /* Announce who we are */
-        msg_Dbg( p_libvlc_global, COPYRIGHT_MESSAGE );
-        msg_Dbg( p_libvlc_global, "libvlc was configured with %s",
-                                CONFIGURE_LINE );
-
-        /* The module bank will be initialized later */
+       /* The module bank will be initialized later */
         libvlc_global.p_module_bank = NULL;
 
         libvlc_global.b_ready = VLC_TRUE;
@@ -203,6 +185,22 @@ libvlc_int_t * libvlc_InternalCreate( void )
     p_libvlc->p_playlist = NULL;
     p_libvlc->psz_object_name = "libvlc";
 
+    /* Initialize message queue */
+    msg_Create( p_libvlc );
+    /* Announce who we are - Do it only for first instance ? */
+    msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
+    msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
+
+    /* Find verbosity from VLC_VERBOSE environment variable */
+    psz_env = getenv( "VLC_VERBOSE" );
+    p_libvlc->i_verbose = psz_env ? atoi( psz_env ) : -1;
+
+#if defined( HAVE_ISATTY ) && !defined( WIN32 )
+    p_libvlc->b_color = isatty( 2 ); /* 2 is for stderr */
+#else
+    p_libvlc->b_color = VLC_FALSE;
+#endif
+
     /* Initialize mutexes */
     vlc_mutex_init( p_libvlc, &p_libvlc->config_lock );
 #ifdef __APPLE__
@@ -350,7 +348,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
     /* End hack */
 
     /* Will be re-done properly later on */
-    p_libvlc->p_libvlc_global->i_verbose = config_GetInt( p_libvlc, "verbose" );
+    p_libvlc->i_verbose = config_GetInt( p_libvlc, "verbose" );
 
     /* Check for daemon mode */
 #ifndef WIN32
@@ -586,8 +584,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
     var_AddCallback( p_libvlc, "verbose", VerboseCallback, NULL );
     var_Change( p_libvlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
 
-    libvlc_global.b_color = libvlc_global.b_color && 
-                                config_GetInt( p_libvlc, "color" );
+    p_libvlc->b_color = p_libvlc->b_color && config_GetInt( p_libvlc, "color" );
 
     /*
      * Output messages that may still be in the queue
@@ -898,16 +895,15 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
         /* System specific cleaning code */
         system_End( p_libvlc );
 
-        /* Free message queue. Nobody shall use msg_* afterward.  */
-        msg_Flush( p_libvlc );
-        msg_Destroy( p_libvlc_global );
-
-        /* Destroy global iconv */
+       /* Destroy global iconv */
         LocaleDeinit();
     }
     vlc_mutex_unlock( lockval.p_address );
     var_Destroy( p_libvlc_global, "libvlc" );
 
+    msg_Flush( p_libvlc );
+    msg_Destroy( p_libvlc );
+
     /* Destroy mutexes */
     vlc_mutex_destroy( &p_libvlc->config_lock );
 
@@ -1048,6 +1044,17 @@ static int GetFilenames( libvlc_int_t *p_vlc, int i_argc, char *ppsz_argv[] )
 {
     int i_opt, i_options;
 
+#ifdef WIN32
+    wchar_t **wargv, **wenvp;
+    int si = { 0 };
+
+    if( GetVersion() < 0x80000000 )
+    {
+        /* fetch unicode argv[] for Windows NT and above */
+        __wgetmainargs(&i_opt, &wargv, &wenvp, 0, &si);
+    }
+#endif
+
     /* We assume that the remaining parameters are filenames
      * and their input options */
     for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
@@ -1065,12 +1072,27 @@ static int GetFilenames( libvlc_int_t *p_vlc, int i_argc, char *ppsz_argv[] )
         /* TODO: write an internal function of this one, to avoid
          *       unnecessary lookups. */
         /* FIXME: should we convert options to UTF-8 as well ?? */
-        psz_target = FromLocale( ppsz_argv[ i_opt ] );
-        VLC_AddTarget( p_vlc->i_object_id, psz_target,
+
+#ifdef WIN32
+        if( GetVersion() < 0x80000000 )
+        {
+            psz_target = FromWide( wargv[ i_opt ] );
+            VLC_AddTarget( p_vlc->i_object_id, psz_target,
                        (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
                                         NULL ), i_options,
                        PLAYLIST_INSERT, 0 );
-        LocaleFree( psz_target );
+            free( psz_target );
+        }
+        else
+#endif
+        {
+            psz_target = FromLocale( ppsz_argv[ i_opt ] );
+            VLC_AddTarget( p_vlc->i_object_id, psz_target,
+                       (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
+                                        NULL ), i_options,
+                       PLAYLIST_INSERT, 0 );
+            LocaleFree( psz_target );
+        }
     }
 
     return VLC_SUCCESS;
@@ -1116,14 +1138,14 @@ static void Help( libvlc_int_t *p_this, char const *psz_help_name )
 static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
 {
 #define FORMAT_STRING "  %s --%s%s%s%s%s%s%s "
-    /* short option ------'    |     | | | |  | |
-     * option name ------------'     | | | |  | |
-     * <bra -------------------------' | | |  | |
-     * option type or "" --------------' | |  | |
-     * ket> -----------------------------' |  | |
-     * padding spaces ---------------------'  | |
-     * comment -------------------------------' |
-     * comment suffix --------------------------'
+    /* short option ------'    | | | | | | |
+     * option name ------------' | | | | | |
+     * <bra ---------------------' | | | | |
+     * option type or "" ----------' | | | |
+     * ket> -------------------------' | | |
+     * padding spaces -----------------' | |
+     * comment --------------------------' |
+     * comment suffix ---------------------'
      *
      * The purpose of having bra and ket is that we might i18n them as well.
      */
@@ -1560,11 +1582,11 @@ static int ConsoleWidth( void )
 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
                      vlc_value_t old_val, vlc_value_t new_val, void *param)
 {
-    libvlc_int_t *p_vlc = (libvlc_int_t *)p_this;
+    libvlc_int_t *p_libvlc = (libvlc_int_t *)p_this;
 
     if( new_val.i_int >= -1 )
     {
-        p_vlc->p_libvlc_global->i_verbose = __MIN( new_val.i_int, 2 );
+        p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
     }
     return VLC_SUCCESS;
 }