]> git.sesse.net Git - vlc/blob - modules/access/dvdplay/tools.c
06f3cc9a85a1227ed9f40493bc4eda61797db9f1
[vlc] / modules / access / dvdplay / tools.c
1 /*****************************************************************************
2  * tools.c: tools for dvd plugin.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: tools.c,v 1.4 2003/01/28 15:05:52 massiot Exp $
6  *
7  * Author: Stéphane Borel <stef@via.ecp.fr>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <sys/stat.h>
30 #include <errno.h>
31
32 #include <vlc/vlc.h>
33
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
36 #include "input_ext-dec.h"
37 #include "input_ext-plugins.h"
38
39 #include "dvd.h"
40
41 /*****************************************************************************
42  * dvdplay_ParseCL: parse command line
43  *****************************************************************************/
44 char * dvdplay_ParseCL( input_thread_t * p_input,
45                        int * i_title, int * i_chapter, int * i_angle )
46 {
47     dvd_data_t *            p_dvd;
48     struct stat             stat_info;
49     char *                  psz_parser;
50     char *                  psz_source;
51     char *                  psz_next;
52     
53     p_dvd = (dvd_data_t*)(p_input->p_access_data);
54
55     psz_source = strdup( p_input->psz_name );
56     if( psz_source == NULL )
57     {
58         return NULL;
59     }
60
61     *i_title = 0;
62     *i_chapter = 1;
63     *i_angle = 1;
64     
65     /* Start with the end, because you could have :
66      * dvdplay:/Volumes/my@toto/VIDEO_TS@1,1
67      * (yes, this is kludgy). */
68     for ( psz_parser = psz_source + strlen(psz_source) - 1;
69           psz_parser >= psz_source && *psz_parser != '@';
70           psz_parser-- );
71
72     if( psz_parser >= psz_source && *psz_parser == '@' )
73     {
74         /* Found options */
75         *psz_parser = '\0';
76         ++psz_parser;
77
78         *i_title = (int)strtol( psz_parser, &psz_next, 10 );
79         if( *psz_next )
80         {
81             psz_parser = psz_next + 1;
82             *i_chapter = (int)strtol( psz_parser, &psz_next, 10 );
83             if( *psz_next )
84             {
85                 *i_angle = (int)strtol( psz_next + 1, NULL, 10 );
86             }
87         }
88     }
89
90     *i_title   = *i_title >= 0 ? *i_title : 0;
91     *i_chapter = *i_chapter    ? *i_chapter : 1;
92     *i_angle   = *i_angle      ? *i_angle : 1;
93
94     if( !*psz_source )
95     {
96         free( psz_source );
97         if( !p_input->psz_access )
98         {
99             return NULL;
100         }
101         psz_source = config_GetPsz( p_input, "dvd" );
102         if( !psz_source ) return NULL;
103     }
104
105 #ifdef WIN32
106     if( psz_source[0] && psz_source[1] == ':' && psz_source[2] == '\0' )
107     {
108         /* Don't try to stat the file */
109     }
110     else
111 #endif
112     {
113         if( stat( psz_source, &stat_info ) == -1 )
114         {
115             msg_Warn( p_input, "cannot stat() source `%s' (%s)",
116                                psz_source, strerror(errno) );
117             free( psz_source );
118             return NULL;
119         }
120
121         if( !S_ISBLK(stat_info.st_mode) &&
122             !S_ISCHR(stat_info.st_mode) &&
123             !S_ISDIR(stat_info.st_mode) )
124         {
125             msg_Dbg( p_input, "plugin discarded (not a valid source)" );
126             free( psz_source );
127             return NULL;
128         }
129     }
130     
131     msg_Dbg( p_input, "dvdroot=%s title=%d chapter=%d angle=%d",
132                   psz_source,  *i_title, *i_chapter, *i_angle );
133     
134     return psz_source;
135 }