Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

old.c

00001 /*****************************************************************************
00002  * old.c : Old playlist format import
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: old.c 11990 2005-08-03 19:09:58Z courmisch $
00006  *
00007  * Authors: Clément Stenac <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 
00029 #include <vlc/vlc.h>
00030 #include <vlc/input.h>
00031 #include <vlc/intf.h>
00032 
00033 #include <errno.h>                                                 /* ENOMEM */
00034 
00035 #define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
00036 
00037 /*****************************************************************************
00038  * Local prototypes
00039  *****************************************************************************/
00040 static int Demux( demux_t *p_demux);
00041 static int Control( demux_t *p_demux, int i_query, va_list args );
00042 
00043 /*****************************************************************************
00044  * Import_Old : main import function
00045  *****************************************************************************/
00046 int E_(Import_Old)( vlc_object_t *p_this )
00047 {
00048     demux_t *p_demux = (demux_t *)p_this;
00049     uint8_t *p_peek;
00050 
00051     if( stream_Peek( p_demux->s, &p_peek, 31 ) < 31 ) return VLC_EGENERIC;
00052 
00053     if( strncmp( (char *)p_peek, PLAYLIST_FILE_HEADER , 31 ) ) return VLC_EGENERIC;
00054 
00055     msg_Dbg( p_demux, "found valid old playlist file");
00056 
00057     p_demux->pf_control = Control;
00058     p_demux->pf_demux = Demux;
00059 
00060     return VLC_SUCCESS;
00061 }
00062 
00063 static int Demux( demux_t *p_demux)
00064 {
00065     char *psz_line;
00066     /* Attach playlist and start reading data */
00067     playlist_t *p_playlist;
00068 
00069     p_playlist = (playlist_t*)vlc_object_find( p_demux,
00070                          VLC_OBJECT_PLAYLIST, FIND_PARENT );
00071     if( !p_playlist )
00072     {
00073         msg_Err( p_demux, "cannot attach playlist" );
00074         return VLC_EGENERIC;
00075     }
00076 
00077     p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
00078     while( ( psz_line = stream_ReadLine( p_demux->s) ) != NULL )
00079     {
00080         char *psz_unicode;
00081 
00082         if( ( psz_line[0] == '#' ) || (psz_line[0] == '\r') ||
00083             ( psz_line[0] == '\n') || (psz_line[0] == (char)0) )
00084         {
00085             continue;
00086         }
00087         /* Remove end of line */
00088         if( psz_line[strlen(psz_line) -1 ] == '\n' ||
00089             psz_line[strlen(psz_line) -1 ] == '\r' )
00090         {
00091             psz_line[ strlen(psz_line) -1 ] = (char)0;
00092             if( psz_line[strlen(psz_line) - 1 ] == '\r' )
00093                 psz_line[strlen(psz_line) - 1 ] = (char)0;
00094         }
00095 
00096         psz_unicode = FromLocale( psz_line );
00097         playlist_Add( p_playlist, psz_unicode, psz_unicode, PLAYLIST_APPEND,
00098                       PLAYLIST_END );
00099 
00100         free( psz_line );
00101         LocaleFree( psz_line );
00102     }
00103 
00104     p_demux->b_die = VLC_TRUE;
00105     vlc_object_release( p_playlist );
00106     return VLC_SUCCESS;
00107 }
00108 
00109 static int Control( demux_t *p_demux, int i_query, va_list args )
00110 {
00111     return VLC_EGENERIC;
00112 }

Generated on Tue Dec 20 10:14:35 2005 for vlc-0.8.4a by  doxygen 1.4.2