Changeset 393b34257f6abcde79f2972e3898674da9a8a481

Show
Ignore:
Timestamp:
20/05/08 14:05:27 (7 months ago)
Author:
Jean-Baptiste Kempf <jb@ambre.(none)>
git-committer:
Jean-Baptiste Kempf <jb@ambre.(none)> 1211285127 -0700
git-parent:

[cffe2dbbf5082a82944aa2ca7aecfe8124780dd5]

git-author:
Jean-Baptiste Kempf <jb@ambre.(none)> 1211229274 -0700
Message:

Formatting cleaning

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/codec/subtitles/subsdec.c

    r27d483e r393b342  
    581581    psz_tag[ 0 ] = '\0'; 
    582582 
    583     if( psz_html_start != NULL ) 
    584     { 
    585         char *psz_html = psz_html_start; 
    586  
    587         strcpy( psz_html, "<text>" ); 
    588         psz_html += 6; 
    589  
    590         while( *psz_subtitle ) 
    591         { 
    592             if( *psz_subtitle == '\n' ) 
     583    if( psz_html_start == NULL ) 
     584    { 
     585        free( psz_tag ); 
     586        return NULL; 
     587    } 
     588     
     589    char *psz_html = psz_html_start; 
     590 
     591    strcpy( psz_html, "<text>" ); 
     592    psz_html += 6; 
     593 
     594    while( *psz_subtitle ) 
     595    { 
     596        if( *psz_subtitle == '\n' ) 
     597        { 
     598            strcpy( psz_html, "<br/>" ); 
     599            psz_html += 5; 
     600            psz_subtitle++; 
     601        } 
     602        else if( *psz_subtitle == '<' ) 
     603        { 
     604            if( !strncasecmp( psz_subtitle, "<br/>", 5 )) 
    593605            { 
    594606                strcpy( psz_html, "<br/>" ); 
    595607                psz_html += 5; 
    596                 psz_subtitle++; 
    597             } 
    598             else if( *psz_subtitle == '<' ) 
    599             { 
    600                 if( !strncasecmp( psz_subtitle, "<br/>", 5 )) 
     608                psz_subtitle += 5; 
     609            } 
     610            else if( !strncasecmp( psz_subtitle, "<b>", 3 ) ) 
     611            { 
     612                strcpy( psz_html, "<b>" ); 
     613                strcat( psz_tag, "b" ); 
     614                psz_html += 3; 
     615                psz_subtitle += 3; 
     616            } 
     617            else if( !strncasecmp( psz_subtitle, "<i>", 3 ) ) 
     618            { 
     619                strcpy( psz_html, "<i>" ); 
     620                strcat( psz_tag, "i" ); 
     621                psz_html += 3; 
     622                psz_subtitle += 3; 
     623            } 
     624            else if( !strncasecmp( psz_subtitle, "<u>", 3 ) ) 
     625            { 
     626                strcpy( psz_html, "<u>" ); 
     627                strcat( psz_tag, "u" ); 
     628                psz_html += 3; 
     629                psz_subtitle += 3; 
     630            } 
     631            else if( !strncasecmp( psz_subtitle, "<font ", 6 )) 
     632            { 
     633                const char *psz_attribs[] = { "face=\"", "family=\"", "size=\"", 
     634                        "color=\"", "outline-color=\"", "shadow-color=\"", 
     635                        "outline-level=\"", "shadow-level=\"", "back-color=\"", 
     636                        "alpha=\"", NULL }; 
     637 
     638                strcpy( psz_html, "<font " ); 
     639                strcat( psz_tag, "f" ); 
     640                psz_html += 6; 
     641                psz_subtitle += 6; 
     642 
     643                while( *psz_subtitle != '>' ) 
    601644                { 
    602                     strcpy( psz_html, "<br/>" ); 
    603                     psz_html += 5; 
    604                     psz_subtitle += 5; 
    605                 } 
    606                 else if( !strncasecmp( psz_subtitle, "<b>", 3 ) ) 
    607                 { 
    608                     strcpy( psz_html, "<b>" ); 
    609                     strcat( psz_tag, "b" ); 
    610                     psz_html += 3; 
    611                     psz_subtitle += 3; 
    612                 } 
    613                 else if( !strncasecmp( psz_subtitle, "<i>", 3 ) ) 
    614                 { 
    615                     strcpy( psz_html, "<i>" ); 
    616                     strcat( psz_tag, "i" ); 
    617                     psz_html += 3; 
    618                     psz_subtitle += 3; 
    619                 } 
    620                 else if( !strncasecmp( psz_subtitle, "<u>", 3 ) ) 
    621                 { 
    622                     strcpy( psz_html, "<u>" ); 
    623                     strcat( psz_tag, "u" ); 
    624                     psz_html += 3; 
    625                     psz_subtitle += 3; 
    626                 } 
    627                 else if( !strncasecmp( psz_subtitle, "<font ", 6 )) 
    628                 { 
    629                     const char *psz_attribs[] = { "face=\"", "family=\"", "size=\"", 
    630                             "color=\"", "outline-color=\"", "shadow-color=\"", 
    631                             "outline-level=\"", "shadow-level=\"", "back-color=\"", 
    632                             "alpha=\"", NULL }; 
    633  
    634                     strcpy( psz_html, "<font " ); 
    635                     strcat( psz_tag, "f" ); 
    636                     psz_html += 6; 
    637                     psz_subtitle += 6; 
    638  
    639                     while( *psz_subtitle != '>' ) 
     645                    int  k; 
     646 
     647                    for( k=0; psz_attribs[ k ]; k++ ) 
    640648                    { 
    641                         int k
    642  
    643                         for( k=0; psz_attribs[ k ]; k++
     649                        int i_len = strlen( psz_attribs[ k ] )
     650 
     651                        if( !strncasecmp( psz_subtitle, psz_attribs[k], i_len )
    644652                        { 
    645                             int i_len = strlen( psz_attribs[ k ] ); 
    646  
    647                             if( !strncasecmp( psz_subtitle, psz_attribs[ k ], i_len )) 
    648                             { 
    649                                 i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1; 
    650  
    651                                 strncpy( psz_html, psz_subtitle, i_len ); 
    652                                 psz_html += i_len; 
    653                                 psz_subtitle += i_len; 
    654                                 break; 
    655                             } 
    656                         } 
    657                         if( psz_attribs[ k ] == NULL ) 
    658                         { 
    659                             /* Jump over unrecognised tag */ 
    660                             int i_len = strcspn( psz_subtitle, "\"" ) + 1; 
    661  
    662653                            i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1; 
     654 
     655                            strncpy( psz_html, psz_subtitle, i_len ); 
     656                            psz_html += i_len; 
    663657                            psz_subtitle += i_len; 
    664                         } 
    665                         while (*psz_subtitle == ' ') 
    666                             *psz_html++ = *psz_subtitle++; 
    667                     } 
    668                     *psz_html++ = *psz_subtitle++; 
    669                 } 
    670                 else if( !strncmp( psz_subtitle, "</", 2 )) 
    671                 { 
    672                     bool  b_match     = false; 
    673                     int         i_len       = strlen( psz_tag ) - 1; 
    674                     char       *psz_lastTag = NULL; 
    675  
    676                     if( i_len >= 0 ) 
    677                     { 
    678                         psz_lastTag = psz_tag + i_len; 
    679                         i_len = 0; 
    680  
    681                         switch( *psz_lastTag ) 
    682                         { 
    683                             case 'b': 
    684                                 b_match = !strncasecmp( psz_subtitle, "</b>", 4 ); 
    685                                 i_len   = 4; 
    686                                 break; 
    687                             case 'i': 
    688                                 b_match = !strncasecmp( psz_subtitle, "</i>", 4 ); 
    689                                 i_len   = 4; 
    690                                 break; 
    691                             case 'u': 
    692                                 b_match = !strncasecmp( psz_subtitle, "</u>", 4 ); 
    693                                 i_len   = 4; 
    694                                 break; 
    695                             case 'f': 
    696                                 b_match = !strncasecmp( psz_subtitle, "</font>", 7 ); 
    697                                 i_len   = 7; 
    698                                 break; 
     658                            break; 
    699659                        } 
    700660                    } 
    701                     if( ! b_match
     661                    if( psz_attribs[ k ] == NULL
    702662                    { 
    703                         /* Not well formed -- kill everything */ 
    704                         free( psz_html_start ); 
    705                         psz_html_start = NULL; 
     663                        /* Jump over unrecognised tag */ 
     664                        int i_len = strcspn( psz_subtitle, "\"" ) + 1; 
     665 
     666                        i_len += strcspn( psz_subtitle + i_len, "\"" ) + 1; 
     667                        psz_subtitle += i_len; 
     668                    } 
     669                    while (*psz_subtitle == ' ') 
     670                        *psz_html++ = *psz_subtitle++; 
     671                } 
     672                *psz_html++ = *psz_subtitle++; 
     673            } 
     674            else if( !strncmp( psz_subtitle, "</", 2 )) 
     675            { 
     676                bool   b_match     = false; 
     677                int    i_len       = strlen( psz_tag ) - 1; 
     678                char  *psz_lastTag = NULL; 
     679 
     680                if( i_len >= 0 ) 
     681                { 
     682                    psz_lastTag = psz_tag + i_len; 
     683                    i_len = 0; 
     684 
     685                    switch( *psz_lastTag ) 
     686                    { 
     687                    case 'b': 
     688                        b_match = !strncasecmp( psz_subtitle, "</b>", 4 ); 
     689                        i_len   = 4; 
     690                        break; 
     691                    case 'i': 
     692                        b_match = !strncasecmp( psz_subtitle, "</i>", 4 ); 
     693                        i_len   = 4; 
     694                        break; 
     695                    case 'u': 
     696                        b_match = !strncasecmp( psz_subtitle, "</u>", 4 ); 
     697                        i_len   = 4; 
     698                        break; 
     699                    case 'f': 
     700                        b_match = !strncasecmp( psz_subtitle, "</font>", 7 ); 
     701                        i_len   = 7; 
    706702                        break; 
    707703                    } 
    708                     *psz_lastTag = '\0'; 
    709                     strncpy( psz_html, psz_subtitle, i_len ); 
    710                     psz_html += i_len; 
    711                     psz_subtitle += i_len; 
    712704                } 
    713                 else 
     705                if( ! b_match ) 
    714706                { 
    715                     psz_subtitle += strcspn( psz_subtitle, ">" ); 
     707                    /* Not well formed -- kill everything */ 
     708                    free( psz_html_start ); 
     709                    psz_html_start = NULL; 
     710                    break; 
    716711                } 
    717             } 
    718             else if( *psz_subtitle == '&' ) 
    719             { 
    720                 if( !strncasecmp( psz_subtitle, "&lt;", 4 )) 
     712                *psz_lastTag = '\0'; 
     713                strncpy( psz_html, psz_subtitle, i_len ); 
     714                psz_html += i_len; 
     715                psz_subtitle += i_len; 
     716            } 
     717            else 
     718            { 
     719                psz_subtitle += strcspn( psz_subtitle, ">" ); 
     720            } 
     721        } 
     722        else if( *psz_subtitle == '&' ) 
     723        { 
     724            if( !strncasecmp( psz_subtitle, "&lt;", 4 )) 
     725            { 
     726                strcpy( psz_html, "&lt;" ); 
     727                psz_html += 4; 
     728                psz_subtitle += 4; 
     729            } 
     730            else if( !strncasecmp( psz_subtitle, "&gt;", 4 )) 
     731            { 
     732                strcpy( psz_html, "&gt;" ); 
     733                psz_html += 4; 
     734                psz_subtitle += 4; 
     735            } 
     736            else if( !strncasecmp( psz_subtitle, "&amp;", 5 )) 
     737            { 
     738                strcpy( psz_html, "&amp;" ); 
     739                psz_html += 5; 
     740                psz_subtitle += 5; 
     741            } 
     742            else 
     743            { 
     744                strcpy( psz_html, "&amp;" ); 
     745                psz_html += 5; 
     746                psz_subtitle++; 
     747            } 
     748        } 
     749        else 
     750        { 
     751            *psz_html = *psz_subtitle; 
     752            if( psz_html > psz_html_start ) 
     753            { 
     754                /* Check for double whitespace */ 
     755                if((( *psz_html == ' ' ) || 
     756                    ( *psz_html == '\t' )) && 
     757                   (( *(psz_html-1) == ' ' ) || 
     758                    ( *(psz_html-1) == '\t' ))) 
    721759                { 
    722                     strcpy( psz_html, "&lt;" ); 
    723                     psz_html += 4; 
    724                     psz_subtitle += 4; 
     760                    strcpy( psz_html, NO_BREAKING_SPACE ); 
     761                    psz_html += strlen( NO_BREAKING_SPACE ) - 1; 
    725762                } 
    726                 else if( !strncasecmp( psz_subtitle, "&gt;", 4 )) 
    727                 { 
    728                     strcpy( psz_html, "&gt;" ); 
    729                     psz_html += 4; 
    730                     psz_subtitle += 4; 
    731                 } 
    732                 else if( !strncasecmp( psz_subtitle, "&amp;", 5 )) 
    733                 { 
    734                     strcpy( psz_html, "&amp;" ); 
    735                     psz_html += 5; 
    736                     psz_subtitle += 5; 
    737                 } 
    738                 else 
    739                 { 
    740                     strcpy( psz_html, "&amp;" ); 
    741                     psz_html += 5; 
    742                     psz_subtitle++; 
    743                 } 
    744             } 
    745             else 
    746             { 
    747                 *psz_html = *psz_subtitle; 
    748                 if( psz_html > psz_html_start ) 
    749                 { 
    750                     /* Check for double whitespace */ 
    751                     if((( *psz_html == ' ' ) || 
    752                         ( *psz_html == '\t' )) && 
    753                        (( *(psz_html-1) == ' ' ) || 
    754                         ( *(psz_html-1) == '\t' ))) 
    755                     { 
    756                         strcpy( psz_html, NO_BREAKING_SPACE ); 
    757                         psz_html += strlen( NO_BREAKING_SPACE ) - 1; 
    758                     } 
    759                 } 
    760                 psz_html++; 
    761                 psz_subtitle++; 
    762             } 
    763  
    764             if( ( size_t )( psz_html - psz_html_start ) > i_buf_size - 10 ) 
    765             { 
    766                 int i_len = psz_html - psz_html_start; 
    767  
    768                 i_buf_size += 100; 
    769                 psz_html_start = realloc( psz_html_start, i_buf_size ); 
    770                 psz_html = psz_html_start + i_len; 
    771                 *psz_html = '\0'; 
    772             } 
    773         } 
    774         strcpy( psz_html, "</text>" ); 
    775         psz_html += 7; 
    776  
    777         if( psz_tag[ 0 ] != '\0' ) 
    778         { 
    779             /* Not well formed -- kill everything */ 
    780             free( psz_html_start ); 
    781             psz_html_start = NULL; 
    782         } 
    783         else if( psz_html_start ) 
    784         { 
    785             /* Shrink the memory requirements */ 
    786             psz_html_start = realloc( psz_html_start,  psz_html - psz_html_start + 1 ); 
    787         } 
     763            } 
     764            psz_html++; 
     765            psz_subtitle++; 
     766        } 
     767 
     768        if( ( size_t )( psz_html - psz_html_start ) > i_buf_size - 10 ) 
     769        { 
     770            int i_len = psz_html - psz_html_start; 
     771 
     772            i_buf_size += 100; 
     773            psz_html_start = realloc( psz_html_start, i_buf_size ); 
     774            psz_html = psz_html_start + i_len; 
     775            *psz_html = '\0'; 
     776        } 
     777    } 
     778    strcpy( psz_html, "</text>" ); 
     779    psz_html += 7; 
     780 
     781    if( psz_tag[ 0 ] != '\0' ) 
     782    { 
     783        /* Not well formed -- kill everything */ 
     784        free( psz_html_start ); 
     785        psz_html_start = NULL; 
     786    } 
     787    else if( psz_html_start ) 
     788    { 
     789        /* Shrink the memory requirements */ 
     790        psz_html_start = realloc( psz_html_start,  psz_html - psz_html_start + 1 ); 
    788791    } 
    789792    free( psz_tag );