17 static int recursion_depth
= 0;
24 #define dvd_range(a) (a>0 && a<256)
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)
30 static int is_entry_option(char *opt
, char *param
, play_tree_t
** ret
) {
31 play_tree_t
* entry
= NULL
;
35 if(strcasecmp(opt
,"playlist") == 0) { // We handle playlist here
37 return M_OPT_MISSING_PARAM
;
39 entry
= parse_playlist_file(param
);
50 static inline void add_entry(play_tree_t
**last_parentp
,
51 play_tree_t
**last_entryp
, play_tree_t
*entry
) {
52 if(*last_entryp
== NULL
)
53 play_tree_set_child(*last_parentp
,entry
);
55 play_tree_append_entry(*last_entryp
,entry
);
60 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
)
62 int i
,j
,start_title
=-1,end_title
=-1;
64 char *opt
,*splitpos
=NULL
;
67 play_tree_t
*last_parent
, *last_entry
= NULL
, *root
;
70 assert(config
!= NULL
);
75 config
->mode
= M_COMMAND_LINE
;
77 last_parent
= root
= play_tree_new();
78 /* in order to work recursion detection properly in parse_config_file */
81 for (i
= 1; i
< argc
; i
++) {
84 /* check for -- (no more options id.) except --help! */
85 if ((*opt
== '-') && (*(opt
+1) == '-') && (*(opt
+2) != 'h'))
90 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "You added '--' but no filenames presented!\n");
95 if((opt
[0] == '{') && (opt
[1] == '\0'))
97 play_tree_t
* entry
= play_tree_new();
99 if(last_parent
->flags
& PLAY_TREE_RND
)
100 entry
->flags
|= PLAY_TREE_RND
;
101 if(last_entry
== NULL
) {
102 play_tree_set_child(last_parent
,entry
);
104 play_tree_append_entry(last_entry
,entry
);
111 if((opt
[0] == '}') && (opt
[1] == '\0'))
113 if( ! last_parent
|| ! last_parent
->parent
) {
114 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "too much }-\n");
117 last_entry
= last_parent
;
118 last_parent
= last_entry
->parent
;
122 if ((no_more_opts
== 0) && (*opt
== '-') && (*(opt
+1) != 0)) /* option */
124 /* remove trailing '-' */
127 mp_msg(MSGT_CFGPARSER
, MSGL_DBG3
, "this_opt = option: %s\n", opt
);
128 // We handle here some specific option
129 if(strcasecmp(opt
,"list-options") == 0) {
130 m_config_print_option_list(config
);
132 // Loop option when it apply to a group
133 } else if(strcasecmp(opt
,"loop") == 0 &&
134 (! last_entry
|| last_entry
->child
) ) {
137 l
= (i
+1<argc
) ? strtol(argv
[i
+1],&end
,0) : 0;
139 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "The loop option must be an integer: %s\n",argv
[i
+1]);
140 tmp
= ERR_OUT_OF_RANGE
;
142 play_tree_t
* pt
= last_entry
? last_entry
: last_parent
;
147 } else if(strcasecmp(opt
,"shuffle") == 0) {
148 if(last_entry
&& last_entry
->child
)
149 last_entry
->flags
|= PLAY_TREE_RND
;
151 last_parent
->flags
|= PLAY_TREE_RND
;
152 } else if(strcasecmp(opt
,"noshuffle") == 0) {
153 if(last_entry
&& last_entry
->child
)
154 last_entry
->flags
&= ~PLAY_TREE_RND
;
156 last_parent
->flags
&= ~PLAY_TREE_RND
;
158 m_option_t
* mp_opt
= NULL
;
159 play_tree_t
* entry
= NULL
;
161 tmp
= is_entry_option(opt
,(i
+1<argc
) ? argv
[i
+ 1] : NULL
,&entry
);
162 if(tmp
> 0) { // It's an entry
164 add_entry(&last_parent
,&last_entry
,entry
);
165 if((last_parent
->flags
& PLAY_TREE_RND
) && entry
->child
)
166 entry
->flags
|= PLAY_TREE_RND
;
168 } else if(mode
== LOCAL
) // Entry is empty we have to drop his params
170 } else if(tmp
== 0) { // 'normal' options
171 mp_opt
= m_config_get_option(config
,opt
);
172 if (mp_opt
!= NULL
) { // Option exist
173 if(mode
== GLOBAL
|| (mp_opt
->flags
& M_OPT_GLOBAL
))
174 tmp
= (i
+1<argc
) ? m_config_set_option(config
, opt
, argv
[i
+ 1])
175 : m_config_set_option(config
, opt
, NULL
);
177 tmp
= m_config_check_option(config
, opt
, (i
+1<argc
) ? argv
[i
+ 1] : NULL
);
178 if(tmp
>= 0 && mode
!= DROP_LOCAL
) {
179 play_tree_t
* pt
= last_entry
? last_entry
: last_parent
;
180 play_tree_set_param(pt
,opt
, argv
[i
+ 1]);
185 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "Unknown option on the command line: %s\n",opt
);
191 if (tmp
== M_OPT_EXIT
)
199 play_tree_t
* entry
= play_tree_new();
200 mp_msg(MSGT_CFGPARSER
, MSGL_DBG2
,"Adding file %s\n",argv
[i
]);
201 // if required expand DVD filename entries like dvd://1-3 into component titles
202 if ( strstr(argv
[i
],"dvd://") != NULL
)
204 splitpos
=strstr(argv
[i
]+6,"-");
207 start_title
=strtol(argv
[i
]+6,NULL
,10);
208 if (start_title
<0) { //entries like dvd://-2 start title implied 1
209 end_title
=abs(start_title
);
212 end_title
=strtol(splitpos
+1,NULL
,10);
215 if (dvd_range(start_title
) && dvd_range(end_title
) && (start_title
<end_title
))
217 for (j
=start_title
;j
<=end_title
;j
++)
220 entry
=play_tree_new();
221 snprintf(entbuf
,9,"dvd://%d",j
);
222 play_tree_add_file(entry
,entbuf
);
223 add_entry(&last_parent
,&last_entry
,entry
);
227 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Invalid play entry %s\n",argv
[i
]);
230 } else { // dvd:// or dvd://x entry
231 play_tree_add_file(entry
,argv
[i
]);
234 play_tree_add_file(entry
,argv
[i
]);
237 // Lock stdin if it will be used as input
238 if(strcasecmp(argv
[i
],"-") == 0)
239 m_config_set_option(config
,"noconsolecontrols",NULL
);
240 add_entry(&last_parent
,&last_entry
,entry
);
241 UNSET_GLOBAL
; // We start entry specific options
247 if(last_parent
!= root
)
248 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Missing }- ?\n");
253 play_tree_free(root
,1);