Mercurial > mplayer.hg
annotate parser-mpcmd.c @ 20464:7b8269775ec0
10l: fixed misplaced adaption field check
author | nicodvb |
---|---|
date | Sat, 28 Oct 2006 09:03:51 +0000 |
parents | 1a14fde7680d |
children | d78e7d5bc6d5 |
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" | |
17 #include "m_option.h" | |
18 #include "m_config.h" | |
19 #include "playtree.h" | |
20 | |
21 static int recursion_depth = 0; | |
22 static int mode = 0; | |
23 | |
24 #define GLOBAL 0 | |
25 #define LOCAL 1 | |
26 #define DROP_LOCAL 2 | |
27 | |
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
28 #define dvd_range(a) (a>0 && a<256) |
8164 | 29 #define UNSET_GLOBAL (mode = LOCAL) |
30 // Use this 1 if you want to have only global option (no per file option) | |
31 // #define UNSET_GLOBAL (mode = GLOBAL) | |
32 | |
33 | |
34 static int is_entry_option(char *opt, char *param, play_tree_t** ret) { | |
35 play_tree_t* entry = NULL; | |
36 | |
37 *ret = NULL; | |
38 | |
39 if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here | |
40 if(!param) | |
41 return M_OPT_MISSING_PARAM; | |
12267 | 42 |
8164 | 43 entry = parse_playlist_file(param); |
44 if(!entry) | |
12267 | 45 return -1; |
46 else { | |
47 *ret=entry; | |
48 return 1; | |
49 } | |
8164 | 50 } |
51 return 0; | |
52 } | |
53 | |
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
54 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
|
55 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
|
56 if(*last_entryp == NULL) |
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
57 play_tree_set_child(*last_parentp,entry); |
10513 | 58 else |
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
59 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
|
60 *last_entryp = entry; |
10513 | 61 } |
62 | |
18265 | 63 /// Setup the \ref Config from command line arguments and build a playtree. |
64 /** \ingroup ConfigParsers | |
65 */ | |
8164 | 66 play_tree_t* |
67 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv) | |
68 { | |
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
69 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
|
70 char *opt,*splitpos=NULL; |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
71 char entbuf[10]; |
8164 | 72 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
|
73 int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything |
8164 | 74 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
|
75 #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
|
76 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
|
77 #endif |
8164 | 78 |
79 #ifdef MP_DEBUG | |
80 assert(config != NULL); | |
81 assert(argv != NULL); | |
82 assert(argc >= 1); | |
83 #endif | |
84 | |
85 config->mode = M_COMMAND_LINE; | |
86 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
|
87 #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
|
88 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
|
89 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
|
90 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
|
91 #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
|
92 |
8164 | 93 last_parent = root = play_tree_new(); |
94 /* in order to work recursion detection properly in parse_config_file */ | |
95 ++recursion_depth; | |
96 | |
97 for (i = 1; i < argc; i++) { | |
98 //next: | |
99 opt = argv[i]; | |
100 /* 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
|
101 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0)) |
8164 | 102 { |
103 no_more_opts = 1; | |
104 if (i+1 >= argc) | |
105 { | |
14541 | 106 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "'--' indicates no more options, but no filename was given on the command line.\n"); |
8164 | 107 goto err_out; |
108 } | |
109 continue; | |
110 } | |
111 if((opt[0] == '{') && (opt[1] == '\0')) | |
112 { | |
113 play_tree_t* entry = play_tree_new(); | |
114 UNSET_GLOBAL; | |
8175 | 115 if(last_parent->flags & PLAY_TREE_RND) |
116 entry->flags |= PLAY_TREE_RND; | |
8164 | 117 if(last_entry == NULL) { |
118 play_tree_set_child(last_parent,entry); | |
119 } else { | |
120 play_tree_append_entry(last_entry,entry); | |
121 last_entry = NULL; | |
122 } | |
123 last_parent = entry; | |
124 continue; | |
125 } | |
126 | |
127 if((opt[0] == '}') && (opt[1] == '\0')) | |
128 { | |
129 if( ! last_parent || ! last_parent->parent) { | |
130 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n"); | |
131 goto err_out; | |
132 } | |
133 last_entry = last_parent; | |
134 last_parent = last_entry->parent; | |
135 continue; | |
136 } | |
137 | |
138 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ | |
139 { | |
13932
f845791e2823
fix: when doing -loop 0 -shuffle, the arg after shuffle was skipped
reimar
parents:
13909
diff
changeset
|
140 int tmp = 0; |
8164 | 141 /* remove trailing '-' */ |
142 opt++; | |
143 | |
144 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); | |
145 // We handle here some specific option | |
17472
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
16345
diff
changeset
|
146 // Loop option when it apply to a group |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
16345
diff
changeset
|
147 if(strcasecmp(opt,"loop") == 0 && |
8164 | 148 (! last_entry || last_entry->child) ) { |
149 int l; | |
18097
df9633d451dc
avoid crash when running "mplayer -loop" (dereferencing uninitialize pointer).
reimar
parents:
17472
diff
changeset
|
150 char* end = NULL; |
8400 | 151 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
|
152 if(!end || *end != '\0') { |
9106 | 153 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The loop option must be an integer: %s\n",argv[i+1]); |
8164 | 154 tmp = ERR_OUT_OF_RANGE; |
9106 | 155 } else { |
8164 | 156 play_tree_t* pt = last_entry ? last_entry : last_parent; |
157 l = l <= 0 ? -1 : l; | |
158 pt->loop = l; | |
159 tmp = 1; | |
160 } | |
8452 | 161 } else if(strcasecmp(opt,"shuffle") == 0) { |
8175 | 162 if(last_entry && last_entry->child) |
163 last_entry->flags |= PLAY_TREE_RND; | |
164 else | |
165 last_parent->flags |= PLAY_TREE_RND; | |
8452 | 166 } else if(strcasecmp(opt,"noshuffle") == 0) { |
8175 | 167 if(last_entry && last_entry->child) |
168 last_entry->flags &= ~PLAY_TREE_RND; | |
169 else | |
170 last_parent->flags &= ~PLAY_TREE_RND; | |
8164 | 171 } else { |
172 m_option_t* mp_opt = NULL; | |
173 play_tree_t* entry = NULL; | |
174 | |
8458 | 175 tmp = is_entry_option(opt,(i+1<argc) ? argv[i + 1] : NULL,&entry); |
8164 | 176 if(tmp > 0) { // It's an entry |
177 if(entry) { | |
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
178 add_entry(&last_parent,&last_entry,entry); |
8175 | 179 if((last_parent->flags & PLAY_TREE_RND) && entry->child) |
180 entry->flags |= PLAY_TREE_RND; | |
8164 | 181 UNSET_GLOBAL; |
182 } else if(mode == LOCAL) // Entry is empty we have to drop his params | |
183 mode = DROP_LOCAL; | |
184 } else if(tmp == 0) { // 'normal' options | |
185 mp_opt = m_config_get_option(config,opt); | |
186 if (mp_opt != NULL) { // Option exist | |
187 if(mode == GLOBAL || (mp_opt->flags & M_OPT_GLOBAL)) | |
8426 | 188 tmp = (i+1<argc) ? m_config_set_option(config, opt, argv[i + 1]) |
189 : m_config_set_option(config, opt, NULL); | |
8164 | 190 else { |
8458 | 191 tmp = m_config_check_option(config, opt, (i+1<argc) ? argv[i + 1] : NULL); |
8164 | 192 if(tmp >= 0 && mode != DROP_LOCAL) { |
193 play_tree_t* pt = last_entry ? last_entry : last_parent; | |
194 play_tree_set_param(pt,opt, argv[i + 1]); | |
195 } | |
196 } | |
197 } 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
|
198 tmp = M_OPT_UNKNOWN; |
15742
55cbf0c204bc
when somebody specifies e.g. --loop, the message says that a -loop option
reimar
parents:
15245
diff
changeset
|
199 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown option on the command line: -%s\n",opt); |
8164 | 200 } |
201 } | |
202 } | |
203 | |
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
|
204 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
|
205 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
|
206 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
|
207 } else |
9792 | 208 if (tmp < 0) { |
18209 | 209 mp_msg(MSGT_CFGPARSER, MSGL_FATAL, "Error parsing option on the command line: -%s\n",opt); |
8164 | 210 goto err_out; |
9792 | 211 } |
8164 | 212 i += tmp; |
213 } | |
214 else /* filename */ | |
215 { | |
216 play_tree_t* entry = play_tree_new(); | |
217 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
|
218 // 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
|
219 if ( strstr(argv[i],"dvd://") != NULL ) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
220 { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
221 splitpos=strstr(argv[i]+6,"-"); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
222 if(splitpos != NULL) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
223 { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
224 start_title=strtol(argv[i]+6,NULL,10); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
225 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
|
226 end_title=abs(start_title); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
227 start_title=1; |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
228 } else { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
229 end_title=strtol(splitpos+1,NULL,10); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
230 } |
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 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
|
233 { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
234 for (j=start_title;j<=end_title;j++) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
235 { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
236 if (j!=start_title) |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
237 entry=play_tree_new(); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
238 snprintf(entbuf,9,"dvd://%d",j); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
239 play_tree_add_file(entry,entbuf); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
240 add_entry(&last_parent,&last_entry,entry); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
241 last_entry = entry; |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
242 } |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
243 } else { |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
244 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Invalid play entry %s\n",argv[i]); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
245 } |
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 } else { // dvd:// or dvd://x entry |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
248 play_tree_add_file(entry,argv[i]); |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
249 } |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
250 } else { |
8164 | 251 play_tree_add_file(entry,argv[i]); |
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
252 } |
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
253 |
8164 | 254 // Lock stdin if it will be used as input |
255 if(strcasecmp(argv[i],"-") == 0) | |
12816 | 256 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
|
257 add_entry(&last_parent,&last_entry,entry); |
8164 | 258 UNSET_GLOBAL; // We start entry specific options |
259 | |
260 } | |
261 } | |
262 | |
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
|
263 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
|
264 goto err_out; |
8164 | 265 --recursion_depth; |
266 if(last_parent != root) | |
267 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n"); | |
268 return root; | |
269 | |
270 err_out: | |
271 --recursion_depth; | |
272 play_tree_free(root,1); | |
273 return NULL; | |
274 } |