Changeset 6ba2378ea683a7cbab6739cb18b64324ba56a377

Show
Ignore:
Timestamp:
13/05/08 08:10:36 (7 months ago)
Author:
Jean-Baptiste Kempf <jb@videolan.org>
git-committer:
Jean-Baptiste Kempf <jb@videolan.org> 1210659036 -0700
git-parent:

[2828d7d1b3f14983d09f5cfb12b4ce13c8b827ed]

git-author:
Jean-Baptiste Kempf <jb@videolan.org> 1210659021 -0700
Message:

Cosmetic, malloc checks and options completion.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/demux/subtitle.c

    r6f9ce7c r6ba2378  
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
    88 *          Derk-Jan Hartman <hartman at videolan dot org> 
     9 *          Jean-Baptiste Kempf <jb@videolan.org> 
    910 * 
    1011 * This program is free software; you can redistribute it and/or modify 
     
    5859    N_("Force the subtiles format. Valid values are : \"microdvd\", " \ 
    5960    "\"subrip\",  \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\" " \ 
    60     "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\" and \"auto\" (meaning autodetection, this " \ 
     61    "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\" "\ 
     62    "\"mpsub\" \"jacosub\" and \"auto\" (meaning autodetection, this " \ 
    6163    "should always work).") 
    6264static const char *ppsz_sub_type[] = 
     
    6466    "auto", "microdvd", "subrip", "subviewer", "ssa1", 
    6567    "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2", 
    66     "aqt", "pjs" 
     68    "aqt", "pjs", "mpsub", "jacosub" 
    6769}; 
    6870 
     
    218220    p_demux->pf_control = Control; 
    219221    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); 
     222    if( p_sys == NULL ) 
     223        return VLC_ENOMEM; 
     224 
    220225    p_sys->psz_header         = NULL; 
    221226    p_sys->i_subtitle         = 0; 
     
    741746                          int i_idx ) 
    742747{ 
     748    VLC_UNUSED( i_idx ); 
    743749    demux_sys_t *p_sys = p_demux->p_sys; 
    744750    text_t      *txt = &p_sys->txt; 
     
    887893                         int i_idx ) 
    888894{ 
     895    VLC_UNUSED( i_idx ); 
    889896    return ParseSubRipSubViewer( p_demux, p_subtitle, 
    890897                                 "%d:%d:%d,%d --> %d:%d:%d,%d", 
     
    896903                            int i_idx ) 
    897904{ 
     905    VLC_UNUSED( i_idx ); 
     906 
    898907    return ParseSubRipSubViewer( p_demux, p_subtitle, 
    899908                                 "%d:%d:%d.%d,%d:%d:%d.%d", 
     
    9971006                          int i_idx ) 
    9981007{ 
     1008    VLC_UNUSED( i_idx ); 
     1009 
    9991010    demux_sys_t *p_sys = p_demux->p_sys; 
    10001011    text_t      *txt = &p_sys->txt; 
     
    10621073static int  ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) 
    10631074{ 
     1075    VLC_UNUSED( i_idx ); 
    10641076    demux_sys_t *p_sys = p_demux->p_sys; 
    10651077    text_t      *txt = &p_sys->txt; 
     
    11601172                             int i_idx ) 
    11611173{ 
     1174    VLC_UNUSED( i_idx ); 
     1175 
    11621176    demux_sys_t *p_sys = p_demux->p_sys; 
    11631177    text_t      *txt = &p_sys->txt; 
     
    12241238static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) 
    12251239{ 
     1240    VLC_UNUSED( i_idx ); 
     1241 
    12261242    demux_sys_t *p_sys = p_demux->p_sys; 
    12271243    text_t      *txt = &p_sys->txt; 
     
    12721288static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) 
    12731289{ 
     1290    VLC_UNUSED( i_idx ); 
     1291 
    12741292    demux_sys_t *p_sys = p_demux->p_sys; 
    12751293    text_t      *txt = &p_sys->txt; 
     
    13241342static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) 
    13251343{ 
     1344    VLC_UNUSED( i_idx ); 
     1345 
    13261346    demux_sys_t *p_sys = p_demux->p_sys; 
    13271347    text_t      *txt = &p_sys->txt; 
     
    13371357 
    13381358        psz_text = malloc( strlen(s) + 1 ); 
     1359        if( !psz_text ) 
     1360            return VLC_ENOMEM; 
    13391361 
    13401362        /* Data Lines */ 
     
    13611383static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) 
    13621384{ 
     1385    VLC_UNUSED( i_idx ); 
     1386 
    13631387    demux_sys_t *p_sys = p_demux->p_sys; 
    13641388    text_t      *txt = &p_sys->txt; 
     
    13671391    for( ;; ) 
    13681392    { 
    1369         const char *s = TextGetLine( txt ); 
    13701393        float f1, f2; 
    13711394        char p_dummy; 
    13721395        char *psz_temp; 
    13731396 
     1397        const char *s = TextGetLine( txt ); 
    13741398        if( !s ) 
    13751399            return VLC_EGENERIC; 
     1400 
    13761401        if( strstr( s, "FORMAT" ) ) 
    13771402        { 
     
    13831408 
    13841409            psz_temp = malloc( strlen(s) ); 
     1410            if( !psz_temp ) 
     1411                return VLC_ENOMEM; 
     1412 
    13851413            if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) ) 
    13861414            { 
     
    14341462static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) 
    14351463{ 
     1464    VLC_UNUSED( i_idx ); 
     1465 
    14361466    demux_sys_t  *p_sys = p_demux->p_sys; 
    14371467    text_t       *txt = &p_sys->txt; 
     
    14521482 
    14531483        psz_text = malloc( strlen( s ) + 1 ); 
     1484        if( !psz_text ) 
     1485            return VLC_ENOMEM; 
    14541486        psz_orig = psz_text; 
    14551487 
     1488        /* Complete time lines */ 
    14561489        if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]", 
    14571490                    &h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 ) 
     
    14641497                * 1000000; 
    14651498        } 
     1499        /* Short time lines */ 
    14661500        else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 ) 
    14671501        { 
     
    14711505                    ( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 ); 
    14721506        } 
     1507        /* General Directive lines */ 
     1508        /* Only TIME and SHIFT are supported so far */ 
    14731509        else if( s[0] == '#' ) 
    14741510        { 
     
    14811517            switch( toupper( psz_text[1] ) ) 
    14821518            { 
    1483                 case 'S': 
    1484                      shift = isalpha( psz_text[2] ) ? 6 : 2 ; 
    1485  
    1486                      if( sscanf( &psz_text[shift], "%d", &h ) ) 
     1519            case 'S': 
     1520                 shift = isalpha( psz_text[2] ) ? 6 : 2 ; 
     1521 
     1522                 if( sscanf( &psz_text[shift], "%d", &h ) ) 
     1523                 { 
     1524                     /* Negative shifting */ 
     1525                     if( h < 0 ) 
    14871526                     { 
    1488                          /* Negative shifting */ 
    1489                          if( h < 0 ) 
     1527                         h *= -1; 
     1528                         inv = -1; 
     1529                     } 
     1530 
     1531                     if( sscanf( &psz_text[shift], "%*d:%d", &m ) ) 
     1532                     { 
     1533                         if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) ) 
    14901534                         { 
    1491                              h *= -1; 
    1492                              inv = -1; 
    1493                          } 
    1494  
    1495                          if( sscanf( &psz_text[shift], "%*d:%d", &m ) ) 
    1496                          { 
    1497                              if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) ) 
    1498                              { 
    1499                                  sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f ); 
    1500                              } 
    1501                              else 
    1502                              { 
    1503                                  h = 0; 
    1504                                  sscanf( &psz_text[shift], "%d:%d.%d", &m, &sec, &f ); 
    1505                                  m *= inv; 
    1506                              } 
     1535                             sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f ); 
    15071536                         } 
    15081537                         else 
    15091538                         { 
    1510                              h = m = 0; 
    1511                              sscanf( &psz_text[shift], "%d.%d", &sec, &f); 
    1512                              sec *= inv; 
     1539                             h = 0; 
     1540                             sscanf( &psz_text[shift], "%d:%d.%d", 
     1541                                     &m, &sec, &f ); 
     1542                             m *= inv; 
    15131543                         } 
    1514                          jss_time_shift = ( ( h * 3600 + m * 60 + sec ) 
    1515                              * jss_time_resolution + f ) * inv; 
    15161544                     } 
    1517                      break; 
    1518  
    1519                 case 'T': 
    1520                     shift = isalpha( psz_text[2] ) ? 8 : 2 ; 
    1521  
    1522                     sscanf( &psz_text[shift], "%d", &jss_time_resolution ); 
    1523                     break; 
     1545                     else 
     1546                     { 
     1547                         h = m = 0; 
     1548                         sscanf( &psz_text[shift], "%d.%d", &sec, &f); 
     1549                         sec *= inv; 
     1550                     } 
     1551                     jss_time_shift = ( ( h * 3600 + m * 60 + sec ) 
     1552                         * jss_time_resolution + f ) * inv; 
     1553                 } 
     1554                 break; 
     1555 
     1556            case 'T': 
     1557                shift = isalpha( psz_text[2] ) ? 8 : 2 ; 
     1558 
     1559                sscanf( &psz_text[shift], "%d", &jss_time_resolution ); 
     1560                break; 
    15241561            } 
    15251562            free( psz_text ); 
     
    15271564        } 
    15281565        else 
    1529             /* Unkown line */ 
     1566            /* Unkown type line, probably a comment */ 
    15301567        { 
    15311568            free( psz_text ); 
     
    15431580 
    15441581            /* Directives are NOT parsed yet */ 
     1582            /* This has probably a better place in a decoder ? */ 
    15451583            /* directive = malloc( strlen( psz_text ) + 1 ); 
    15461584            if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/ 
     
    15501588        while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++; 
    15511589 
     1590 
     1591        /* Clean all the lines from inline comments and other stuffs */ 
    15521592        psz_text2 = calloc( strlen( psz_text) + 1, 1 ); 
    15531593        psz_orig2 = psz_text2; 
     
    16381678    } 
    16391679} 
     1680