]> git.sesse.net Git - vlc/blobdiff - src/libvlc-common.c
more info about developers/contributors
[vlc] / src / libvlc-common.c
index b4093bba9773e14bb51c42f137256200759e0bab..9e33d92bebad25638c416af0669084618a528081 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include "control/libvlc_internal.h"
 #include <vlc_input.h>
 
 #include "modules/modules.h"
-#include "config/config.h"
+#include "config/configuration.h"
 
 #include <errno.h>                                                 /* ENOMEM */
 #include <stdio.h>                                              /* sprintf() */
@@ -71,8 +75,6 @@
 #   include <hal/libhal.h>
 #endif
 
-#include "vlc_os_specific.h"
-
 #include <vlc_playlist.h>
 #include <vlc_interface.h>
 
  * The evil global variable. We handle it with care, don't worry.
  *****************************************************************************/
 static libvlc_global_data_t   libvlc_global;
-#define p_libvlc_global (&libvlc_global)
+static libvlc_global_data_t *p_libvlc_global = &libvlc_global;
 static libvlc_int_t *    p_static_vlc = NULL;
 static volatile unsigned int i_instances = 0;
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-#if defined (__APPLE__) || defined (WIN32)
+#if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
+    ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
 static void SetLanguage   ( char const * );
 #endif
 static inline int LoadMessages (void);
@@ -135,12 +138,7 @@ libvlc_global_data_t *vlc_global( void )
  *****************************************************************************/
 libvlc_int_t * vlc_current_object( int i_object )
 {
-    if( i_object )
-    {
-         return vlc_object_get( p_libvlc_global, i_object );
-    }
-
-    return p_static_vlc;
+    return i_object ? vlc_object_get( i_object ) : p_static_vlc;
 }
 
 
@@ -216,6 +214,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
     msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
 
     /* Initialize mutexes */
+    vlc_mutex_init( p_libvlc, &p_libvlc->timer_lock );
     vlc_mutex_init( p_libvlc, &p_libvlc->config_lock );
 #ifdef __APPLE__
     vlc_mutex_init( p_libvlc, &p_libvlc->quicktime_lock );
@@ -327,7 +326,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 #ifndef WIN32
     if( config_GetInt( p_libvlc, "daemon" ) )
     {
-#if HAVE_DAEMON
+#ifdef HAVE_DAEMON
         char *psz_pidfile = NULL;
 
         if( daemon( 1, 0) != 0 )
@@ -421,7 +420,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
         libvlc_global.p_module_bank->b_cache_delete = b_cache_delete;
     }
-    if( psz_language ) free( psz_language );
+    free( psz_language );
 # endif
 #endif
 
@@ -724,7 +723,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     p_libvlc->b_stats = config_GetInt( p_libvlc, "stats" ) > 0;
     p_libvlc->i_timers = 0;
     p_libvlc->pp_timers = NULL;
-    vlc_mutex_init( p_libvlc, &p_libvlc->timer_lock );
 
     /*
      * Initialize hotkey handling
@@ -754,7 +752,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         /* Add service discovery modules */
         playlist_ServicesDiscoveryAdd( p_playlist, psz_modules );
     }
-    if( psz_modules ) free( psz_modules );
+    free( psz_modules );
 
     /*
      * Load background interfaces
@@ -858,12 +856,12 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
             if( psz_morecodecs )
             {
                 config_PutPsz( p_libvlc, "codec", psz_morecodecs);
-                free(psz_morecodecs);
+                free( psz_morecodecs );
             }
         }
         else
             config_PutPsz( p_libvlc, "codec", "dmo,quicktime");
-        free(psz_codecs);
+        free( psz_codecs );
     }
 #endif
 
@@ -898,7 +896,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         VLC_AddTarget( p_libvlc->i_object_id, val.psz_string, NULL, 0,
                        PLAYLIST_INSERT, 0 );
     }
-    if ( val.psz_string != NULL ) free( val.psz_string );
+    free( val.psz_string );
 
     return VLC_SUCCESS;
 }
@@ -993,7 +991,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
                         psz_pidfile );
             }
         }
-        free ( psz_pidfile );
+        free( psz_pidfile );
     }
 #endif
 
@@ -1034,7 +1032,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
     vlc_mutex_destroy( &p_libvlc->timer_lock );
 
     if( b_release ) vlc_object_release( p_libvlc );
-    vlc_object_destroy( p_libvlc );
+    vlc_object_release( p_libvlc );
     p_libvlc = NULL;
 
     /* Stop thread system: last one out please shut the door!
@@ -1074,7 +1072,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc,
          * We prefer the dummy interface if none is specified. */
         char *psz_interface = config_GetPsz( p_libvlc, "intf" );
         if( !psz_interface || !*psz_interface ) psz_module = "dummy";
-        if( psz_interface ) free( psz_interface );
+        free( psz_interface );
     }
 #endif
 
@@ -1118,7 +1116,8 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc,
     return VLC_SUCCESS;
 };
 
-#if defined (__APPLE__) || defined (WIN32)
+#if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
+    ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
 /*****************************************************************************
  * SetLanguage: set the interface language.
  *****************************************************************************
@@ -1318,6 +1317,9 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
     psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
     memset( psz_spaces_longtext, ' ', LINE_START+2 );
     psz_spaces_longtext[LINE_START+2] = '\0';
+#ifdef WIN32
+    b_color = VLC_FALSE; // don't put color control codes in a .txt file
+#endif
 
     if( b_color )
     {
@@ -1692,9 +1694,15 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
         }
     }
 
-    if( b_has_advanced )
-        utf8_fprintf( stdout, "\n" WHITE "%s" GRAY " %s\n", _( "Note:" ),
-        _( "add --advanced to your command line to see advanced options." ) );
+    if( b_has_advanced ) 
+    {
+        if( b_color )
+            utf8_fprintf( stdout, "\n" WHITE "%s" GRAY " %s\n", _( "Note:" ),
+           _( "add --advanced to your command line to see advanced options."));
+        else
+            utf8_fprintf( stdout, "\n %s %s\n", _( "Note:" ),
+           _( "add --advanced to your command line to see advanced options."));
+    }
 
     /* Release the module list */
     vlc_list_release( p_list );
@@ -1802,7 +1810,7 @@ static void Version( void )
              VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
     utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
     if( strcmp( VLC_Changeset(), "exported" ) )
-        utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"),
+        utf8_fprintf( stdout, _("Based upon Git commit [%s]\n"),
                  VLC_Changeset() );
     utf8_fprintf( stdout, LICENSE_MSG );
 
@@ -1825,6 +1833,11 @@ static void ShowConsole( vlc_bool_t b_dofile )
     if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
 
     AllocConsole();
+    /* Use the ANSI code page (e.g. Windows-1252) as expected by the LibVLC
+     * Unicode/locale subsystem. By default, we have the obsolecent OEM code
+     * page (e.g. CP437 or CP850). */
+    SetConsoleOutputCP (GetACP ());
+    SetConsoleTitle ("VLC media player version "PACKAGE_VERSION);
 
     freopen( "CONOUT$", "w", stderr );
     freopen( "CONIN$", "r", stdin );
@@ -1869,34 +1882,21 @@ static void PauseConsole( void )
  *****************************************************************************/
 static int ConsoleWidth( void )
 {
-    int i_width = 80;
+    unsigned i_width = 80;
 
 #ifndef WIN32
-    char buf[20];
-    char *psz_parser = NULL;
-    FILE *file = NULL;
-    int i_ret;
-
-    file = popen( "stty size 2>/dev/null", "r" );
-    if( file )
+    FILE *file = popen( "stty size 2>/dev/null", "r" );
+    if (file != NULL)
     {
-        i_ret = fread( buf, 1, 20, file );
-        if( i_ret > 0 )
-        {
-            buf[19] = '\0';
-            psz_parser = strchr( buf, ' ' );
-            if( psz_parser )
-            {
-                i_ret = atoi( psz_parser + 1 );
-                if( i_ret >= 80 )
-                {
-                    i_width = i_ret;
-                }
-            }
-        }
-
+        if (fscanf (file, "%*u %u", &i_width) <= 0)
+            i_width = 80;
         pclose( file );
     }
+#else
+    CONSOLE_SCREEN_BUFFER_INFO buf;
+
+    if (GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &buf))
+        i_width = buf.dwSize.X;
 #endif
 
     return i_width;