Mercurial > mplayer.hg
annotate parser-mpcmd.c @ 25312:643c5e2b6b56
Comment out unused variable.
author | diego |
---|---|
date | Mon, 10 Dec 2007 14:13:34 +0000 |
parents | 75837c33484b |
children | 65d1238b3631 |
rev | line source |
---|---|
18265 | 1 |
2 /// \file | |
3 /// \ingroup ConfigParsers Playtree | |
4 | |
8164 | 5 #include "config.h" |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <errno.h> | |
11 | |
12 #ifdef MP_DEBUG | |
13 #include <assert.h> | |
14 #endif | |
15 | |
16 #include "mp_msg.h" | |
21312 | 17 #include "help_mp.h" |
8164 | 18 #include "m_option.h" |
19 #include "m_config.h" | |
20 #include "playtree.h" | |
21 | |
22 static int recursion_depth = 0; | |
23 static int mode = 0; | |
24 | |
25 #define GLOBAL 0 | |
26 #define LOCAL 1 | |
27 #define DROP_LOCAL 2 | |
28 | |
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
29 #define dvd_range(a) (a>0 && a<256) |
8164 | 30 #define UNSET_GLOBAL (mode = LOCAL) |
31 // Use this 1 if you want to have only global option (no per file option) | |
32 // #define UNSET_GLOBAL (mode = GLOBAL) | |
33 | |
34 | |
35 static int is_entry_option(char *opt, char *param, play_tree_t** ret) { | |
36 play_tree_t* entry = NULL; | |
37 | |
38 *ret = NULL; | |
39 | |
40 if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here | |
41 if(!param) | |
42 return M_OPT_MISSING_PARAM; | |
12267 | 43 |
8164 | 44 entry = parse_playlist_file(param); |
45 if(!entry) | |
12267 | 46 return -1; |
47 else { | |
48 *ret=entry; | |
49 return 1; | |
50 } | |
8164 | 51 } |
52 return 0; | |
53 } | |
54 | |
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
55 static inline void add_entry(play_tree_t **last_parentp, |
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
56 play_tree_t **last_entryp, play_tree_t *entry) { |
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
57 if(*last_entryp == NULL) |
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
58 play_tree_set_child(*last_parentp,entry); |
10513 | 59 else |
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
60 play_tree_append_entry(*last_entryp,entry); |
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
61 *last_entryp = entry; |
10513 | 62 } |
63 | |
18265 | 64 /// Setup the \ref Config from command line arguments and build a playtree. |
65 /** \ingroup ConfigParsers | |
66 */ | |
8164 | 67 play_tree_t* |
68 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv) | |
69 { | |
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
70 int i,j,start_title=-1,end_title=-1; |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
71 char *opt,*splitpos=NULL; |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
72 char entbuf[10]; |
8164 | 73 int no_more_opts = 0; |
16345
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
74 int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything |
8164 | 75 play_tree_t *last_parent, *last_entry = NULL, *root; |
13909
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
76 #ifdef MACOSX_FINDER_SUPPORT |
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
77 extern play_tree_t *macosx_finder_args(m_config_t *, int , char **); |
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
78 #endif |
8164 | 79 |
80 #ifdef MP_DEBUG | |
81 assert(config != NULL); | |
82 assert(argv != NULL); | |
83 assert(argc >= 1); | |
84 #endif | |
85 | |
86 config->mode = M_COMMAND_LINE; | |
87 mode = GLOBAL; | |
13909
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
88 #ifdef MACOSX_FINDER_SUPPORT |
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
89 root=macosx_finder_args(config, argc, argv); |
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
90 if(root) |
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
91 return root; |
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
92 #endif |
07dadc3066f3
add support for macosx finder argument support (let you bundle mplayer to be a finder compliant .app) patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
12816
diff
changeset
|
93 |
8164 | 94 last_parent = root = play_tree_new(); |
95 /* in order to work recursion detection properly in parse_config_file */ | |
96 ++recursion_depth; | |
97 | |
98 for (i = 1; i < argc; i++) { | |
99 //next: | |
100 opt = argv[i]; | |
101 /* check for -- (no more options id.) except --help! */ | |
15245
4fdfe0860cc5
Make "mplayer -- --a" play the file --a instead of bailing out with a useless
reimar
parents:
14541
diff
changeset
|
102 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0)) |
8164 | 103 { |
104 no_more_opts = 1; | |
105 if (i+1 >= argc) | |
106 { | |
21312 | 107 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NoFileGivenOnCommandLine); |
8164 | 108 goto err_out; |
109 } | |
110 continue; | |
111 } | |
112 if((opt[0] == '{') && (opt[1] == '\0')) | |
113 { | |
114 play_tree_t* entry = play_tree_new(); | |
115 UNSET_GLOBAL; | |
8175 | 116 if(last_parent->flags & PLAY_TREE_RND) |
117 entry->flags |= PLAY_TREE_RND; | |
8164 | 118 if(last_entry == NULL) { |
119 play_tree_set_child(last_parent,entry); | |
120 } else { | |
121 play_tree_append_entry(last_entry,entry); | |
122 last_entry = NULL; | |
123 } | |
124 last_parent = entry; | |
125 continue; | |
126 } | |
127 | |
128 if((opt[0] == '}') && (opt[1] == '\0')) | |
129 { | |
130 if( ! last_parent || ! last_parent->parent) { | |
131 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n"); | |
132 goto err_out; | |
133 } | |
134 last_entry = last_parent; | |
135 last_parent = last_entry->parent; | |
136 continue; | |
137 } | |
138 | |
139 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ | |
140 { | |
13932
f845791e2823
fix: when doing -loop 0 -shuffle, the arg after shuffle was skipped
reimar
parents:
13909
diff
changeset
|
141 int tmp = 0; |
8164 | 142 /* remove trailing '-' */ |
143 opt++; | |
144 | |
145 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); | |
146 // We handle here some specific option | |
17472
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
16345
diff
changeset
|
147 // Loop option when it apply to a group |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
16345
diff
changeset
|
148 if(strcasecmp(opt,"loop") == 0 && |
8164 | 149 (! last_entry || last_entry->child) ) { |
150 int l; | |
18097
df9633d451dc
avoid crash when running "mplayer -loop" (dereferencing uninitialize pointer).
reimar
parents:
17472
diff
changeset
|
151 char* end = NULL; |
8400 | 152 l = (i+1<argc) ? strtol(argv[i+1],&end,0) : 0; |
18097
df9633d451dc
avoid crash when running "mplayer -loop" (dereferencing uninitialize pointer).
reimar
parents:
17472
diff
changeset
|
153 if(!end || *end != '\0') { |
21312 | 154 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_TheLoopOptionMustBeAnInteger, argv[i+1]); |
8164 | 155 tmp = ERR_OUT_OF_RANGE; |
9106 | 156 } else { |
8164 | 157 play_tree_t* pt = last_entry ? last_entry : last_parent; |
158 l = l <= 0 ? -1 : l; | |
159 pt->loop = l; | |
160 tmp = 1; | |
161 } | |
8452 | 162 } else if(strcasecmp(opt,"shuffle") == 0) { |
8175 | 163 if(last_entry && last_entry->child) |
164 last_entry->flags |= PLAY_TREE_RND; | |
165 else | |
166 last_parent->flags |= PLAY_TREE_RND; | |
8452 | 167 } else if(strcasecmp(opt,"noshuffle") == 0) { |
8175 | 168 if(last_entry && last_entry->child) |
169 last_entry->flags &= ~PLAY_TREE_RND; | |
170 else | |
171 last_parent->flags &= ~PLAY_TREE_RND; | |
8164 | 172 } else { |
25227 | 173 const m_option_t* mp_opt = NULL; |
8164 | 174 play_tree_t* entry = NULL; |
175 | |
8458 | 176 tmp = is_entry_option(opt,(i+1<argc) ? argv[i + 1] : NULL,&entry); |
8164 | 177 if(tmp > 0) { // It's an entry |
178 if(entry) { | |
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
179 add_entry(&last_parent,&last_entry,entry); |
8175 | 180 if((last_parent->flags & PLAY_TREE_RND) && entry->child) |
181 entry->flags |= PLAY_TREE_RND; | |
8164 | 182 UNSET_GLOBAL; |
183 } else if(mode == LOCAL) // Entry is empty we have to drop his params | |
184 mode = DROP_LOCAL; | |
185 } else if(tmp == 0) { // 'normal' options | |
186 mp_opt = m_config_get_option(config,opt); | |
187 if (mp_opt != NULL) { // Option exist | |
188 if(mode == GLOBAL || (mp_opt->flags & M_OPT_GLOBAL)) | |
8426 | 189 tmp = (i+1<argc) ? m_config_set_option(config, opt, argv[i + 1]) |
190 : m_config_set_option(config, opt, NULL); | |
8164 | 191 else { |
8458 | 192 tmp = m_config_check_option(config, opt, (i+1<argc) ? argv[i + 1] : NULL); |
8164 | 193 if(tmp >= 0 && mode != DROP_LOCAL) { |
194 play_tree_t* pt = last_entry ? last_entry : last_parent; | |
195 play_tree_set_param(pt,opt, argv[i + 1]); | |
196 } | |
197 } | |
198 } else { | |
10595
522afd56703c
100l to albeu for his english grammar, and 10l to me becouse I noticed that lately (my backward compatibilty macro uses M_OPT_UNKNOWN)
alex
parents:
10594
diff
changeset
|
199 tmp = M_OPT_UNKNOWN; |
21312 | 200 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_UnknownOptionOnCommandLine, opt); |
8164 | 201 } |
202 } | |
203 } | |
204 | |
16345
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
205 if (tmp <= M_OPT_EXIT) { |
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
206 opt_exit = 1; |
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
207 tmp = M_OPT_EXIT - tmp; |
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
208 } else |
9792 | 209 if (tmp < 0) { |
21312 | 210 mp_msg(MSGT_CFGPARSER, MSGL_FATAL, MSGTR_ErrorParsingOptionOnCommandLine, opt); |
8164 | 211 goto err_out; |
9792 | 212 } |
8164 | 213 i += tmp; |
214 } | |
215 else /* filename */ | |
216 { | |
217 play_tree_t* entry = play_tree_new(); | |
218 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]); | |
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
219 // if required expand DVD filename entries like dvd://1-3 into component titles |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
220 if ( strstr(argv[i],"dvd://") != NULL ) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
221 { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
222 splitpos=strstr(argv[i]+6,"-"); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
223 if(splitpos != NULL) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
224 { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
225 start_title=strtol(argv[i]+6,NULL,10); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
226 if (start_title<0) { //entries like dvd://-2 start title implied 1 |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
227 end_title=abs(start_title); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
228 start_title=1; |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
229 } else { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
230 end_title=strtol(splitpos+1,NULL,10); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
231 } |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
232 |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
233 if (dvd_range(start_title) && dvd_range(end_title) && (start_title<end_title)) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
234 { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
235 for (j=start_title;j<=end_title;j++) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
236 { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
237 if (j!=start_title) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
238 entry=play_tree_new(); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
239 snprintf(entbuf,9,"dvd://%d",j); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
240 play_tree_add_file(entry,entbuf); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
241 add_entry(&last_parent,&last_entry,entry); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
242 last_entry = entry; |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
243 } |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
244 } else { |
21312 | 245 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_InvalidPlayEntry, argv[i]); |
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
246 } |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
247 |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
248 } else { // dvd:// or dvd://x entry |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
249 play_tree_add_file(entry,argv[i]); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
250 } |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
251 } else { |
8164 | 252 play_tree_add_file(entry,argv[i]); |
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
253 } |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
254 |
8164 | 255 // Lock stdin if it will be used as input |
256 if(strcasecmp(argv[i],"-") == 0) | |
12816 | 257 m_config_set_option(config,"noconsolecontrols",NULL); |
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
258 add_entry(&last_parent,&last_entry,entry); |
8164 | 259 UNSET_GLOBAL; // We start entry specific options |
260 | |
261 } | |
262 } | |
263 | |
16345
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
264 if (opt_exit) |
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
265 goto err_out; |
8164 | 266 --recursion_depth; |
267 if(last_parent != root) | |
268 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n"); | |
269 return root; | |
270 | |
271 err_out: | |
272 --recursion_depth; | |
273 play_tree_free(root,1); | |
274 return NULL; | |
275 } |