Commit 393b3425 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Formatting cleaning

parent cffe2dbb
...@@ -580,212 +580,215 @@ static char *CreateHtmlSubtitle( char *psz_subtitle ) ...@@ -580,212 +580,215 @@ static char *CreateHtmlSubtitle( char *psz_subtitle )
psz_tag[ 0 ] = '\0'; 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, "<text>" ); strcpy( psz_html, "<text>" );
psz_html += 6; psz_html += 6;
while( *psz_subtitle ) while( *psz_subtitle )
{
if( *psz_subtitle == '\n' )
{
strcpy( psz_html, "<br/>" );
psz_html += 5;
psz_subtitle++;
}
else if( *psz_subtitle == '<' )
{ {
if( *psz_subtitle == '\n' ) if( !strncasecmp( psz_subtitle, "<br/>", 5 ))
{ {
strcpy( psz_html, "<br/>" ); strcpy( psz_html, "<br/>" );
psz_html += 5; psz_html += 5;
psz_subtitle++; psz_subtitle += 5;
} }
else if( *psz_subtitle == '<' ) else if( !strncasecmp( psz_subtitle, "<b>", 3 ) )
{ {
if( !strncasecmp( psz_subtitle, "<br/>", 5 )) strcpy( psz_html, "<b>" );
{ strcat( psz_tag, "b" );
strcpy( psz_html, "<br/>" ); psz_html += 3;
psz_html += 5; psz_subtitle += 3;
psz_subtitle += 5; }
} else if( !strncasecmp( psz_subtitle, "<i>", 3 ) )
else if( !strncasecmp( psz_subtitle, "<b>", 3 ) ) {
{ strcpy( psz_html, "<i>" );
strcpy( psz_html, "<b>" ); strcat( psz_tag, "i" );
strcat( psz_tag, "b" ); psz_html += 3;
psz_html += 3; psz_subtitle += 3;
psz_subtitle += 3; }
} else if( !strncasecmp( psz_subtitle, "<u>", 3 ) )
else if( !strncasecmp( psz_subtitle, "<i>", 3 ) ) {
{ strcpy( psz_html, "<u>" );
strcpy( psz_html, "<i>" ); strcat( psz_tag, "u" );
strcat( psz_tag, "i" ); psz_html += 3;
psz_html += 3; psz_subtitle += 3;
psz_subtitle += 3; }
} else if( !strncasecmp( psz_subtitle, "<font ", 6 ))
else if( !strncasecmp( psz_subtitle, "<u>", 3 ) ) {
{ const char *psz_attribs[] = { "face=\"", "family=\"", "size=\"",
strcpy( psz_html, "<u>" ); "color=\"", "outline-color=\"", "shadow-color=\"",
strcat( psz_tag, "u" ); "outline-level=\"", "shadow-level=\"", "back-color=\"",
psz_html += 3; "alpha=\"", NULL };
psz_subtitle += 3;
}
else if( !strncasecmp( psz_subtitle, "<font ", 6 ))
{
const char *psz_attribs[] = { "face=\"", "family=\"", "size=\"",
"color=\"", "outline-color=\"", "shadow-color=\"",
"outline-level=\"", "shadow-level=\"", "back-color=\"",
"alpha=\"", NULL };
strcpy( psz_html, "<font " );
strcat( psz_tag, "f" );
psz_html += 6;
psz_subtitle += 6;
while( *psz_subtitle != '>' ) strcpy( psz_html, "<font " );
{ strcat( psz_tag, "f" );
int k; psz_html += 6;
psz_subtitle += 6;
for( k=0; psz_attribs[ k ]; k++ ) while( *psz_subtitle != '>' )
{ {
int i_len = strlen( psz_attribs[ k ] ); int k;
if( !strncasecmp( psz_subtitle, psz_attribs[ k ], i_len )) for( k=0; psz_attribs[ k ]; k++ )
{ {
i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1; int i_len = strlen( psz_attribs[ k ] );
strncpy( psz_html, psz_subtitle, i_len ); if( !strncasecmp( psz_subtitle, psz_attribs[k], i_len ))
psz_html += i_len;
psz_subtitle += i_len;
break;
}
}
if( psz_attribs[ k ] == NULL )
{ {
/* Jump over unrecognised tag */
int i_len = strcspn( psz_subtitle, "\"" ) + 1;
i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1; i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1;
strncpy( psz_html, psz_subtitle, i_len );
psz_html += i_len;
psz_subtitle += i_len; psz_subtitle += i_len;
break;
} }
while (*psz_subtitle == ' ')
*psz_html++ = *psz_subtitle++;
} }
*psz_html++ = *psz_subtitle++; if( psz_attribs[ k ] == NULL )
}
else if( !strncmp( psz_subtitle, "</", 2 ))
{
bool b_match = false;
int i_len = strlen( psz_tag ) - 1;
char *psz_lastTag = NULL;
if( i_len >= 0 )
{ {
psz_lastTag = psz_tag + i_len; /* Jump over unrecognised tag */
i_len = 0; int i_len = strcspn( psz_subtitle, "\"" ) + 1;
switch( *psz_lastTag ) i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1;
{ psz_subtitle += i_len;
case 'b':
b_match = !strncasecmp( psz_subtitle, "</b>", 4 );
i_len = 4;
break;
case 'i':
b_match = !strncasecmp( psz_subtitle, "</i>", 4 );
i_len = 4;
break;
case 'u':
b_match = !strncasecmp( psz_subtitle, "</u>", 4 );
i_len = 4;
break;
case 'f':
b_match = !strncasecmp( psz_subtitle, "</font>", 7 );
i_len = 7;
break;
}
} }
if( ! b_match ) while (*psz_subtitle == ' ')
*psz_html++ = *psz_subtitle++;
}
*psz_html++ = *psz_subtitle++;
}
else if( !strncmp( psz_subtitle, "</", 2 ))
{
bool b_match = false;
int i_len = strlen( psz_tag ) - 1;
char *psz_lastTag = NULL;
if( i_len >= 0 )
{
psz_lastTag = psz_tag + i_len;
i_len = 0;
switch( *psz_lastTag )
{ {
/* Not well formed -- kill everything */ case 'b':
free( psz_html_start ); b_match = !strncasecmp( psz_subtitle, "</b>", 4 );
psz_html_start = NULL; i_len = 4;
break;
case 'i':
b_match = !strncasecmp( psz_subtitle, "</i>", 4 );
i_len = 4;
break;
case 'u':
b_match = !strncasecmp( psz_subtitle, "</u>", 4 );
i_len = 4;
break;
case 'f':
b_match = !strncasecmp( psz_subtitle, "</font>", 7 );
i_len = 7;
break; 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, "&lt;", 4 )) psz_subtitle += strcspn( psz_subtitle, ">" );
{ }
strcpy( psz_html, "&lt;" ); }
psz_html += 4; else if( *psz_subtitle == '&' )
psz_subtitle += 4; {
} if( !strncasecmp( psz_subtitle, "&lt;", 4 ))
else if( !strncasecmp( psz_subtitle, "&gt;", 4 )) {
{ strcpy( psz_html, "&lt;" );
strcpy( psz_html, "&gt;" ); psz_html += 4;
psz_html += 4; psz_subtitle += 4;
psz_subtitle += 4; }
} else if( !strncasecmp( psz_subtitle, "&gt;", 4 ))
else if( !strncasecmp( psz_subtitle, "&amp;", 5 )) {
{ strcpy( psz_html, "&gt;" );
strcpy( psz_html, "&amp;" ); psz_html += 4;
psz_html += 5; psz_subtitle += 4;
psz_subtitle += 5; }
} else if( !strncasecmp( psz_subtitle, "&amp;", 5 ))
else {
{ strcpy( psz_html, "&amp;" );
strcpy( psz_html, "&amp;" ); psz_html += 5;
psz_html += 5; psz_subtitle += 5;
psz_subtitle++;
}
} }
else else
{ {
*psz_html = *psz_subtitle; strcpy( psz_html, "&amp;" );
if( psz_html > psz_html_start ) psz_html += 5;
{
/* 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++; 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; /* Check for double whitespace */
if((( *psz_html == ' ' ) ||
i_buf_size += 100; ( *psz_html == '\t' )) &&
psz_html_start = realloc( psz_html_start, i_buf_size ); (( *(psz_html-1) == ' ' ) ||
psz_html = psz_html_start + i_len; ( *(psz_html-1) == '\t' )))
*psz_html = '\0'; {
strcpy( psz_html, NO_BREAKING_SPACE );
psz_html += strlen( NO_BREAKING_SPACE ) - 1;
}
} }
psz_html++;
psz_subtitle++;
} }
strcpy( psz_html, "</text>" );
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 */ int i_len = psz_html - psz_html_start;
free( psz_html_start );
psz_html_start = NULL; i_buf_size += 100;
} psz_html_start = realloc( psz_html_start, i_buf_size );
else if( psz_html_start ) psz_html = psz_html_start + i_len;
{ *psz_html = '\0';
/* Shrink the memory requirements */
psz_html_start = realloc( psz_html_start, psz_html - psz_html_start + 1 );
} }
} }
strcpy( psz_html, "</text>" );
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 ); free( psz_tag );
return psz_html_start; return psz_html_start;
} }
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