From 393b34257f6abcde79f2972e3898674da9a8a481 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Kempf Date: Mon, 19 May 2008 13:34:34 -0700 Subject: [PATCH] Formatting cleaning --- modules/codec/subtitles/subsdec.c | 333 +++++++++++++++--------------- 1 file changed, 168 insertions(+), 165 deletions(-) diff --git a/modules/codec/subtitles/subsdec.c b/modules/codec/subtitles/subsdec.c index 079a563563..40cb747398 100644 --- a/modules/codec/subtitles/subsdec.c +++ b/modules/codec/subtitles/subsdec.c @@ -580,212 +580,215 @@ static char *CreateHtmlSubtitle( char *psz_subtitle ) psz_tag[ 0 ] = '\0'; - if( psz_html_start != NULL ) + if( psz_html_start == NULL ) { - char *psz_html = psz_html_start; + free( psz_tag ); + return NULL; + } + + char *psz_html = psz_html_start; - strcpy( psz_html, "" ); - psz_html += 6; + strcpy( psz_html, "" ); + psz_html += 6; - while( *psz_subtitle ) + while( *psz_subtitle ) + { + if( *psz_subtitle == '\n' ) + { + strcpy( psz_html, "
" ); + psz_html += 5; + psz_subtitle++; + } + else if( *psz_subtitle == '<' ) { - if( *psz_subtitle == '\n' ) + if( !strncasecmp( psz_subtitle, "
", 5 )) { strcpy( psz_html, "
" ); psz_html += 5; - psz_subtitle++; + psz_subtitle += 5; } - else if( *psz_subtitle == '<' ) + else if( !strncasecmp( psz_subtitle, "", 3 ) ) { - if( !strncasecmp( psz_subtitle, "
", 5 )) - { - strcpy( psz_html, "
" ); - psz_html += 5; - psz_subtitle += 5; - } - else if( !strncasecmp( psz_subtitle, "", 3 ) ) - { - strcpy( psz_html, "" ); - strcat( psz_tag, "b" ); - psz_html += 3; - psz_subtitle += 3; - } - else if( !strncasecmp( psz_subtitle, "", 3 ) ) - { - strcpy( psz_html, "" ); - strcat( psz_tag, "i" ); - psz_html += 3; - psz_subtitle += 3; - } - else if( !strncasecmp( psz_subtitle, "", 3 ) ) - { - strcpy( psz_html, "" ); - strcat( psz_tag, "u" ); - psz_html += 3; - psz_subtitle += 3; - } - else if( !strncasecmp( psz_subtitle, "" ); + strcat( psz_tag, "b" ); + psz_html += 3; + psz_subtitle += 3; + } + else if( !strncasecmp( psz_subtitle, "", 3 ) ) + { + strcpy( psz_html, "" ); + strcat( psz_tag, "i" ); + psz_html += 3; + psz_subtitle += 3; + } + else if( !strncasecmp( psz_subtitle, "", 3 ) ) + { + strcpy( psz_html, "" ); + strcat( psz_tag, "u" ); + psz_html += 3; + psz_subtitle += 3; + } + else if( !strncasecmp( psz_subtitle, "= 0 ) + if( psz_attribs[ k ] == NULL ) { - psz_lastTag = psz_tag + i_len; - i_len = 0; + /* Jump over unrecognised tag */ + int i_len = strcspn( psz_subtitle, "\"" ) + 1; - switch( *psz_lastTag ) - { - case 'b': - b_match = !strncasecmp( psz_subtitle, "", 4 ); - i_len = 4; - break; - case 'i': - b_match = !strncasecmp( psz_subtitle, "", 4 ); - i_len = 4; - break; - case 'u': - b_match = !strncasecmp( psz_subtitle, "", 4 ); - i_len = 4; - break; - case 'f': - b_match = !strncasecmp( psz_subtitle, "", 7 ); - i_len = 7; - break; - } + i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1; + psz_subtitle += i_len; } - if( ! b_match ) + while (*psz_subtitle == ' ') + *psz_html++ = *psz_subtitle++; + } + *psz_html++ = *psz_subtitle++; + } + else if( !strncmp( psz_subtitle, "= 0 ) + { + psz_lastTag = psz_tag + i_len; + i_len = 0; + + switch( *psz_lastTag ) { - /* Not well formed -- kill everything */ - free( psz_html_start ); - psz_html_start = NULL; + case 'b': + b_match = !strncasecmp( psz_subtitle, "", 4 ); + i_len = 4; + break; + case 'i': + b_match = !strncasecmp( psz_subtitle, "", 4 ); + i_len = 4; + break; + case 'u': + b_match = !strncasecmp( psz_subtitle, "", 4 ); + i_len = 4; + break; + case 'f': + b_match = !strncasecmp( psz_subtitle, "", 7 ); + i_len = 7; break; } - *psz_lastTag = '\0'; - strncpy( psz_html, psz_subtitle, i_len ); - psz_html += i_len; - psz_subtitle += i_len; } - else + if( ! b_match ) { - psz_subtitle += strcspn( psz_subtitle, ">" ); + /* Not well formed -- kill everything */ + free( psz_html_start ); + psz_html_start = NULL; + break; } + *psz_lastTag = '\0'; + strncpy( psz_html, psz_subtitle, i_len ); + psz_html += i_len; + psz_subtitle += i_len; } - else if( *psz_subtitle == '&' ) + else { - if( !strncasecmp( psz_subtitle, "<", 4 )) - { - strcpy( psz_html, "<" ); - psz_html += 4; - psz_subtitle += 4; - } - else if( !strncasecmp( psz_subtitle, ">", 4 )) - { - strcpy( psz_html, ">" ); - psz_html += 4; - psz_subtitle += 4; - } - else if( !strncasecmp( psz_subtitle, "&", 5 )) - { - strcpy( psz_html, "&" ); - psz_html += 5; - psz_subtitle += 5; - } - else - { - strcpy( psz_html, "&" ); - psz_html += 5; - psz_subtitle++; - } + psz_subtitle += strcspn( psz_subtitle, ">" ); + } + } + else if( *psz_subtitle == '&' ) + { + if( !strncasecmp( psz_subtitle, "<", 4 )) + { + strcpy( psz_html, "<" ); + psz_html += 4; + psz_subtitle += 4; + } + else if( !strncasecmp( psz_subtitle, ">", 4 )) + { + strcpy( psz_html, ">" ); + psz_html += 4; + psz_subtitle += 4; + } + else if( !strncasecmp( psz_subtitle, "&", 5 )) + { + strcpy( psz_html, "&" ); + psz_html += 5; + psz_subtitle += 5; } else { - *psz_html = *psz_subtitle; - if( psz_html > psz_html_start ) - { - /* Check for double whitespace */ - if((( *psz_html == ' ' ) || - ( *psz_html == '\t' )) && - (( *(psz_html-1) == ' ' ) || - ( *(psz_html-1) == '\t' ))) - { - strcpy( psz_html, NO_BREAKING_SPACE ); - psz_html += strlen( NO_BREAKING_SPACE ) - 1; - } - } - psz_html++; + strcpy( psz_html, "&" ); + psz_html += 5; psz_subtitle++; } - - if( ( size_t )( psz_html - psz_html_start ) > i_buf_size - 10 ) + } + else + { + *psz_html = *psz_subtitle; + if( psz_html > psz_html_start ) { - int i_len = psz_html - psz_html_start; - - i_buf_size += 100; - psz_html_start = realloc( psz_html_start, i_buf_size ); - psz_html = psz_html_start + i_len; - *psz_html = '\0'; + /* Check for double whitespace */ + if((( *psz_html == ' ' ) || + ( *psz_html == '\t' )) && + (( *(psz_html-1) == ' ' ) || + ( *(psz_html-1) == '\t' ))) + { + strcpy( psz_html, NO_BREAKING_SPACE ); + psz_html += strlen( NO_BREAKING_SPACE ) - 1; + } } + psz_html++; + psz_subtitle++; } - strcpy( psz_html, "
" ); - psz_html += 7; - if( psz_tag[ 0 ] != '\0' ) + if( ( size_t )( psz_html - psz_html_start ) > i_buf_size - 10 ) { - /* Not well formed -- kill everything */ - free( psz_html_start ); - psz_html_start = NULL; - } - else if( psz_html_start ) - { - /* Shrink the memory requirements */ - psz_html_start = realloc( psz_html_start, psz_html - psz_html_start + 1 ); + int i_len = psz_html - psz_html_start; + + i_buf_size += 100; + psz_html_start = realloc( psz_html_start, i_buf_size ); + psz_html = psz_html_start + i_len; + *psz_html = '\0'; } } + strcpy( psz_html, "
" ); + psz_html += 7; + + if( psz_tag[ 0 ] != '\0' ) + { + /* Not well formed -- kill everything */ + free( psz_html_start ); + psz_html_start = NULL; + } + else if( psz_html_start ) + { + /* Shrink the memory requirements */ + psz_html_start = realloc( psz_html_start, psz_html - psz_html_start + 1 ); + } free( psz_tag ); return psz_html_start; } -- 2.39.2