Commit 47b6f761 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Multi-line support for JacoSub.

parent 85ca5599
...@@ -1333,7 +1333,7 @@ static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) ...@@ -1333,7 +1333,7 @@ static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
/* We have been too far: end of the subtitle, begin of next */ /* We have been too far: end of the subtitle, begin of next */
else else
{ {
txt->i_line--; TextPreviousLine( txt );
break; break;
} }
} }
...@@ -1505,10 +1505,10 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) ...@@ -1505,10 +1505,10 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
if( !s ) if( !s )
return VLC_EGENERIC; return VLC_EGENERIC;
psz_text = malloc( strlen( s ) + 1 ); psz_orig = malloc( strlen( s ) + 1 );
if( !psz_text ) if( !psz_orig )
return VLC_ENOMEM; return VLC_ENOMEM;
psz_orig = psz_text; psz_text = psz_orig;
/* Complete time lines */ /* Complete time lines */
if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]", if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]",
...@@ -1520,6 +1520,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) ...@@ -1520,6 +1520,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
p_subtitle->i_stop = ( (int64_t)( h2 *3600 + m2 * 60 + s2 ) + p_subtitle->i_stop = ( (int64_t)( h2 *3600 + m2 * 60 + s2 ) +
(int64_t)( ( f2 + jss_time_shift ) / jss_time_resolution ) ) (int64_t)( ( f2 + jss_time_shift ) / jss_time_resolution ) )
* 1000000; * 1000000;
break;
} }
/* Short time lines */ /* Short time lines */
else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 ) else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 )
...@@ -1528,6 +1529,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) ...@@ -1528,6 +1529,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
( f1 + jss_time_shift ) / jss_time_resolution * 1000000.0 ); ( f1 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
p_subtitle->i_stop = (int64_t)( p_subtitle->i_stop = (int64_t)(
( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 ); ( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
break;
} }
/* General Directive lines */ /* General Directive lines */
/* Only TIME and SHIFT are supported so far */ /* Only TIME and SHIFT are supported so far */
...@@ -1584,123 +1586,136 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) ...@@ -1584,123 +1586,136 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
sscanf( &psz_text[shift], "%d", &jss_time_resolution ); sscanf( &psz_text[shift], "%d", &jss_time_resolution );
break; break;
} }
free( psz_text ); free( psz_orig );
continue; continue;
} }
else else
/* Unkown type line, probably a comment */ /* Unkown type line, probably a comment */
{ {
free( psz_text ); free( psz_orig );
continue; continue;
} }
}
while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
{
const char *s2 = TextGetLine( txt );
/* Skip the blanks */ if( !s2 )
while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++; return VLC_EGENERIC;
/* Parse the directives */ int i_len = strlen( s2 );
if( isalpha( *psz_text ) || *psz_text == '[' ) if( i_len == 0 )
{ break;
while( *psz_text != ' ' )
{ psz_text++ ;};
/* Directives are NOT parsed yet */ int i_old = strlen( psz_text );
/* This has probably a better place in a decoder ? */
/* directive = malloc( strlen( psz_text ) + 1 ); psz_text = realloc( psz_text, i_old + i_len + 1 );
if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/ if( !psz_text )
} return VLC_ENOMEM;
psz_orig = psz_text;
strcat( psz_text, s2 );
}
/* Skip the blanks after directives */ /* Skip the blanks */
while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++; while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
/* Parse the directives */
if( isalpha( *psz_text ) || *psz_text == '[' )
{
while( *psz_text != ' ' )
{ psz_text++ ;};
/* Directives are NOT parsed yet */
/* This has probably a better place in a decoder ? */
/* directive = malloc( strlen( psz_text ) + 1 );
if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/
}
/* Clean all the lines from inline comments and other stuffs */ /* Skip the blanks after directives */
psz_text2 = calloc( strlen( psz_text) + 1, 1 ); while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
psz_orig2 = psz_text2;
for( ; *psz_text != '\0' && *psz_text != '\n' && *psz_text != '\r'; ) /* Clean all the lines from inline comments and other stuffs */
psz_orig2 = calloc( strlen( psz_text) + 1, 1 );
psz_text2 = psz_orig2;
for( ; *psz_text != '\0' && *psz_text != '\n' && *psz_text != '\r'; )
{
switch( *psz_text )
{ {
switch( *psz_text ) case '{':
i_comment++;
break;
case '}':
if( i_comment )
{ {
case '{': i_comment = 0;
i_comment++; if( (*(psz_text + 1 ) ) == ' ' ) psz_text++;
}
break;
case '~':
if( !i_comment )
{
*psz_text2 = ' ';
psz_text2++;
}
break;
case ' ':
case '\t':
if( (*(psz_text + 1 ) ) == ' ' || (*(psz_text + 1 ) ) == '\t' )
break; break;
case '}': if( !i_comment )
if( i_comment ) {
{ *psz_text2 = ' ';
i_comment = 0; psz_text2++;
if( (*(psz_text + 1 ) ) == ' ' ) psz_text++; }
} break;
case '\\':
if( (*(psz_text + 1 ) ) == 'n' )
{
*psz_text2 = '\n';
psz_text++;
psz_text2++;
break; break;
case '~': }
if( !i_comment ) if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
{ ( toupper(*(psz_text + 1 ) ) == 'F' ) )
*psz_text2 = ' '; {
psz_text2++; psz_text++; psz_text++;
}
break; break;
case ' ': }
case '\t': if( (*(psz_text + 1 ) ) == 'B' || (*(psz_text + 1 ) ) == 'b' ||
if( (*(psz_text + 1 ) ) == ' ' || (*(psz_text + 1 ) ) == '\t' ) (*(psz_text + 1 ) ) == 'I' || (*(psz_text + 1 ) ) == 'i' ||
break; (*(psz_text + 1 ) ) == 'U' || (*(psz_text + 1 ) ) == 'u' ||
if( !i_comment ) (*(psz_text + 1 ) ) == 'D' || (*(psz_text + 1 ) ) == 'N' )
{ {
*psz_text2 = ' '; psz_text++;
psz_text2++;
}
break; break;
case '\\':
if( (*(psz_text + 1 ) ) == 'n' )
{
*psz_text2 = '\n';
psz_text++;
psz_text2++;
break;
}
if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
( toupper(*(psz_text + 1 ) ) == 'F' ) )
{
psz_text++; psz_text++;
break;
}
if( (*(psz_text + 1 ) ) == 'B' || (*(psz_text + 1 ) ) == 'b' ||
(*(psz_text + 1 ) ) == 'I' || (*(psz_text + 1 ) ) == 'i' ||
(*(psz_text + 1 ) ) == 'U' || (*(psz_text + 1 ) ) == 'u' ||
(*(psz_text + 1 ) ) == 'D' || (*(psz_text + 1 ) ) == 'N' )
{
psz_text++;
break;
}
if( (*(psz_text + 1 ) ) == '~' || (*(psz_text + 1 ) ) == '{' ||
(*(psz_text + 1 ) ) == '\\' )
psz_text++;
else if( *(psz_text + 1 ) == '\r' || *(psz_text + 1 ) == '\n'
|| *(psz_text + 1 ) == '\0' )
{
char *s2 = TextGetLine( txt );
if( !s2 )
return VLC_EGENERIC;
while ( *s2 == ' ' ) s2++;
/* Here to parse the second line, we should add s2 to
psz_text and go on the for( ) line 1556 in order to
parse the next line.
*/
}
default:
if( !i_comment )
{
*psz_text2 = *psz_text;
psz_text2++;
}
} }
psz_text++; if( (*(psz_text + 1 ) ) == '~' || (*(psz_text + 1 ) ) == '{' ||
(*(psz_text + 1 ) ) == '\\' )
psz_text++;
else if( *(psz_text + 1 ) == '\r' || *(psz_text + 1 ) == '\n' ||
*(psz_text + 1 ) == '\0' )
{
psz_text++;
}
break;
default:
if( !i_comment )
{
*psz_text2 = *psz_text;
psz_text2++;
}
} }
psz_text++;
p_subtitle->psz_text = psz_orig2;
free( psz_orig );
return VLC_SUCCESS;
} }
p_subtitle->psz_text = psz_orig2;
msg_Dbg( p_demux, "%s", p_subtitle->psz_text );
free( psz_orig );
return VLC_SUCCESS;
} }
static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
...@@ -1837,7 +1852,7 @@ static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) ...@@ -1837,7 +1852,7 @@ static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
if( strcasestr( s, "<time" ) || if( strcasestr( s, "<time" ) ||
strcasestr( s, "<clear/") ) strcasestr( s, "<clear/") )
{ {
txt->i_line--; TextPreviousLine( txt );
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment