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