]> git.sesse.net Git - vlc/blobdiff - src/libvlc.c
Variables fixes
[vlc] / src / libvlc.c
index c677df92959fcf1acb8b1e6b7c35fbdd603d6158..5cb74d8946c4b58399a0dd51852f2d6f45d8ec60 100644 (file)
 #   include <locale.h>
 #endif
 
-#ifdef ENABLE_NLS
-# include <libintl.h> /* bindtextdomain */
-#endif
-
 #ifdef HAVE_DBUS
 /* used for one-instance mode */
 #   include <dbus/dbus.h>
@@ -209,7 +205,6 @@ void vlc_release (gc_object_t *p_gc)
     ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
 static void SetLanguage   ( char const * );
 #endif
-static inline int LoadMessages (void);
 static int  GetFilenames  ( libvlc_int_t *, int, const char *[] );
 static void Help          ( libvlc_int_t *, char const *psz_help_name );
 static void Usage         ( libvlc_int_t *, char const *psz_search );
@@ -313,7 +308,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     /*
      * Support for gettext
      */
-    LoadMessages ();
+    vlc_bindtextdomain (PACKAGE_NAME);
 
     /* Initialize the module bank and load the configuration of the
      * main module. We need to do this at this stage to be able to display
@@ -349,9 +344,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         i_ret = VLC_EEXITSUCCESS;
     }
 
-    /* Check for plugins cache options */
-    bool b_cache_delete = var_InheritBool( p_libvlc, "reset-plugins-cache" );
-
     /* Check for daemon mode */
 #ifndef WIN32
     if( var_InheritBool( p_libvlc, "daemon" ) )
@@ -451,7 +443,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
      * list of configuration options exported by each module and loads their
      * default values.
      */
-    module_LoadPlugins( p_libvlc, b_cache_delete );
+    module_LoadPlugins( p_libvlc );
     if( p_libvlc->b_die )
     {
         b_exit = true;
@@ -813,17 +805,18 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         return VLC_EGENERIC;
     }
     playlist_Activate( p_playlist );
-    vlc_object_attach( p_playlist, p_libvlc );
 
     /* Add service discovery modules */
-    psz_modules = var_CreateGetNonEmptyString( p_playlist, "services-discovery" );
+    psz_modules = var_InheritString( p_libvlc, "services-discovery" );
     if( psz_modules )
     {
         char *p = psz_modules, *m;
+        playlist_t *p_playlist = pl_Hold( p_libvlc );
         while( ( m = strsep( &p, " :," ) ) != NULL )
             playlist_ServicesDiscoveryAdd( p_playlist, m );
+        free( psz_modules );
+        pl_Release (p_playlist);
     }
-    free( psz_modules );
 
 #ifdef ENABLE_VLM
     /* Initialize VLM if vlm-conf is specified */
@@ -933,7 +926,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 #ifdef WIN32
     if( var_InheritBool( p_libvlc, "prefer-system-codecs") )
     {
-        char *psz_codecs = var_CreateGetNonEmptyString( p_playlist, "codec" );
+        char *psz_codecs = var_CreateGetNonEmptyString( p_libvlc, "codec" );
         if( psz_codecs )
         {
             char *psz_morecodecs;
@@ -974,15 +967,15 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     /*
      * Get --open argument
      */
-    psz_val = var_CreateGetNonEmptyString( p_libvlc, "open" );
+    psz_val = var_InheritString( p_libvlc, "open" );
     if ( psz_val != NULL )
     {
         playlist_t *p_playlist = pl_Hold( p_libvlc );
         playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0,
                          -1, 0, NULL, 0, true, pl_Unlocked );
         pl_Release( p_libvlc );
+        free( psz_val );
     }
-    free( psz_val );
 
     return VLC_SUCCESS;
 }
@@ -1199,55 +1192,6 @@ static void SetLanguage ( const char *psz_lang )
 }
 #endif
 
-
-static inline int LoadMessages (void)
-{
-#if defined( ENABLE_NLS ) \
-     && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
-    /* Specify where to find the locales for current domain */
-#if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS )
-    static const char psz_path[] = LOCALEDIR;
-#else
-    char psz_path[1024];
-    char *datadir = config_GetDataDirDefault();
-    int ret;
-
-    if (unlikely(datadir == NULL))
-        return -1;
-    ret = snprintf (psz_path, sizeof (psz_path), "%s" DIR_SEP "locale",
-                    datadir);
-    free (datadir);
-    if (ret >= (int)sizeof (psz_path))
-        return -1;
-#endif
-    if (bindtextdomain (PACKAGE_NAME, psz_path) == NULL)
-    {
-        fprintf (stderr, "Warning: cannot bind text domain "PACKAGE_NAME
-                         " to directory %s\n", psz_path);
-        return -1;
-    }
-
-    /* LibVLC wants all messages in UTF-8.
-     * Unfortunately, we cannot ask UTF-8 for strerror_r(), strsignal_r()
-     * and other functions that are not part of our text domain.
-     */
-    if (bind_textdomain_codeset (PACKAGE_NAME, "UTF-8") == NULL)
-    {
-        fprintf (stderr, "Error: cannot set Unicode encoding for text domain "
-                         PACKAGE_NAME"\n");
-        // Unbinds the text domain to avoid broken encoding
-        bindtextdomain (PACKAGE_NAME, "DOES_NOT_EXIST");
-        return -1;
-    }
-
-    /* LibVLC does NOT set the default textdomain, since it is a library.
-     * This could otherwise break programs using LibVLC (other than VLC).
-     * textdomain (PACKAGE_NAME);
-     */
-#endif
-    return 0;
-}
-
 /*****************************************************************************
  * GetFilenames: parse command line options which are not flags
  *****************************************************************************
@@ -1379,21 +1323,26 @@ static void Help( libvlc_int_t *p_this, char const *psz_help_name )
 #   define CYAN    COL(36)
 #   define WHITE   COL(0)
 #   define GRAY    "\033[0m"
-static void print_help_section( module_config_t *p_item, bool b_color, bool b_description )
+static void
+print_help_section( const module_t *m, const module_config_t *p_item,
+                    bool b_color, bool b_description )
 {
     if( !p_item ) return;
     if( b_color )
     {
-        utf8_fprintf( stdout, RED"   %s:\n"GRAY, _( p_item->psz_text ) );
-        if( b_description && p_item->psz_longtext )
+        utf8_fprintf( stdout, RED"   %s:\n"GRAY,
+                      module_gettext( m, p_item->psz_text ) );
+        if( b_description && p_item->psz_longtext && *p_item->psz_longtext )
             utf8_fprintf( stdout, MAGENTA"   %s\n"GRAY,
-                          _( p_item->psz_longtext ) );
+                          module_gettext( m, p_item->psz_longtext ) );
     }
     else
     {
-        utf8_fprintf( stdout, "   %s:\n", _( p_item->psz_text ) );
-        if( b_description && p_item->psz_longtext )
-            utf8_fprintf( stdout, "   %s\n", _( p_item->psz_longtext ) );
+        utf8_fprintf( stdout, "   %s:\n",
+                      module_gettext( m, p_item->psz_text ) );
+        if( b_description && p_item->psz_longtext && *p_item->psz_longtext )
+            utf8_fprintf( stdout, "   %s\n",
+                          module_gettext(m, p_item->psz_longtext ) );
     }
 }
 
@@ -1533,18 +1482,20 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
         {
             if( b_color )
                 utf8_fprintf( stdout, "\n " GREEN "%s" GRAY " (%s)\n",
-                              _( p_parser->psz_longname ),
+                              module_gettext( p_parser, p_parser->psz_longname ),
                               p_parser->psz_object_name );
             else
-                utf8_fprintf( stdout, "\n %s\n", _( p_parser->psz_longname ) );
+                utf8_fprintf( stdout, "\n %s\n",
+                              module_gettext(p_parser, p_parser->psz_longname ) );
         }
         if( p_parser->psz_help )
         {
             if( b_color )
                 utf8_fprintf( stdout, CYAN" %s\n"GRAY,
-                              _( p_parser->psz_help ) );
+                              module_gettext( p_parser, p_parser->psz_help ) );
             else
-                utf8_fprintf( stdout, " %s\n",  _( p_parser->psz_help ) );
+                utf8_fprintf( stdout, " %s\n",
+                              module_gettext( p_parser, p_parser->psz_help ) );
         }
 
         /* Print module options */
@@ -1578,19 +1529,20 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
                 {
                     if( b_color )
                         utf8_fprintf( stdout, GREEN "\n %s\n" GRAY,
-                                      _( p_item->psz_text ) );
+                                      module_gettext( p_parser, p_item->psz_text ) );
                     else
                         utf8_fprintf( stdout, "\n %s\n",
-                                      _( p_item->psz_text ) );
+                                      module_gettext( p_parser, p_item->psz_text ) );
                 }
-                if( b_description && p_item->psz_longtext )
+                if( b_description && p_item->psz_longtext
+                 && *p_item->psz_longtext )
                 {
                     if( b_color )
                         utf8_fprintf( stdout, CYAN " %s\n" GRAY,
-                                      _( p_item->psz_longtext ) );
+                                      module_gettext( p_parser, p_item->psz_longtext ) );
                     else
                         utf8_fprintf( stdout, " %s\n",
-                                      _( p_item->psz_longtext ) );
+                                      module_gettext( p_parser, p_item->psz_longtext ) );
                 }
                 break;
 
@@ -1610,7 +1562,8 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
             case CONFIG_ITEM_MODULE_LIST_CAT:
             case CONFIG_ITEM_FONT:
             case CONFIG_ITEM_PASSWORD:
-                print_help_section( p_section, b_color, b_description );
+                print_help_section( p_parser, p_section, b_color,
+                                    b_description );
                 p_section = NULL;
                 psz_bra = OPTION_VALUE_SEP "<";
                 psz_type = _("string");
@@ -1631,7 +1584,8 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
                 break;
             case CONFIG_ITEM_INTEGER:
             case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
-                print_help_section( p_section, b_color, b_description );
+                print_help_section( p_parser, p_section, b_color,
+                                    b_description );
                 p_section = NULL;
                 psz_bra = OPTION_VALUE_SEP "<";
                 psz_type = _("integer");
@@ -1654,13 +1608,14 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
                         if( i ) strcat( psz_buffer, ", " );
                         sprintf( psz_buffer + strlen(psz_buffer), "%i (%s)",
                                  p_item->pi_list[i],
-                                 _( p_item->ppsz_list_text[i] ) );
+                                 module_gettext( p_parser, p_item->ppsz_list_text[i] ) );
                     }
                     psz_ket = "}";
                 }
                 break;
             case CONFIG_ITEM_FLOAT:
-                print_help_section( p_section, b_color, b_description );
+                print_help_section( p_parser, p_section, b_color,
+                                    b_description );
                 p_section = NULL;
                 psz_bra = OPTION_VALUE_SEP "<";
                 psz_type = _("float");
@@ -1673,7 +1628,8 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
                 }
                 break;
             case CONFIG_ITEM_BOOL:
-                print_help_section( p_section, b_color, b_description );
+                print_help_section( p_parser, p_section, b_color,
+                                    b_description );
                 p_section = NULL;
                 psz_bra = ""; psz_type = ""; psz_ket = "";
                 if( !b_help_module )
@@ -1734,7 +1690,7 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
             psz_spaces[i] = ' ';
 
             /* We wrap the rest of the output */
-            sprintf( psz_buffer, "%s%s", _( p_item->psz_text ),
+            sprintf( psz_buffer, "%s%s", module_gettext( p_parser, p_item->psz_text ),
                      psz_suf );
             b_description_hack = b_description;
 
@@ -1825,9 +1781,11 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
                 }
             }
 
-            if( b_description_hack && p_item->psz_longtext )
+            if( b_description_hack && p_item->psz_longtext
+             && *p_item->psz_longtext )
             {
-                sprintf( psz_buffer, "%s%s", _( p_item->psz_longtext ),
+                sprintf( psz_buffer, "%s%s",
+                         module_gettext( p_parser, p_item->psz_longtext ),
                          psz_suf );
                 b_description_hack = false;
                 psz_spaces = psz_spaces_longtext;
@@ -1905,11 +1863,11 @@ static void ListModules( libvlc_int_t *p_this, bool b_verbose )
         if( b_color )
             utf8_fprintf( stdout, GREEN"  %-22s "WHITE"%s\n"GRAY,
                           p_parser->psz_object_name,
-                          _( p_parser->psz_longname ) );
+                          module_gettext( p_parser, p_parser->psz_longname ) );
         else
             utf8_fprintf( stdout, "  %-22s %s\n",
                           p_parser->psz_object_name,
-                          _( p_parser->psz_longname ) );
+                          module_gettext( p_parser, p_parser->psz_longname ) );
 
         if( b_verbose )
         {