17 static int recursion_depth
= 0;
24 #define UNSET_GLOBAL (mode = LOCAL)
25 // Use this 1 if you want to have only global option (no per file option)
26 // #define UNSET_GLOBAL (mode = GLOBAL)
29 static int is_entry_option(char *opt
, char *param
, play_tree_t
** ret
) {
30 play_tree_t
* entry
= NULL
;
34 if(strcasecmp(opt
,"playlist") == 0) { // We handle playlist here
36 return M_OPT_MISSING_PARAM
;
37 entry
= parse_playlist_file(param
);
49 static inline void add_entry(play_tree_t
**last_parentp
,
50 play_tree_t
**last_entryp
, play_tree_t
*entry
) {
51 if(*last_entryp
== NULL
)
52 play_tree_set_child(*last_parentp
,entry
);
54 play_tree_append_entry(*last_entryp
,entry
);
59 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
)
65 play_tree_t
*last_parent
, *last_entry
= NULL
, *root
;
68 assert(config
!= NULL
);
73 config
->mode
= M_COMMAND_LINE
;
75 last_parent
= root
= play_tree_new();
76 /* in order to work recursion detection properly in parse_config_file */
79 for (i
= 1; i
< argc
; i
++) {
82 /* check for -- (no more options id.) except --help! */
83 if ((*opt
== '-') && (*(opt
+1) == '-') && (*(opt
+2) != 'h'))
88 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "You added '--' but no filenames presented!\n");
93 if((opt
[0] == '{') && (opt
[1] == '\0'))
95 play_tree_t
* entry
= play_tree_new();
97 if(last_parent
->flags
& PLAY_TREE_RND
)
98 entry
->flags
|= PLAY_TREE_RND
;
99 if(last_entry
== NULL
) {
100 play_tree_set_child(last_parent
,entry
);
102 play_tree_append_entry(last_entry
,entry
);
109 if((opt
[0] == '}') && (opt
[1] == '\0'))
111 if( ! last_parent
|| ! last_parent
->parent
) {
112 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "too much }-\n");
115 last_entry
= last_parent
;
116 last_parent
= last_entry
->parent
;
120 if ((no_more_opts
== 0) && (*opt
== '-') && (*(opt
+1) != 0)) /* option */
122 /* remove trailing '-' */
125 mp_msg(MSGT_CFGPARSER
, MSGL_DBG3
, "this_opt = option: %s\n", opt
);
126 // We handle here some specific option
127 if(strcasecmp(opt
,"list-options") == 0) {
128 m_config_print_option_list(config
);
130 // Loop option when it apply to a group
131 } else if(strcasecmp(opt
,"loop") == 0 &&
132 (! last_entry
|| last_entry
->child
) ) {
135 l
= (i
+1<argc
) ? strtol(argv
[i
+1],&end
,0) : 0;
137 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "The loop option must be an integer: %s\n",argv
[i
+1]);
138 tmp
= ERR_OUT_OF_RANGE
;
140 play_tree_t
* pt
= last_entry
? last_entry
: last_parent
;
145 } else if(strcasecmp(opt
,"shuffle") == 0) {
146 if(last_entry
&& last_entry
->child
)
147 last_entry
->flags
|= PLAY_TREE_RND
;
149 last_parent
->flags
|= PLAY_TREE_RND
;
150 } else if(strcasecmp(opt
,"noshuffle") == 0) {
151 if(last_entry
&& last_entry
->child
)
152 last_entry
->flags
&= ~PLAY_TREE_RND
;
154 last_parent
->flags
&= ~PLAY_TREE_RND
;
156 m_option_t
* mp_opt
= NULL
;
157 play_tree_t
* entry
= NULL
;
159 tmp
= is_entry_option(opt
,(i
+1<argc
) ? argv
[i
+ 1] : NULL
,&entry
);
160 if(tmp
> 0) { // It's an entry
162 add_entry(&last_parent
,&last_entry
,entry
);
163 if((last_parent
->flags
& PLAY_TREE_RND
) && entry
->child
)
164 entry
->flags
|= PLAY_TREE_RND
;
166 } else if(mode
== LOCAL
) // Entry is empty we have to drop his params
168 } else if(tmp
== 0) { // 'normal' options
169 mp_opt
= m_config_get_option(config
,opt
);
170 if (mp_opt
!= NULL
) { // Option exist
171 if(mode
== GLOBAL
|| (mp_opt
->flags
& M_OPT_GLOBAL
))
172 tmp
= (i
+1<argc
) ? m_config_set_option(config
, opt
, argv
[i
+ 1])
173 : m_config_set_option(config
, opt
, NULL
);
175 tmp
= m_config_check_option(config
, opt
, (i
+1<argc
) ? argv
[i
+ 1] : NULL
);
176 if(tmp
>= 0 && mode
!= DROP_LOCAL
) {
177 play_tree_t
* pt
= last_entry
? last_entry
: last_parent
;
178 play_tree_set_param(pt
,opt
, argv
[i
+ 1]);
183 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "Unknown option on the command line: %s\n",opt
);
189 if (tmp
== M_OPT_EXIT
)
197 play_tree_t
* entry
= play_tree_new();
198 mp_msg(MSGT_CFGPARSER
, MSGL_DBG2
,"Adding file %s\n",argv
[i
]);
199 play_tree_add_file(entry
,argv
[i
]);
200 // Lock stdin if it will be used as input
201 if(strcasecmp(argv
[i
],"-") == 0)
202 m_config_set_option(config
,"use-stdin",NULL
);
203 add_entry(&last_parent
,&last_entry
,entry
);
204 UNSET_GLOBAL
; // We start entry specific options
210 if(last_parent
!= root
)
211 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Missing }- ?\n");
216 play_tree_free(root
,1);