3 /// \ingroup ConfigParsers Playtree
21 static int recursion_depth
= 0;
28 #define dvd_range(a) (a>0 && a<256)
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)
34 static int is_entry_option(char *opt
, char *param
, play_tree_t
** ret
) {
35 play_tree_t
* entry
= NULL
;
39 if(strcasecmp(opt
,"playlist") == 0) { // We handle playlist here
41 return M_OPT_MISSING_PARAM
;
43 entry
= parse_playlist_file(param
);
54 static inline void add_entry(play_tree_t
**last_parentp
,
55 play_tree_t
**last_entryp
, play_tree_t
*entry
) {
56 if(*last_entryp
== NULL
)
57 play_tree_set_child(*last_parentp
,entry
);
59 play_tree_append_entry(*last_entryp
,entry
);
63 /// Setup the \ref Config from command line arguments and build a playtree.
64 /** \ingroup ConfigParsers
67 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
)
69 int i
,j
,start_title
=-1,end_title
=-1;
70 char *opt
,*splitpos
=NULL
;
73 int opt_exit
= 0; // flag indicating whether mplayer should exit without playing anything
74 play_tree_t
*last_parent
, *last_entry
= NULL
, *root
;
75 #ifdef MACOSX_FINDER_SUPPORT
76 extern play_tree_t
*macosx_finder_args(m_config_t
*, int , char **);
80 assert(config
!= NULL
);
85 config
->mode
= M_COMMAND_LINE
;
87 #ifdef MACOSX_FINDER_SUPPORT
88 root
=macosx_finder_args(config
, argc
, argv
);
93 last_parent
= root
= play_tree_new();
94 /* in order to work recursion detection properly in parse_config_file */
97 for (i
= 1; i
< argc
; i
++) {
100 /* check for -- (no more options id.) except --help! */
101 if ((*opt
== '-') && (*(opt
+1) == '-') && (*(opt
+2) == 0))
106 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "'--' indicates no more options, but no filename was given on the command line.\n");
111 if((opt
[0] == '{') && (opt
[1] == '\0'))
113 play_tree_t
* entry
= play_tree_new();
115 if(last_parent
->flags
& PLAY_TREE_RND
)
116 entry
->flags
|= PLAY_TREE_RND
;
117 if(last_entry
== NULL
) {
118 play_tree_set_child(last_parent
,entry
);
120 play_tree_append_entry(last_entry
,entry
);
127 if((opt
[0] == '}') && (opt
[1] == '\0'))
129 if( ! last_parent
|| ! last_parent
->parent
) {
130 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "too much }-\n");
133 last_entry
= last_parent
;
134 last_parent
= last_entry
->parent
;
138 if ((no_more_opts
== 0) && (*opt
== '-') && (*(opt
+1) != 0)) /* option */
141 /* remove trailing '-' */
144 mp_msg(MSGT_CFGPARSER
, MSGL_DBG3
, "this_opt = option: %s\n", opt
);
145 // We handle here some specific option
146 // Loop option when it apply to a group
147 if(strcasecmp(opt
,"loop") == 0 &&
148 (! last_entry
|| last_entry
->child
) ) {
151 l
= (i
+1<argc
) ? strtol(argv
[i
+1],&end
,0) : 0;
152 if(!end
|| *end
!= '\0') {
153 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "The loop option must be an integer: %s\n",argv
[i
+1]);
154 tmp
= ERR_OUT_OF_RANGE
;
156 play_tree_t
* pt
= last_entry
? last_entry
: last_parent
;
161 } else if(strcasecmp(opt
,"shuffle") == 0) {
162 if(last_entry
&& last_entry
->child
)
163 last_entry
->flags
|= PLAY_TREE_RND
;
165 last_parent
->flags
|= PLAY_TREE_RND
;
166 } else if(strcasecmp(opt
,"noshuffle") == 0) {
167 if(last_entry
&& last_entry
->child
)
168 last_entry
->flags
&= ~PLAY_TREE_RND
;
170 last_parent
->flags
&= ~PLAY_TREE_RND
;
172 m_option_t
* mp_opt
= NULL
;
173 play_tree_t
* entry
= NULL
;
175 tmp
= is_entry_option(opt
,(i
+1<argc
) ? argv
[i
+ 1] : NULL
,&entry
);
176 if(tmp
> 0) { // It's an entry
178 add_entry(&last_parent
,&last_entry
,entry
);
179 if((last_parent
->flags
& PLAY_TREE_RND
) && entry
->child
)
180 entry
->flags
|= PLAY_TREE_RND
;
182 } else if(mode
== LOCAL
) // Entry is empty we have to drop his params
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
))
188 tmp
= (i
+1<argc
) ? m_config_set_option(config
, opt
, argv
[i
+ 1])
189 : m_config_set_option(config
, opt
, NULL
);
191 tmp
= m_config_check_option(config
, opt
, (i
+1<argc
) ? argv
[i
+ 1] : NULL
);
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]);
199 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "Unknown option on the command line: -%s\n",opt
);
204 if (tmp
<= M_OPT_EXIT
) {
206 tmp
= M_OPT_EXIT
- tmp
;
209 mp_msg(MSGT_CFGPARSER
, MSGL_FATAL
, "Error parsing option on the command line: -%s\n",opt
);
216 play_tree_t
* entry
= play_tree_new();
217 mp_msg(MSGT_CFGPARSER
, MSGL_DBG2
,"Adding file %s\n",argv
[i
]);
218 // if required expand DVD filename entries like dvd://1-3 into component titles
219 if ( strstr(argv
[i
],"dvd://") != NULL
)
221 splitpos
=strstr(argv
[i
]+6,"-");
224 start_title
=strtol(argv
[i
]+6,NULL
,10);
225 if (start_title
<0) { //entries like dvd://-2 start title implied 1
226 end_title
=abs(start_title
);
229 end_title
=strtol(splitpos
+1,NULL
,10);
232 if (dvd_range(start_title
) && dvd_range(end_title
) && (start_title
<end_title
))
234 for (j
=start_title
;j
<=end_title
;j
++)
237 entry
=play_tree_new();
238 snprintf(entbuf
,9,"dvd://%d",j
);
239 play_tree_add_file(entry
,entbuf
);
240 add_entry(&last_parent
,&last_entry
,entry
);
244 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Invalid play entry %s\n",argv
[i
]);
247 } else { // dvd:// or dvd://x entry
248 play_tree_add_file(entry
,argv
[i
]);
251 play_tree_add_file(entry
,argv
[i
]);
254 // Lock stdin if it will be used as input
255 if(strcasecmp(argv
[i
],"-") == 0)
256 m_config_set_option(config
,"noconsolecontrols",NULL
);
257 add_entry(&last_parent
,&last_entry
,entry
);
258 UNSET_GLOBAL
; // We start entry specific options
266 if(last_parent
!= root
)
267 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Missing }- ?\n");
272 play_tree_free(root
,1);