3 /// \ingroup ConfigParsers Playtree
22 static int recursion_depth
= 0;
29 #define dvd_range(a) (a>0 && a<256)
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)
35 static int is_entry_option(char *opt
, char *param
, play_tree_t
** ret
) {
36 play_tree_t
* entry
= NULL
;
40 if(strcasecmp(opt
,"playlist") == 0) { // We handle playlist here
42 return M_OPT_MISSING_PARAM
;
44 entry
= parse_playlist_file(param
);
55 static inline void add_entry(play_tree_t
**last_parentp
,
56 play_tree_t
**last_entryp
, play_tree_t
*entry
) {
57 if(*last_entryp
== NULL
)
58 play_tree_set_child(*last_parentp
,entry
);
60 play_tree_append_entry(*last_entryp
,entry
);
64 /// Setup the \ref Config from command line arguments and build a playtree.
65 /** \ingroup ConfigParsers
68 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
)
70 int i
,j
,start_title
=-1,end_title
=-1;
71 char *opt
,*splitpos
=NULL
;
74 int opt_exit
= 0; // flag indicating whether mplayer should exit without playing anything
75 play_tree_t
*last_parent
, *last_entry
= NULL
, *root
;
76 #ifdef MACOSX_FINDER_SUPPORT
77 extern play_tree_t
*macosx_finder_args(m_config_t
*, int , char **);
81 assert(config
!= NULL
);
86 config
->mode
= M_COMMAND_LINE
;
88 #ifdef MACOSX_FINDER_SUPPORT
89 root
=macosx_finder_args(config
, argc
, argv
);
94 last_parent
= root
= play_tree_new();
95 /* in order to work recursion detection properly in parse_config_file */
98 for (i
= 1; i
< argc
; i
++) {
101 /* check for -- (no more options id.) except --help! */
102 if ((*opt
== '-') && (*(opt
+1) == '-') && (*(opt
+2) == 0))
107 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, MSGTR_NoFileGivenOnCommandLine
);
112 if((opt
[0] == '{') && (opt
[1] == '\0'))
114 play_tree_t
* entry
= play_tree_new();
116 if(last_parent
->flags
& PLAY_TREE_RND
)
117 entry
->flags
|= PLAY_TREE_RND
;
118 if(last_entry
== NULL
) {
119 play_tree_set_child(last_parent
,entry
);
121 play_tree_append_entry(last_entry
,entry
);
128 if((opt
[0] == '}') && (opt
[1] == '\0'))
130 if( ! last_parent
|| ! last_parent
->parent
) {
131 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "too much }-\n");
134 last_entry
= last_parent
;
135 last_parent
= last_entry
->parent
;
139 if ((no_more_opts
== 0) && (*opt
== '-') && (*(opt
+1) != 0)) /* option */
142 /* remove trailing '-' */
145 mp_msg(MSGT_CFGPARSER
, MSGL_DBG3
, "this_opt = option: %s\n", opt
);
146 // We handle here some specific option
147 // Loop option when it apply to a group
148 if(strcasecmp(opt
,"loop") == 0 &&
149 (! last_entry
|| last_entry
->child
) ) {
152 l
= (i
+1<argc
) ? strtol(argv
[i
+1],&end
,0) : 0;
153 if(!end
|| *end
!= '\0') {
154 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, MSGTR_TheLoopOptionMustBeAnInteger
, argv
[i
+1]);
155 tmp
= ERR_OUT_OF_RANGE
;
157 play_tree_t
* pt
= last_entry
? last_entry
: last_parent
;
162 } else if(strcasecmp(opt
,"shuffle") == 0) {
163 if(last_entry
&& last_entry
->child
)
164 last_entry
->flags
|= PLAY_TREE_RND
;
166 last_parent
->flags
|= PLAY_TREE_RND
;
167 } else if(strcasecmp(opt
,"noshuffle") == 0) {
168 if(last_entry
&& last_entry
->child
)
169 last_entry
->flags
&= ~PLAY_TREE_RND
;
171 last_parent
->flags
&= ~PLAY_TREE_RND
;
173 const m_option_t
* mp_opt
= NULL
;
174 play_tree_t
* entry
= NULL
;
176 tmp
= is_entry_option(opt
,(i
+1<argc
) ? argv
[i
+ 1] : NULL
,&entry
);
177 if(tmp
> 0) { // It's an entry
179 add_entry(&last_parent
,&last_entry
,entry
);
180 if((last_parent
->flags
& PLAY_TREE_RND
) && entry
->child
)
181 entry
->flags
|= PLAY_TREE_RND
;
183 } else if(mode
== LOCAL
) // Entry is empty we have to drop his params
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
))
189 tmp
= (i
+1<argc
) ? m_config_set_option(config
, opt
, argv
[i
+ 1])
190 : m_config_set_option(config
, opt
, NULL
);
192 tmp
= m_config_check_option(config
, opt
, (i
+1<argc
) ? argv
[i
+ 1] : NULL
);
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]);
200 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, MSGTR_UnknownOptionOnCommandLine
, opt
);
205 if (tmp
<= M_OPT_EXIT
) {
207 tmp
= M_OPT_EXIT
- tmp
;
210 mp_msg(MSGT_CFGPARSER
, MSGL_FATAL
, MSGTR_ErrorParsingOptionOnCommandLine
, opt
);
217 play_tree_t
* entry
= play_tree_new();
218 mp_msg(MSGT_CFGPARSER
, MSGL_DBG2
,"Adding file %s\n",argv
[i
]);
219 // if required expand DVD filename entries like dvd://1-3 into component titles
220 if ( strstr(argv
[i
],"dvd://") != NULL
)
222 splitpos
=strstr(argv
[i
]+6,"-");
225 start_title
=strtol(argv
[i
]+6,NULL
,10);
226 if (start_title
<0) { //entries like dvd://-2 start title implied 1
227 end_title
=abs(start_title
);
230 end_title
=strtol(splitpos
+1,NULL
,10);
233 if (dvd_range(start_title
) && dvd_range(end_title
) && (start_title
<end_title
))
235 for (j
=start_title
;j
<=end_title
;j
++)
238 entry
=play_tree_new();
239 snprintf(entbuf
,9,"dvd://%d",j
);
240 play_tree_add_file(entry
,entbuf
);
241 add_entry(&last_parent
,&last_entry
,entry
);
245 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, MSGTR_InvalidPlayEntry
, argv
[i
]);
248 } else { // dvd:// or dvd://x entry
249 play_tree_add_file(entry
,argv
[i
]);
252 play_tree_add_file(entry
,argv
[i
]);
255 // Lock stdin if it will be used as input
256 if(strcasecmp(argv
[i
],"-") == 0)
257 m_config_set_option(config
,"noconsolecontrols",NULL
);
258 add_entry(&last_parent
,&last_entry
,entry
);
259 UNSET_GLOBAL
; // We start entry specific options
267 if(last_parent
!= root
)
268 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Missing }- ?\n");
273 play_tree_free(root
,1);