annotate parser-mpcmd.c @ 9252:b1533eba7231

I haven't read eyck@incubus for 2 years. I do read eyck@ghost.anime.pl
author eyck
date Mon, 03 Feb 2003 14:23:25 +0000
parents 2c1aee5bb754
children 264cb5f03131
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
1
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
2 #include "config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
3
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
4 #ifdef NEW_CONFIG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
5
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
6 #include <stdio.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
7 #include <stdlib.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
8 #include <string.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
9 #include <errno.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
10
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
11 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
12 #include <assert.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
13 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
14
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
15 #include "mp_msg.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
16 #include "m_option.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
17 #include "m_config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
18 #include "playtree.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
19
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
20 static int recursion_depth = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
21 static int mode = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
22
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
23 #define GLOBAL 0
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
24 #define LOCAL 1
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
25 #define DROP_LOCAL 2
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
26
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
27 #define UNSET_GLOBAL (mode = LOCAL)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
28 // Use this 1 if you want to have only global option (no per file option)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
29 // #define UNSET_GLOBAL (mode = GLOBAL)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
30
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
31
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
32 static int is_entry_option(char *opt, char *param, play_tree_t** ret) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
33 play_tree_t* entry = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
34
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
35 *ret = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
36
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
37 if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
38 if(!param)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
39 return M_OPT_MISSING_PARAM;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
40 entry = parse_playlist_file(param);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
41 if(!entry)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
42 return 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
43 } else if(strcasecmp(opt,"vcd") == 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
44 char* s;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
45 if(!param)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
46 return M_OPT_MISSING_PARAM;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
47 s = (char*)malloc((strlen(param) + 6 + 1)*sizeof(char));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
48 sprintf(s,"vcd://%s",param);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
49 entry = play_tree_new();
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
50 play_tree_add_file(entry,s);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
51 free(s);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
52 } else if(strcasecmp(opt,"dvd") == 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
53 char* s;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
54 if(!param)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
55 return M_OPT_MISSING_PARAM;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
56 s = (char*)malloc((strlen(param) + 6 + 1)*sizeof(char));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
57 sprintf(s,"dvd://%s",param);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
58 entry = play_tree_new();
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
59 play_tree_add_file(entry,s);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
60 free(s);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
61 } else if(strcasecmp(opt,"tv") == 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
62 char *s,*pr,*prs;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
63 char *ps,*pe,*channel=NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
64 char *as;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
65 int on=0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
66
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
67 if(!param)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
68 return M_OPT_MISSING_PARAM;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
69 ps = param;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
70 pe = strchr(param,':');
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
71 pr = prs = (char*)malloc((strlen(param)+1)*sizeof(char));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
72 pr[0] = '\0';
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
73 while(ps) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
74 if(!pe)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
75 pe = ps + strlen(ps);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
76
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
77 as = strchr(ps,'=');
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
78 if(as && as[1] != '\0' && pe-as > 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
79 as++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
80 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
81 as = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
82 if( !as && pe-ps == 2 && strncasecmp("on",ps,2) == 0 )
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
83 on = 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
84 else if(as && as-ps == 8 && strncasecmp("channel",ps,6) == 0 && pe-as > 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
85 channel = (char*)realloc(channel,(pe-as+1)*sizeof(char));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
86 strncpy(channel,as,pe-as);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
87 channel[pe-as] = '\0';
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
88 } else if(pe-ps > 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
89 if(prs != pr) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
90 prs[0] = ':';
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
91 prs++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
92 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
93 strncpy(prs,ps,pe-ps);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
94 prs += pe-ps;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
95 prs[0] = '\0';
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
96 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
97
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
98 if(pe[0] != '\0') {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
99 ps = pe+1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
100 pe = strchr(ps,':');
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
101 } else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
102 ps = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
103 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
104
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
105 if(on) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
106 int l=5;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
107
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
108 if(channel)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
109 l += strlen(channel);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
110 s = (char*) malloc((l+1)*sizeof(char));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
111 if(channel)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
112 sprintf(s,"tv://%s",channel);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
113 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
114 sprintf(s,"tv://");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
115 entry = play_tree_new();
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
116 play_tree_add_file(entry,s);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
117 if(strlen(pr) > 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
118 play_tree_set_param(entry,"tv",pr);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
119 free(s);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
120 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
121 free(pr);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
122 if(channel)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
123 free(channel);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
124
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
125 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
126
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
127 if(entry) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
128 *ret = entry;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
129 return 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
130 } else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
131 return 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
132 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
133
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
134 play_tree_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
135 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
136 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
137 int i;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
138 int tmp = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
139 char *opt;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
140 int no_more_opts = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
141 play_tree_t *last_parent, *last_entry = NULL, *root;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
142 void add_entry(play_tree_t *entry) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
143 if(last_entry == NULL)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
144 play_tree_set_child(last_parent,entry);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
145 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
146 play_tree_append_entry(last_entry,entry);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
147 last_entry = entry;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
148 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
149
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
150 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
151 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
152 assert(argv != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
153 assert(argc >= 1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
154 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
155
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
156 config->mode = M_COMMAND_LINE;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
157 mode = GLOBAL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
158 last_parent = root = play_tree_new();
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
159 /* in order to work recursion detection properly in parse_config_file */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
160 ++recursion_depth;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
161
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
162 for (i = 1; i < argc; i++) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
163 //next:
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
164 opt = argv[i];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
165 /* check for -- (no more options id.) except --help! */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
166 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) != 'h'))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
167 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
168 no_more_opts = 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
169 if (i+1 >= argc)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
170 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
171 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "You added '--' but no filenames presented!\n");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
172 goto err_out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
173 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
174 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
175 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
176 if((opt[0] == '{') && (opt[1] == '\0'))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
177 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
178 play_tree_t* entry = play_tree_new();
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
179 UNSET_GLOBAL;
8175
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
180 if(last_parent->flags & PLAY_TREE_RND)
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
181 entry->flags |= PLAY_TREE_RND;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
182 if(last_entry == NULL) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
183 play_tree_set_child(last_parent,entry);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
184 } else {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
185 play_tree_append_entry(last_entry,entry);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
186 last_entry = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
187 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
188 last_parent = entry;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
189 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
190 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
191
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
192 if((opt[0] == '}') && (opt[1] == '\0'))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
193 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
194 if( ! last_parent || ! last_parent->parent) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
195 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
196 goto err_out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
197 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
198 last_entry = last_parent;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
199 last_parent = last_entry->parent;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
200 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
201 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
202
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
203 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
204 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
205 /* remove trailing '-' */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
206 opt++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
207
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
208 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
209 // We handle here some specific option
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
210 if(strcasecmp(opt,"list-options") == 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
211 m_config_print_option_list(config);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
212 exit(1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
213 // Loop option when it apply to a group
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
214 } else if(strcasecmp(opt,"loop") == 0 &&
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
215 (! last_entry || last_entry->child) ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
216 int l;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
217 char* end;
8400
587b62cd4119 10l noticed by "Puk Madick" <pingy@swirvemail.com>
arpi
parents: 8175
diff changeset
218 l = (i+1<argc) ? strtol(argv[i+1],&end,0) : 0;
9106
2c1aee5bb754 Ok, firstly fixed the bug in parser-mpcmd.c where it
arpi
parents: 8458
diff changeset
219 if(*end != '\0') {
2c1aee5bb754 Ok, firstly fixed the bug in parser-mpcmd.c where it
arpi
parents: 8458
diff changeset
220 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The loop option must be an integer: %s\n",argv[i+1]);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
221 tmp = ERR_OUT_OF_RANGE;
9106
2c1aee5bb754 Ok, firstly fixed the bug in parser-mpcmd.c where it
arpi
parents: 8458
diff changeset
222 } else {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
223 play_tree_t* pt = last_entry ? last_entry : last_parent;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
224 l = l <= 0 ? -1 : l;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
225 pt->loop = l;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
226 tmp = 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
227 }
8452
418b0017a8d2 -rnd --> -shuffle
diego
parents: 8426
diff changeset
228 } else if(strcasecmp(opt,"shuffle") == 0) {
8175
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
229 if(last_entry && last_entry->child)
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
230 last_entry->flags |= PLAY_TREE_RND;
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
231 else
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
232 last_parent->flags |= PLAY_TREE_RND;
8452
418b0017a8d2 -rnd --> -shuffle
diego
parents: 8426
diff changeset
233 } else if(strcasecmp(opt,"noshuffle") == 0) {
8175
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
234 if(last_entry && last_entry->child)
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
235 last_entry->flags &= ~PLAY_TREE_RND;
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
236 else
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
237 last_parent->flags &= ~PLAY_TREE_RND;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
238 } else {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
239 m_option_t* mp_opt = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
240 play_tree_t* entry = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
241
8458
92a7bf835d98 2*10l=20l
arpi
parents: 8452
diff changeset
242 tmp = is_entry_option(opt,(i+1<argc) ? argv[i + 1] : NULL,&entry);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
243 if(tmp > 0) { // It's an entry
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
244 if(entry) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
245 add_entry(entry);
8175
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
246 if((last_parent->flags & PLAY_TREE_RND) && entry->child)
bf5d1da56ecd Basic support for random playing (-rnd and -nornd)
albeu
parents: 8164
diff changeset
247 entry->flags |= PLAY_TREE_RND;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
248 UNSET_GLOBAL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
249 } else if(mode == LOCAL) // Entry is empty we have to drop his params
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
250 mode = DROP_LOCAL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
251 } else if(tmp == 0) { // 'normal' options
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
252 mp_opt = m_config_get_option(config,opt);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
253 if (mp_opt != NULL) { // Option exist
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
254 if(mode == GLOBAL || (mp_opt->flags & M_OPT_GLOBAL))
8426
ca2813aafb35 more i+1<argc checks
arpi
parents: 8400
diff changeset
255 tmp = (i+1<argc) ? m_config_set_option(config, opt, argv[i + 1])
ca2813aafb35 more i+1<argc checks
arpi
parents: 8400
diff changeset
256 : m_config_set_option(config, opt, NULL);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
257 else {
8458
92a7bf835d98 2*10l=20l
arpi
parents: 8452
diff changeset
258 tmp = m_config_check_option(config, opt, (i+1<argc) ? argv[i + 1] : NULL);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
259 if(tmp >= 0 && mode != DROP_LOCAL) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
260 play_tree_t* pt = last_entry ? last_entry : last_parent;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
261 play_tree_set_param(pt,opt, argv[i + 1]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
262 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
263 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
264 } else {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
265 tmp = M_OPT_UNKNOW;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
266 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknow option on the command line: %s\n",opt);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
267 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
268 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
269 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
270
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
271 if (tmp < 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
272 goto err_out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
273 i += tmp;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
274 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
275 else /* filename */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
276 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
277 play_tree_t* entry = play_tree_new();
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
278 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
279 play_tree_add_file(entry,argv[i]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
280 // Lock stdin if it will be used as input
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
281 if(strcasecmp(argv[i],"-") == 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
282 m_config_set_option(config,"use-stdin",NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
283 add_entry(entry);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
284 UNSET_GLOBAL; // We start entry specific options
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
285
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
286 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
287 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
288
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
289 --recursion_depth;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
290 if(last_parent != root)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
291 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
292 return root;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
293
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
294 err_out:
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
295 --recursion_depth;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
296 play_tree_free(root,1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
297 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
298 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
299
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
300 #endif