]> git.sesse.net Git - vlc/blob - modules/demux/playlist/old.c
Add a bunch of helper functions/macros and start using them:
[vlc] / modules / demux / playlist / old.c
1 /*****************************************************************************
2  * old.c : Old playlist format import
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc/input.h>
29 #include <vlc/intf.h>
30 #include "charset.h"
31
32 #define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
33
34 /*****************************************************************************
35  * Local prototypes
36  *****************************************************************************/
37 static int Demux( demux_t *p_demux);
38 static int Control( demux_t *p_demux, int i_query, va_list args );
39
40 /*****************************************************************************
41  * Import_Old : main import function
42  *****************************************************************************/
43 int E_(Import_Old)( vlc_object_t *p_this )
44 {
45     demux_t *p_demux = (demux_t *)p_this;
46     uint8_t *p_peek;
47
48     if( stream_Peek( p_demux->s, &p_peek, 31 ) < 31 ) return VLC_EGENERIC;
49
50     if( strncmp( (char *)p_peek, PLAYLIST_FILE_HEADER , 31 ) ) return VLC_EGENERIC;
51
52     msg_Dbg( p_demux, "found valid old playlist file");
53     p_demux->pf_control = Control;
54     p_demux->pf_demux = Demux;
55
56     return VLC_SUCCESS;
57 }
58
59 static int Demux( demux_t *p_demux)
60 {
61     char *psz_line;
62     /* Attach playlist and start reading data */
63     playlist_t *p_playlist;
64
65     p_playlist = (playlist_t*)vlc_object_find( p_demux,
66                          VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
67     if( !p_playlist )
68     {
69         msg_Err( p_demux, "cannot attach playlist" );
70         return VLC_EGENERIC;
71     }
72
73     while( ( psz_line = stream_ReadLine( p_demux->s) ) != NULL )
74     {
75         char *psz_unicode;
76
77         if( ( psz_line[0] == '#' ) || (psz_line[0] == '\r') ||
78             ( psz_line[0] == '\n') || (psz_line[0] == (char)0) )
79         {
80             continue;
81         }
82         /* Remove end of line */
83         if( psz_line[strlen(psz_line) -1 ] == '\n' ||
84             psz_line[strlen(psz_line) -1 ] == '\r' )
85         {
86             psz_line[ strlen(psz_line) -1 ] = (char)0;
87             if( psz_line[strlen(psz_line) - 1 ] == '\r' )
88                 psz_line[strlen(psz_line) - 1 ] = (char)0;
89         }
90
91         psz_unicode = FromLocale( psz_line );
92 //        playlist_Add( p_playlist, psz_unicode, psz_unicode, PLAYLIST_APPEND,
93 //                      PLAYLIST_END );
94
95         free( psz_line );
96         LocaleFree( psz_line );
97     }
98
99     p_demux->b_die = VLC_TRUE;
100     vlc_object_release( p_playlist );
101     return VLC_SUCCESS;
102 }
103
104 static int Control( demux_t *p_demux, int i_query, va_list args )
105 {
106     return VLC_EGENERIC;
107 }