Mercurial > mplayer.hg
annotate m_config.c @ 30673:cfb6e0b4e2bd
Mark sleep_accurate() as static, it is only used within the file.
author | diego |
---|---|
date | Mon, 22 Feb 2010 21:53:06 +0000 |
parents | e9b902ad0ddb |
children | a26f6577d338 |
rev | line source |
---|---|
30429
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
1 /* |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
2 * This file is part of MPlayer. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
3 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
7 * (at your option) any later version. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
8 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
12 * GNU General Public License for more details. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
13 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
17 */ |
18258 | 18 |
19 /// \file | |
20 /// \ingroup Config | |
21 | |
8164 | 22 #include "config.h" |
23 | |
24 #include <stdlib.h> | |
25 #include <stdio.h> | |
26 #include <errno.h> | |
27 #include <string.h> | |
28 #ifdef MP_DEBUG | |
29 #include <assert.h> | |
30 #endif | |
31 | |
32 #include "m_config.h" | |
33 #include "m_option.h" | |
34 #include "mp_msg.h" | |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
10595
diff
changeset
|
35 #include "help_mp.h" |
8164 | 36 |
17471 | 37 #define MAX_PROFILE_DEPTH 20 |
38 | |
39 static int | |
26288 | 40 parse_profile(const m_option_t *opt, const char *name, char *param, void *dst, int src); |
17471 | 41 |
42 static void | |
26288 | 43 set_profile(const m_option_t *opt, void* dst, void* src); |
17471 | 44 |
45 static int | |
46 show_profile(m_option_t *opt, char* name, char *param); | |
47 | |
48 static void | |
25225
51c23a18a17b
First try to mark some things in m_config correctly as const
reimar
parents:
23868
diff
changeset
|
49 m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefix); |
17471 | 50 |
17472
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
51 static int |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
52 list_options(m_option_t *opt, char* name, char *param); |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
53 |
8164 | 54 m_config_t* |
55 m_config_new(void) { | |
56 m_config_t* config; | |
25962 | 57 static int initialized = 0; |
17471 | 58 static m_option_type_t profile_opt_type; |
59 static m_option_t ref_opts[] = { | |
60 { "profile", NULL, &profile_opt_type, CONF_NOSAVE, 0, 0, NULL }, | |
61 { "show-profile", show_profile, CONF_TYPE_PRINT_FUNC, CONF_NOCFG, 0, 0, NULL }, | |
17472
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
62 { "list-options", list_options, CONF_TYPE_PRINT_FUNC, CONF_NOCFG, 0, 0, NULL }, |
17471 | 63 { NULL, NULL, NULL, 0, 0, 0, NULL } |
64 }; | |
65 int i; | |
8164 | 66 |
18879 | 67 config = calloc(1,sizeof(m_config_t)); |
8164 | 68 config->lvl = 1; // 0 Is the defaults |
25962 | 69 if(!initialized) { |
70 initialized = 1; | |
17471 | 71 profile_opt_type = m_option_type_string_list; |
72 profile_opt_type.parse = parse_profile; | |
73 profile_opt_type.set = set_profile; | |
74 } | |
75 config->self_opts = malloc(sizeof(ref_opts)); | |
76 memcpy(config->self_opts,ref_opts,sizeof(ref_opts)); | |
77 for(i = 0 ; config->self_opts[i].name ; i++) | |
78 config->self_opts[i].priv = config; | |
79 m_config_register_options(config,config->self_opts); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
80 |
8164 | 81 return config; |
82 } | |
83 | |
84 void | |
85 m_config_free(m_config_t* config) { | |
86 m_config_option_t *i = config->opts, *ct; | |
87 m_config_save_slot_t *sl,*st; | |
17471 | 88 m_profile_t *p,*pn; |
89 int j; | |
8164 | 90 |
91 #ifdef MP_DEBUG | |
92 assert(config != NULL); | |
93 #endif | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
94 |
8164 | 95 while(i) { |
13824 | 96 if (i->flags & M_CFG_OPT_ALIAS) |
97 sl = NULL; | |
98 else | |
99 sl = i->slots; | |
8164 | 100 while(sl) { |
101 m_option_free(i->opt,sl->data); | |
102 st = sl->prev; | |
103 free(sl); | |
104 sl = st; | |
105 } | |
106 if(i->name != i->opt->name) | |
107 free(i->name); | |
108 ct = i->next; | |
109 free(i); | |
13824 | 110 i = ct; |
8164 | 111 } |
17471 | 112 for(p = config->profiles ; p ; p = pn) { |
113 pn = p->next; | |
114 free(p->name); | |
115 if(p->desc) free(p->desc); | |
116 for(j = 0 ; j < p->num_opts ; j++) { | |
117 free(p->opts[2*j]); | |
118 if(p->opts[2*j+1]) free(p->opts[2*j+1]); | |
119 } | |
120 free(p->opts); | |
121 free(p); | |
122 } | |
123 free(config->self_opts); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
124 free(config); |
8164 | 125 } |
126 | |
127 void | |
128 m_config_push(m_config_t* config) { | |
129 m_config_option_t *co; | |
130 m_config_save_slot_t *slot; | |
131 | |
132 #ifdef MP_DEBUG | |
133 assert(config != NULL); | |
134 assert(config->lvl > 0); | |
135 #endif | |
136 | |
137 config->lvl++; | |
138 | |
139 for(co = config->opts ; co ; co = co->next ) { | |
140 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) | |
141 continue; | |
142 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE)) | |
143 continue; | |
21054
7d5035aafcc6
Fix obvious typo, although the exact effect is still unclear to me, see also bug #593.
reimar
parents:
18879
diff
changeset
|
144 if((co->opt->flags & M_OPT_OLD) && !(co->flags & M_CFG_OPT_SET)) |
9912
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
145 continue; |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
146 if(co->flags & M_CFG_OPT_ALIAS) |
8164 | 147 continue; |
148 | |
149 // Update the current status | |
150 m_option_save(co->opt,co->slots->data,co->opt->p); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
151 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
152 // Allocate a new slot |
18879 | 153 slot = calloc(1,sizeof(m_config_save_slot_t) + co->opt->type->size); |
8164 | 154 slot->lvl = config->lvl; |
155 slot->prev = co->slots; | |
156 co->slots = slot; | |
157 m_option_copy(co->opt,co->slots->data,co->slots->prev->data); | |
9912
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
158 // Reset our set flag |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
159 co->flags &= ~M_CFG_OPT_SET; |
8164 | 160 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
161 |
8164 | 162 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config pushed level is now %d\n",config->lvl); |
163 } | |
164 | |
165 void | |
166 m_config_pop(m_config_t* config) { | |
167 m_config_option_t *co; | |
168 m_config_save_slot_t *slot; | |
169 | |
170 #ifdef MP_DEBUG | |
171 assert(config != NULL); | |
172 assert(config->lvl > 1); | |
173 #endif | |
174 | |
175 for(co = config->opts ; co ; co = co->next ) { | |
176 int pop = 0; | |
177 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) | |
178 continue; | |
179 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE)) | |
180 continue; | |
9912
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
181 if(co->flags & M_CFG_OPT_ALIAS) |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
182 continue; |
8164 | 183 if(co->slots->lvl > config->lvl) |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
10595
diff
changeset
|
184 mp_msg(MSGT_CFGPARSER, MSGL_WARN,MSGTR_SaveSlotTooOld,config->lvl,co->slots->lvl); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
185 |
8164 | 186 while(co->slots->lvl >= config->lvl) { |
187 m_option_free(co->opt,co->slots->data); | |
188 slot = co->slots; | |
189 co->slots = slot->prev; | |
190 free(slot); | |
191 pop++; | |
192 } | |
193 if(pop) // We removed some ctx -> set the previous value | |
194 m_option_set(co->opt,co->opt->p,co->slots->data); | |
195 } | |
196 | |
197 config->lvl--; | |
198 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config poped level=%d\n",config->lvl); | |
199 } | |
200 | |
201 static void | |
25225
51c23a18a17b
First try to mark some things in m_config correctly as const
reimar
parents:
23868
diff
changeset
|
202 m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefix) { |
8164 | 203 m_config_option_t *co; |
204 m_config_save_slot_t* sl; | |
205 | |
206 #ifdef MP_DEBUG | |
207 assert(config != NULL); | |
208 assert(config->lvl > 0); | |
209 assert(arg != NULL); | |
210 #endif | |
211 | |
212 // Allocate a new entry for this option | |
18879 | 213 co = calloc(1,sizeof(m_config_option_t) + arg->type->size); |
8164 | 214 co->opt = arg; |
215 | |
216 // Fill in the full name | |
217 if(prefix && strlen(prefix) > 0) { | |
218 int l = strlen(prefix) + 1 + strlen(arg->name) + 1; | |
23806 | 219 co->name = malloc(l); |
8164 | 220 sprintf(co->name,"%s:%s",prefix,arg->name); |
221 } else | |
222 co->name = arg->name; | |
223 | |
23868 | 224 // Option with children -> add them |
8164 | 225 if(arg->type->flags & M_OPT_TYPE_HAS_CHILD) { |
25225
51c23a18a17b
First try to mark some things in m_config correctly as const
reimar
parents:
23868
diff
changeset
|
226 const m_option_t *ol = arg->p; |
8164 | 227 int i; |
13824 | 228 co->slots = NULL; |
8164 | 229 for(i = 0 ; ol[i].name != NULL ; i++) |
230 m_config_add_option(config,&ol[i], co->name); | |
231 } else { | |
9912
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
232 m_config_option_t *i; |
23868 | 233 // Check if there is already an option pointing to this address |
9912
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
234 if(arg->p) { |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
235 for(i = config->opts ; i ; i = i->next ) { |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
236 if(i->opt->p == arg->p) { // So we don't save the same vars more than 1 time |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
237 co->slots = i->slots; |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
238 co->flags |= M_CFG_OPT_ALIAS; |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
239 break; |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
240 } |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
241 } |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
242 } |
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
243 if(!(co->flags & M_CFG_OPT_ALIAS)) { |
8164 | 244 // Allocate a slot for the defaults |
18879 | 245 sl = calloc(1,sizeof(m_config_save_slot_t) + arg->type->size); |
8164 | 246 m_option_save(arg,sl->data,(void**)arg->p); |
23868 | 247 // Hack to avoid too much trouble with dynamically allocated data : |
8164 | 248 // We always use a dynamic version |
249 if((arg->type->flags & M_OPT_TYPE_DYNAMIC) && arg->p && (*(void**)arg->p)) { | |
250 *(void**)arg->p = NULL; | |
251 m_option_set(arg,arg->p,sl->data); | |
252 } | |
253 sl->lvl = 0; | |
13824 | 254 sl->prev = NULL; |
18879 | 255 co->slots = calloc(1,sizeof(m_config_save_slot_t) + arg->type->size); |
8164 | 256 co->slots->prev = sl; |
257 co->slots->lvl = config->lvl; | |
258 m_option_copy(co->opt,co->slots->data,sl->data); | |
9912
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
259 } // !M_OPT_ALIAS |
8164 | 260 } |
261 co->next = config->opts; | |
262 config->opts = co; | |
263 } | |
264 | |
265 int | |
25225
51c23a18a17b
First try to mark some things in m_config correctly as const
reimar
parents:
23868
diff
changeset
|
266 m_config_register_options(m_config_t *config, const m_option_t *args) { |
8164 | 267 int i; |
268 | |
269 #ifdef MP_DEBUG | |
270 assert(config != NULL); | |
271 assert(config->lvl > 0); | |
272 assert(args != NULL); | |
273 #endif | |
274 | |
275 for(i = 0 ; args[i].name != NULL ; i++) | |
276 m_config_add_option(config,&args[i],NULL); | |
277 | |
278 return 1; | |
279 } | |
280 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
281 static m_config_option_t* |
8164 | 282 m_config_get_co(m_config_t *config, char* arg) { |
283 m_config_option_t *co; | |
284 | |
285 for(co = config->opts ; co ; co = co->next ) { | |
286 int l = strlen(co->name) - 1; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
287 if((co->opt->type->flags & M_OPT_TYPE_ALLOW_WILDCARD) && |
8164 | 288 (co->name[l] == '*')) { |
289 if(strncasecmp(co->name,arg,l) == 0) | |
290 return co; | |
291 } else if(strcasecmp(co->name,arg) == 0) | |
292 return co; | |
293 } | |
294 return NULL; | |
295 } | |
296 | |
297 static int | |
298 m_config_parse_option(m_config_t *config, char* arg, char* param,int set) { | |
299 m_config_option_t *co; | |
300 int r = 0; | |
301 | |
302 #ifdef MP_DEBUG | |
303 assert(config != NULL); | |
304 assert(config->lvl > 0); | |
305 assert(arg != NULL); | |
306 #endif | |
307 | |
308 co = m_config_get_co(config,arg); | |
8892 | 309 if(!co){ |
8894 | 310 // mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Unknown option: %s\n",arg); |
10595
522afd56703c
100l to albeu for his english grammar, and 10l to me becouse I noticed that lately (my backward compatibilty macro uses M_OPT_UNKNOWN)
alex
parents:
10594
diff
changeset
|
311 return M_OPT_UNKNOWN; |
8892 | 312 } |
8164 | 313 |
314 #ifdef MP_DEBUG | |
315 // This is the only mandatory function | |
316 assert(co->opt->type->parse); | |
317 #endif | |
318 | |
23868 | 319 // Check if this option isn't forbidden in the current mode |
8164 | 320 if((config->mode == M_CONFIG_FILE) && (co->opt->flags & M_OPT_NOCFG)) { |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
10595
diff
changeset
|
321 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidCfgfileOption,arg); |
8164 | 322 return M_OPT_INVALID; |
323 } | |
324 if((config->mode == M_COMMAND_LINE) && (co->opt->flags & M_OPT_NOCMD)) { | |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
10595
diff
changeset
|
325 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidCmdlineOption,arg); |
8164 | 326 return M_OPT_INVALID; |
327 } | |
26408
7a36d5941fd8
Replace the trivial command line preparser with a more robust version
albeu
parents:
26288
diff
changeset
|
328 // During command line preparse set only pre-parse options |
7a36d5941fd8
Replace the trivial command line preparser with a more robust version
albeu
parents:
26288
diff
changeset
|
329 // Otherwise only set pre-parse option if they were not already set. |
7a36d5941fd8
Replace the trivial command line preparser with a more robust version
albeu
parents:
26288
diff
changeset
|
330 if(((config->mode == M_COMMAND_LINE_PRE_PARSE) && |
7a36d5941fd8
Replace the trivial command line preparser with a more robust version
albeu
parents:
26288
diff
changeset
|
331 !(co->opt->flags & M_OPT_PRE_PARSE)) || |
7a36d5941fd8
Replace the trivial command line preparser with a more robust version
albeu
parents:
26288
diff
changeset
|
332 ((config->mode != M_COMMAND_LINE_PRE_PARSE) && |
7a36d5941fd8
Replace the trivial command line preparser with a more robust version
albeu
parents:
26288
diff
changeset
|
333 (co->opt->flags & M_OPT_PRE_PARSE) && (co->flags & M_CFG_OPT_SET))) |
7a36d5941fd8
Replace the trivial command line preparser with a more robust version
albeu
parents:
26288
diff
changeset
|
334 set = 0; |
8164 | 335 |
23868 | 336 // Option with children are a bit different to parse |
8164 | 337 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) { |
338 char** lst = NULL; | |
339 int i,sr; | |
340 // Parse the child options | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9222
diff
changeset
|
341 r = m_option_parse(co->opt,arg,param,&lst,M_COMMAND_LINE); |
8164 | 342 // Set them now |
8894 | 343 if(r >= 0) |
8164 | 344 for(i = 0 ; lst && lst[2*i] ; i++) { |
345 int l = strlen(co->name) + 1 + strlen(lst[2*i]) + 1; | |
346 if(r >= 0) { | |
347 // Build the full name | |
348 char n[l]; | |
349 sprintf(n,"%s:%s",co->name,lst[2*i]); | |
350 sr = m_config_parse_option(config,n,lst[2*i+1],set); | |
8894 | 351 if(sr < 0){ |
10595
522afd56703c
100l to albeu for his english grammar, and 10l to me becouse I noticed that lately (my backward compatibilty macro uses M_OPT_UNKNOWN)
alex
parents:
10594
diff
changeset
|
352 if(sr == M_OPT_UNKNOWN){ |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
10595
diff
changeset
|
353 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidSuboption,co->name,lst[2*i]); |
8894 | 354 r = M_OPT_INVALID; |
355 } else | |
9222 | 356 if(sr == M_OPT_MISSING_PARAM){ |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
10595
diff
changeset
|
357 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_MissingSuboptionParameter,lst[2*i],co->name); |
9222 | 358 r = M_OPT_INVALID; |
359 } else | |
8894 | 360 r = sr; |
361 } | |
8164 | 362 } |
363 free(lst[2*i]); | |
364 free(lst[2*i+1]); | |
365 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
366 if(lst) free(lst); |
8164 | 367 } else |
368 r = m_option_parse(co->opt,arg,param,set ? co->slots->data : NULL,config->mode); | |
369 | |
370 // Parsing failed ? | |
371 if(r < 0) | |
372 return r; | |
373 // Set the option | |
374 if(set) { | |
375 m_option_set(co->opt,co->opt->p,co->slots->data); | |
9912
39444d65c4cb
Don't save restore all options wich point to the same variable.
albeu
parents:
9593
diff
changeset
|
376 co->flags |= M_CFG_OPT_SET; |
8164 | 377 } |
378 | |
379 return r; | |
380 } | |
381 | |
382 int | |
383 m_config_set_option(m_config_t *config, char* arg, char* param) { | |
384 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Setting %s=%s\n",arg,param); | |
385 return m_config_parse_option(config,arg,param,1); | |
386 } | |
387 | |
388 int | |
389 m_config_check_option(m_config_t *config, char* arg, char* param) { | |
9222 | 390 int r; |
8164 | 391 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Checking %s=%s\n",arg,param); |
9222 | 392 r=m_config_parse_option(config,arg,param,0); |
393 if(r==M_OPT_MISSING_PARAM){ | |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
10595
diff
changeset
|
394 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_MissingOptionParameter,arg); |
9222 | 395 return M_OPT_INVALID; |
396 } | |
397 return r; | |
8164 | 398 } |
399 | |
400 | |
25225
51c23a18a17b
First try to mark some things in m_config correctly as const
reimar
parents:
23868
diff
changeset
|
401 const m_option_t* |
8164 | 402 m_config_get_option(m_config_t *config, char* arg) { |
403 m_config_option_t *co; | |
404 | |
405 #ifdef MP_DEBUG | |
406 assert(config != NULL); | |
407 assert(config->lvl > 0); | |
408 assert(arg != NULL); | |
409 #endif | |
410 | |
411 co = m_config_get_co(config,arg); | |
412 if(co) | |
413 return co->opt; | |
414 else | |
415 return NULL; | |
416 } | |
417 | |
30631
e9b902ad0ddb
Mark m_config_get_option_ptr() as static, it is only used within the file.
diego
parents:
30429
diff
changeset
|
418 static const void* |
8164 | 419 m_config_get_option_ptr(m_config_t *config, char* arg) { |
25225
51c23a18a17b
First try to mark some things in m_config correctly as const
reimar
parents:
23868
diff
changeset
|
420 const m_option_t* conf; |
8164 | 421 |
422 #ifdef MP_DEBUG | |
423 assert(config != NULL); | |
424 assert(arg != NULL); | |
425 #endif | |
426 | |
427 conf = m_config_get_option(config,arg); | |
428 if(!conf) return NULL; | |
429 return conf->p; | |
430 } | |
431 | |
432 void | |
433 m_config_print_option_list(m_config_t *config) { | |
434 char min[50],max[50]; | |
435 m_config_option_t* co; | |
436 int count = 0; | |
437 | |
438 if(!config->opts) return; | |
439 | |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
440 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_OptionListHeader); |
8164 | 441 for(co = config->opts ; co ; co = co->next) { |
25225
51c23a18a17b
First try to mark some things in m_config correctly as const
reimar
parents:
23868
diff
changeset
|
442 const m_option_t* opt = co->opt; |
8164 | 443 if(opt->type->flags & M_OPT_TYPE_HAS_CHILD) continue; |
444 if(opt->flags & M_OPT_MIN) | |
445 sprintf(min,"%-8.0f",opt->min); | |
446 else | |
447 strcpy(min,"No"); | |
448 if(opt->flags & M_OPT_MAX) | |
449 sprintf(max,"%-8.0f",opt->max); | |
450 else | |
451 strcpy(max,"No"); | |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
452 mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %-20.20s %-15.15s %-10.10s %-10.10s %-3.3s %-3.3s %-3.3s\n", |
8164 | 453 co->name, |
454 co->opt->type->name, | |
455 min, | |
456 max, | |
457 opt->flags & CONF_GLOBAL ? "Yes" : "No", | |
458 opt->flags & CONF_NOCMD ? "No" : "Yes", | |
459 opt->flags & CONF_NOCFG ? "No" : "Yes"); | |
460 count++; | |
461 } | |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
462 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_TotalOptions,count); |
8164 | 463 } |
17471 | 464 |
465 m_profile_t* | |
466 m_config_get_profile(m_config_t* config, char* name) { | |
467 m_profile_t* p; | |
468 for(p = config->profiles ; p ; p = p->next) | |
469 if(!strcmp(p->name,name)) return p; | |
470 return NULL; | |
471 } | |
472 | |
473 m_profile_t* | |
474 m_config_add_profile(m_config_t* config, char* name) { | |
475 m_profile_t* p = m_config_get_profile(config,name); | |
476 if(p) return p; | |
477 p = calloc(1,sizeof(m_profile_t)); | |
478 p->name = strdup(name); | |
479 p->next = config->profiles; | |
480 config->profiles = p; | |
481 return p; | |
482 } | |
483 | |
484 void | |
485 m_profile_set_desc(m_profile_t* p, char* desc) { | |
486 if(p->desc) free(p->desc); | |
487 p->desc = desc ? strdup(desc) : NULL; | |
488 } | |
489 | |
490 int | |
491 m_config_set_profile_option(m_config_t* config, m_profile_t* p, | |
492 char* name, char* val) { | |
493 int i = m_config_check_option(config,name,val); | |
494 if(i < 0) return i; | |
495 if(p->opts) p->opts = realloc(p->opts,2*(p->num_opts+2)*sizeof(char*)); | |
496 else p->opts = malloc(2*(p->num_opts+2)*sizeof(char*)); | |
497 p->opts[p->num_opts*2] = strdup(name); | |
498 p->opts[p->num_opts*2+1] = val ? strdup(val) : NULL; | |
499 p->num_opts++; | |
500 p->opts[p->num_opts*2] = p->opts[p->num_opts*2+1] = NULL; | |
17856 | 501 return 1; |
17471 | 502 } |
503 | |
25634 | 504 void |
17471 | 505 m_config_set_profile(m_config_t* config, m_profile_t* p) { |
506 int i; | |
507 if(config->profile_depth > MAX_PROFILE_DEPTH) { | |
18335 | 508 mp_msg(MSGT_CFGPARSER, MSGL_WARN, MSGTR_ProfileInclusionTooDeep); |
17471 | 509 return; |
510 } | |
511 config->profile_depth++; | |
512 for(i = 0 ; i < p->num_opts ; i++) | |
513 m_config_set_option(config,p->opts[2*i],p->opts[2*i+1]); | |
514 config->profile_depth--; | |
515 } | |
516 | |
517 static int | |
26288 | 518 parse_profile(const m_option_t *opt, const char *name, char *param, void *dst, int src) |
519 { | |
17471 | 520 m_config_t* config = opt->priv; |
521 char** list = NULL; | |
522 int i,r; | |
523 if(param && !strcmp(param,"help")) { | |
524 m_profile_t* p; | |
525 if(!config->profiles) { | |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
526 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_NoProfileDefined); |
17471 | 527 return M_OPT_EXIT-1; |
528 } | |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
529 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_AvailableProfiles); |
17471 | 530 for(p = config->profiles ; p ; p = p->next) |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
531 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\t%s\t%s\n",p->name, |
17471 | 532 p->desc ? p->desc : ""); |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
533 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); |
17471 | 534 return M_OPT_EXIT-1; |
535 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
536 |
17471 | 537 r = m_option_type_string_list.parse(opt,name,param,&list,src); |
538 if(r < 0) return r; | |
539 if(!list || !list[0]) return M_OPT_INVALID; | |
540 for(i = 0 ; list[i] ; i++) | |
541 if(!m_config_get_profile(config,list[i])) { | |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
542 mp_msg(MSGT_CFGPARSER, MSGL_WARN, MSGTR_UnknownProfile, |
17471 | 543 list[i]); |
544 r = M_OPT_INVALID; | |
545 } | |
546 if(dst) | |
547 m_option_copy(opt,dst,&list); | |
548 else | |
549 m_option_free(opt,&list); | |
550 return r; | |
551 } | |
552 | |
553 static void | |
26288 | 554 set_profile(const m_option_t *opt, void *dst, void *src) { |
17471 | 555 m_config_t* config = opt->priv; |
556 m_profile_t* p; | |
557 char** list = NULL; | |
558 int i; | |
559 if(!src || !*(char***)src) return; | |
560 m_option_copy(opt,&list,src); | |
561 for(i = 0 ; list[i] ; i++) { | |
562 p = m_config_get_profile(config,list[i]); | |
563 if(!p) continue; | |
564 m_config_set_profile(config,p); | |
565 } | |
566 m_option_free(opt,&list); | |
567 } | |
568 | |
569 static int | |
570 show_profile(m_option_t *opt, char* name, char *param) { | |
571 m_config_t* config = opt->priv; | |
572 m_profile_t* p; | |
573 int i,j; | |
574 if(!param) return M_OPT_MISSING_PARAM; | |
575 if(!(p = m_config_get_profile(config,param))) { | |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
576 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_UnknownProfile, param); |
17471 | 577 return M_OPT_EXIT-1; |
578 } | |
579 if(!config->profile_depth) | |
17481
99c0caec4677
Fix the MSG?_FIXME and make the profiles help translatable.
albeu
parents:
17472
diff
changeset
|
580 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_Profile, param, |
17471 | 581 p->desc ? p->desc : ""); |
582 config->profile_depth++; | |
583 for(i = 0 ; i < p->num_opts ; i++) { | |
584 char spc[config->profile_depth+1]; | |
585 for(j = 0 ; j < config->profile_depth ; j++) | |
586 spc[j] = ' '; | |
587 spc[config->profile_depth] = '\0'; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
588 |
17471 | 589 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s%s=%s\n", spc, |
590 p->opts[2*i], p->opts[2*i+1]); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26408
diff
changeset
|
591 |
17471 | 592 |
593 if(config->profile_depth < MAX_PROFILE_DEPTH && | |
594 !strcmp(p->opts[2*i],"profile")) { | |
595 char* e,*list = p->opts[2*i+1]; | |
596 while((e = strchr(list,','))) { | |
597 int l = e-list; | |
598 char tmp[l+1]; | |
599 if(!l) continue; | |
600 memcpy(tmp,list,l); | |
601 tmp[l] = '\0'; | |
602 show_profile(opt,name,tmp); | |
603 list = e+1; | |
604 } | |
605 if(list[0] != '\0') | |
606 show_profile(opt,name,list); | |
607 } | |
608 } | |
609 config->profile_depth--; | |
610 if(!config->profile_depth) mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); | |
611 return M_OPT_EXIT-1; | |
612 } | |
17472
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
613 |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
614 static int |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
615 list_options(m_option_t *opt, char* name, char *param) { |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
616 m_config_t* config = opt->priv; |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
617 m_config_print_option_list(config); |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
618 return M_OPT_EXIT; |
526abfe30498
Make -list-options work in both MPlayer and MEncoder.
albeu
parents:
17471
diff
changeset
|
619 } |