Changeset a8fcedd2dde5382673e6b39c559d3b93ac638297

Show
Ignore:
Timestamp:
19/07/06 13:53:18 (2 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1153309998 +0000
git-parent:

[13d098788a120824f287be44e1e63637ba82ddc1]

git-author:
Clément Stenac <zorglub@videolan.org> 1153309998 +0000
Message:

Remove some code duplication

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_common.h

    rf0ddd61 ra8fcedd  
    611611                                    if( !var ) return NULL; 
    612612 
     613#define FREENULL(a) if( a ) { free( a ); a = NULL; } 
     614 
    613615/* Dynamic array handling: realloc array, move data, increment position */ 
    614616#if defined( _MSC_VER ) && _MSC_VER < 1300 && !defined( UNDER_CE ) 
  • modules/demux/playlist/podcast.c

    rf0ddd61 ra8fcedd  
    198198            case XML_READER_TEXT: 
    199199            { 
     200#define SET_DATA( field, name ) else if( b_item == VLC_TRUE \ 
     201                && !strcmp( psz_elname, name ) ) \ 
     202                { \ 
     203                    field = strdup( psz_text ); \ 
     204                } 
    200205                char *psz_text = xml_ReaderValue( p_xml_reader ); 
    201206                /* item specific meta data */ 
     
    203208                { 
    204209                    psz_item_name = strdup( psz_text ); 
    205                 } 
    206                 else if( b_item == VLC_TRUE 
    207                          && !strcmp( psz_elname, "pubDate" ) ) 
    208                 { 
    209                     psz_item_date = strdup( psz_text ); 
    210210                } 
    211211                else if( b_item == VLC_TRUE 
     
    216216                } 
    217217                else if( b_item == VLC_TRUE 
    218                          && !strcmp( psz_elname, "itunes:category" ) ) 
    219                 { 
    220                     psz_item_category = strdup( psz_text ); 
    221                 } 
    222                 else if( b_item == VLC_TRUE 
    223                          && !strcmp( psz_elname, "itunes:duration" ) ) 
    224                 { 
    225                     psz_item_duration = strdup( psz_text ); 
    226                 } 
    227                 else if( b_item == VLC_TRUE 
    228                          && !strcmp( psz_elname, "itunes:keywords" ) ) 
    229                 { 
    230                     psz_item_keywords = strdup( psz_text ); 
    231                 } 
    232                 else if( b_item == VLC_TRUE 
    233                          && !strcmp( psz_elname, "itunes:subtitle" ) ) 
    234                 { 
    235                     psz_item_subtitle = strdup( psz_text ); 
    236                 } 
    237                 else if( b_item == VLC_TRUE 
    238218                         && ( !strcmp( psz_elname, "itunes:summary" ) 
    239219                            ||!strcmp( psz_elname, "description" ) ) ) 
     
    241221                    psz_item_summary = strdup( psz_text ); 
    242222                } 
     223                SET_DATA( psz_item_date, "pubDate" ) 
     224                SET_DATA( psz_item_category, "itunes:category" )  
     225                SET_DATA( psz_item_duration, "itunes:duration" ) 
     226                SET_DATA( psz_item_keywords, "itunes:keywords" ) 
     227                SET_DATA( psz_item_subtitle, "itunes:subtitle" ) 
    243228                /* toplevel meta data */ 
    244229                else if( b_item == VLC_FALSE && b_image == VLC_FALSE 
     
    247232                    playlist_ItemSetName( p_current, psz_text ); 
    248233                } 
    249                 else if( b_item == VLC_FALSE && b_image == VLC_FALSE 
    250                          && !strcmp( psz_elname, "link" ) ) 
    251                 { 
    252                     vlc_input_item_AddInfo( p_current->p_input, 
    253                                             _( "Podcast Info" ), 
    254                                             _( "Podcast Link" ), 
    255                                             "%s", 
    256                                             psz_text ); 
    257                 } 
    258                 else if( b_item == VLC_FALSE && b_image == VLC_FALSE 
    259                          && !strcmp( psz_elname, "copyright" ) ) 
    260                 { 
    261                     vlc_input_item_AddInfo( p_current->p_input, 
    262                                             _( "Podcast Info" ), 
    263                                             _( "Podcast Copyright" ), 
    264                                             "%s", 
    265                                             psz_text ); 
    266                 } 
    267                 else if( b_item == VLC_FALSE && b_image == VLC_FALSE 
    268                          && !strcmp( psz_elname, "itunes:category" ) ) 
    269                 { 
    270                     vlc_input_item_AddInfo( p_current->p_input, 
    271                                             _( "Podcast Info" ), 
    272                                             _( "Podcast Category" ), 
    273                                             "%s", 
    274                                             psz_text ); 
    275                 } 
    276                 else if( b_item == VLC_FALSE && b_image == VLC_FALSE 
    277                          && !strcmp( psz_elname, "itunes:keywords" ) ) 
    278                 { 
    279                     vlc_input_item_AddInfo( p_current->p_input, 
    280                                             _( "Podcast Info" ), 
    281                                             _( "Podcast Keywords" ), 
    282                                             "%s", 
    283                                             psz_text ); 
    284                 } 
    285                 else if( b_item == VLC_FALSE && b_image == VLC_FALSE 
    286                          && !strcmp( psz_elname, "itunes:subtitle" ) ) 
    287                 { 
    288                     vlc_input_item_AddInfo( p_current->p_input, 
    289                                             _( "Podcast Info" ), 
    290                                             _( "Podcast Subtitle" ), 
    291                                             "%s", 
    292                                             psz_text ); 
    293                 } 
     234#define ADD_GINFO( info, name ) \ 
     235    else if( !b_item && !b_image && !strcmp( psz_elname, name ) ) \ 
     236    { \ 
     237        vlc_input_item_AddInfo( p_current->p_input, _("Podcast Info"), \ 
     238                                _( info ), "%s", psz_text ); \ 
     239    } 
     240                ADD_GINFO( "Podcast Link", "link" ) 
     241                ADD_GINFO( "Podcast Copyright", "copyright" ) 
     242                ADD_GINFO( "Podcast Category", "itunes:category" ) 
     243                ADD_GINFO( "Podcast Keywords", "itunes:keywords" ) 
     244                ADD_GINFO( "Podcast Subtitle", "itunes:subtitle" ) 
     245#undef ADD_GINFO 
    294246                else if( b_item == VLC_FALSE && b_image == VLC_FALSE 
    295247                         && ( !strcmp( psz_elname, "itunes:summary" ) 
     
    297249                { /* <description> isn't standard iTunes podcast stuff */ 
    298250                    vlc_input_item_AddInfo( p_current->p_input, 
    299                                             _( "Podcast Info" ), 
    300                                             _( "Podcast Summary" ), 
    301                                             "%s", 
    302                                             psz_text ); 
     251                             _( "Podcast Info" ), _( "Podcast Summary" ), 
     252                             "%s", psz_text ); 
    303253                } 
    304254                else 
     
    322272                                                psz_item_name, 0, NULL, -1 ); 
    323273                    if( p_input == NULL ) break; 
    324                     if( psz_item_date ) 
    325                     { 
    326                         vlc_input_item_AddInfo( p_input, 
    327                                                 _( "Podcast Info" ), 
    328                                                 _( "Podcast Publication Date" ), 
    329                                                 "%s", 
    330                                                 psz_item_date ); 
    331                     } 
    332                     if( psz_item_author ) 
    333                     { 
    334                         vlc_input_item_AddInfo( p_input, 
    335                                                 _( "Podcast Info" ), 
    336                                                 _( "Podcast Author" ), 
    337                                                 "%s", 
    338                                                 psz_item_author ); 
    339                     } 
    340                     if( psz_item_category ) 
    341                     { 
    342                         vlc_input_item_AddInfo( p_input, 
    343                                                 _( "Podcast Info" ), 
    344                                                 _( "Podcast Subcategory" ), 
    345                                                 "%s", 
    346                                                 psz_item_category ); 
    347                     } 
    348                     if( psz_item_duration ) 
    349                     { 
    350                         vlc_input_item_AddInfo( p_input, 
    351                                                 _( "Podcast Info" ), 
    352                                                 _( "Podcast Duration" ), 
    353                                                 "%s", 
    354                                                 psz_item_duration ); 
    355                     } 
    356                     if( psz_item_keywords ) 
    357                     { 
    358                         vlc_input_item_AddInfo( p_input, 
    359                                                 _( "Podcast Info" ), 
    360                                                 _( "Podcast Keywords" ), 
    361                                                 "%s", 
    362                                                 psz_item_keywords ); 
    363                     } 
    364                     if( psz_item_subtitle ) 
    365                     { 
    366                         vlc_input_item_AddInfo( p_input, 
    367                                                 _( "Podcast Info" ), 
    368                                                 _( "Podcast Subtitle" ), 
    369                                                 "%s", 
    370                                                 psz_item_subtitle ); 
    371                     } 
    372                     if( psz_item_summary ) 
    373                     { 
    374                         vlc_input_item_AddInfo( p_input, 
    375                                                 _( "Podcast Info" ), 
    376                                                 _( "Podcast Summary" ), 
    377                                                 "%s", 
    378                                                 psz_item_summary ); 
    379                     } 
     274#define ADD_INFO( info, field ) \ 
     275    if( field ) { vlc_input_item_AddInfo( p_input, \ 
     276                            _( "Podcast Info" ),  _( info ), "%s", field ); } 
     277                    ADD_INFO( "Podcast Publication Date", psz_item_date  ); 
     278                    ADD_INFO( "Podcast Author", psz_item_author ); 
     279                    ADD_INFO( "Podcast Subcategory", psz_item_category ); 
     280                    ADD_INFO( "Podcast Duration", psz_item_duration ); 
     281                    ADD_INFO( "Podcast Keywords", psz_item_keywords ); 
     282                    ADD_INFO( "Podcast Subtitle", psz_item_subtitle ); 
     283                    ADD_INFO( "Podcast Summary", psz_item_summary ); 
     284                    ADD_INFO( "Podcast Type", psz_item_type ); 
    380285                    if( psz_item_size ) 
    381286                    { 
     
    386291                                                psz_item_size ); 
    387292                    } 
    388                     if( psz_item_type ) 
    389                     { 
    390                         vlc_input_item_AddInfo( p_input, 
    391                                                 _( "Podcast Info" ), 
    392                                                 _( "Podcast Type" ), 
    393                                                 "%s", 
    394                                                 psz_item_type ); 
    395                     } 
    396  
    397                     msg_Dbg( p_demux, "Adding WHEREVER\n" ); 
    398293                    playlist_AddWhereverNeeded( p_playlist, p_input, p_current, 
    399294                          p_item_in_category, (i_parent_id > 0 ) ? VLC_TRUE: 
    400295                                                VLC_FALSE, PLAYLIST_APPEND ); 
    401 #define FREE(a) if( a ) free( a ); a = NULL; 
    402                     FREE( psz_item_name ); 
    403                     FREE( psz_item_mrl ); 
    404                     FREE( psz_item_size ); 
    405                     FREE( psz_item_type ); 
    406                     FREE( psz_item_date ); 
    407                     FREE( psz_item_author ); 
    408                     FREE( psz_item_category ); 
    409                     FREE( psz_item_duration ); 
    410                     FREE( psz_item_keywords ); 
    411                     FREE( psz_item_subtitle ); 
    412                     FREE( psz_item_summary ); 
    413 #undef FREE 
    414  
     296                    FREENULL( psz_item_name ); 
     297                    FREENULL( psz_item_mrl ); 
     298                    FREENULL( psz_item_size ); 
     299                    FREENULL( psz_item_type ); 
     300                    FREENULL( psz_item_date ); 
     301                    FREENULL( psz_item_author ); 
     302                    FREENULL( psz_item_category ); 
     303                    FREENULL( psz_item_duration ); 
     304                    FREENULL( psz_item_keywords ); 
     305                    FREENULL( psz_item_subtitle ); 
     306                    FREENULL( psz_item_summary ); 
    415307                    b_item = VLC_FALSE; 
    416308                }