]> git.sesse.net Git - vlc/blobdiff - modules/codec/subtitles/subsdec.c
subsdec: use var_Inherit()
[vlc] / modules / codec / subtitles / subsdec.c
index 80b25626a5926cbc28edd86f07938250d4bba3c2..c49e8f1dae08de4ec555e6295e984095472a93be 100644 (file)
@@ -94,7 +94,11 @@ static const char *const ppsz_encodings[] = {
 };
 
 static const char *const ppsz_encoding_names[] = {
-    N_("Auto"),
+    /* xgettext:
+      The character encoding name in parenthesis corresponds to that used for
+      the GetACP translation. "Windows-1252" applies to Western European
+      languages using the Latin alphabet. */
+    N_("Default (Windows-1252)"),
     N_("Universal (UTF-8)"),
     N_("Universal (UTF-16)"),
     N_("Universal (big endian UTF-16)"),
@@ -275,7 +279,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     /* Second, try configured encoding */
     if (psz_charset == NULL)
     {
-        psz_charset = var_CreateGetNonEmptyString (p_dec, "subsdec-encoding");
+        psz_charset = var_InheritString (p_dec, "subsdec-encoding");
         msg_Dbg (p_dec, "trying configured character encoding: %s",
                  psz_charset ? psz_charset : "not specified");
     }
@@ -283,11 +287,23 @@ static int OpenDecoder( vlc_object_t *p_this )
     /* Third, try "local" encoding with optional UTF-8 autodetection */
     if (psz_charset == NULL)
     {
-        psz_charset = strdup (GetFallbackEncoding ());
+        /* xgettext:
+           The Windows ANSI code page most commonly used for this language.
+           VLC uses this as a guess of the subtitle files character set
+           (if UTF-8 and UTF-16 autodetection fails).
+           Western European languages normally use "CP1252", which is a
+           Microsoft-variant of ISO 8859-1. That suits the Latin alphabet.
+           Other scripts use other code pages.
+
+           This MUST be a valid iconv character set. If unsure, please refer
+           the VideoLAN translators mailing list. */
+        const char *acp = vlc_pgettext("GetACP", "CP1252");
+
+        psz_charset = strdup (acp);
         msg_Dbg (p_dec, "trying default character encoding: %s",
                  psz_charset ? psz_charset : "not specified");
 
-        if (var_CreateGetBool (p_dec, "subsdec-autodetect-utf8"))
+        if (var_InheritBool (p_dec, "subsdec-autodetect-utf8"))
         {
             msg_Dbg (p_dec, "using automatic UTF-8 detection");
             p_sys->b_autodetect_utf8 = true;
@@ -311,10 +327,10 @@ static int OpenDecoder( vlc_object_t *p_this )
     }
     free (psz_charset);
 
-    p_sys->i_align = var_CreateGetInteger( p_dec, "subsdec-align" );
+    p_sys->i_align = var_InheritInteger( p_dec, "subsdec-align" );
 
     if( p_dec->fmt_in.i_codec == VLC_CODEC_SSA
-     && var_CreateGetBool( p_dec, "subsdec-formatted" ) )
+     && var_InheritBool( p_dec, "subsdec-formatted" ) )
     {
         if( p_dec->fmt_in.i_extra > 0 )
             ParseSSAHeader( p_dec );
@@ -423,10 +439,11 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
     }
 
     /* Should be resiliant against bad subtitles */
-    psz_subtitle = strndup( (const char *)p_block->p_buffer,
-                            p_block->i_buffer );
+    psz_subtitle = malloc( p_block->i_buffer + 1 );
     if( psz_subtitle == NULL )
         return NULL;
+    memcpy( psz_subtitle, p_block->p_buffer, p_block->i_buffer );
+    psz_subtitle[p_block->i_buffer] = '\0';
 
     if( p_sys->iconv_handle == (vlc_iconv_t)-1 )
     {
@@ -482,7 +499,7 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
     }
 
     /* Create the subpicture unit */
-    p_spu = decoder_NewSubpicture( p_dec );
+    p_spu = decoder_NewSubpicture( p_dec, NULL );
     if( !p_spu )
     {
         msg_Warn( p_dec, "can't get spu buffer" );
@@ -515,7 +532,7 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
         /* Remove formatting from string */
 
         p_spu->p_region->psz_text = StripTags( psz_subtitle );
-        if( var_CreateGetBool( p_dec, "subsdec-formatted" ) )
+        if( var_InheritBool( p_dec, "subsdec-formatted" ) )
         {
             p_spu->p_region->psz_html = CreateHtmlSubtitle( &p_spu->p_region->i_align, psz_subtitle );
         }
@@ -782,9 +799,13 @@ static char *CreateHtmlSubtitle( int *pi_align, char *psz_subtitle )
                     if( psz_attribs[ k ] == NULL )
                     {
                         /* Jump over unrecognised tag */
-                        int i_len = strcspn( psz_subtitle, "\"" ) + 1;
-
-                        i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1;
+                        int i_len = strcspn( psz_subtitle, "\"" );
+                        if( psz_subtitle[i_len] == '\"' )
+                        {
+                            i_len += 1 + strcspn( &psz_subtitle[i_len + 1], "\"" );
+                            if( psz_subtitle[i_len] == '\"' )
+                                i_len++;
+                        }
                         psz_subtitle += i_len;
                     }
                     while (*psz_subtitle == ' ')