]> git.sesse.net Git - vlc/blob - modules/access/dvdplay/tools.c
* modules/demux/dvdnav.c, modules/access/dvdplay/tools.c: on win32, remove trailing...
[vlc] / modules / access / dvdplay / tools.c
1 /*****************************************************************************
2  * tools.c: tools for dvd plugin.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id$
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 if( psz_source[0] && psz_source[1] == ':' &&
111              psz_source[2] == '\\' && psz_source[3] == '\0' )
112     {
113         /* Don't try to stat the file */
114         psz_source[2] = '\0';
115     }
116     else
117 #endif
118     {
119         if( stat( psz_source, &stat_info ) == -1 )
120         {
121             msg_Warn( p_input, "cannot stat() source `%s' (%s)",
122                                psz_source, strerror(errno) );
123             free( psz_source );
124             return NULL;
125         }
126
127         if( !S_ISBLK(stat_info.st_mode) &&
128             !S_ISCHR(stat_info.st_mode) &&
129             !S_ISDIR(stat_info.st_mode) )
130         {
131             msg_Dbg( p_input, "plugin discarded (not a valid source)" );
132             free( psz_source );
133             return NULL;
134         }
135     }
136     
137     msg_Dbg( p_input, "dvdroot=%s title=%d chapter=%d angle=%d",
138                   psz_source,  *i_title, *i_chapter, *i_angle );
139     
140     return psz_source;
141 }