annotate m_config.c @ 13757:40c44e178073

1.132: MSGTR_EdlCantOpenForWrite updated 1.133: mp_msg transition of unmaintained audio output drivers (referring to date 2004/09/18!) file isn't yet up to date, will continue updating in steps..
author kraymer
date Mon, 25 Oct 2004 16:31:50 +0000
parents 11b249ef87b0
children bad703951cf9
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 #include "config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
2
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
3 #include <stdlib.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
4 #include <stdio.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
5 #include <errno.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
6 #include <string.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
7 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
8 #include <assert.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
9 #endif
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 #include "m_config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
12 #include "m_option.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
13 #include "mp_msg.h"
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
14 #include "help_mp.h"
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
15
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
16 m_config_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
17 m_config_new(void) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
18 m_config_t* config;
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 config = (m_config_t*)calloc(1,sizeof(m_config_t));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
21 config->lvl = 1; // 0 Is the defaults
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
22 return config;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
23 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
24
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
25 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
26 m_config_free(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
27 m_config_option_t *i = config->opts, *ct;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
28 m_config_save_slot_t *sl,*st;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
29
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
30 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
31 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
32 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
33
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
34 while(i) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
35 sl = i->slots;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
36 while(sl) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
37 m_option_free(i->opt,sl->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
38 st = sl->prev;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
39 free(sl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
40 sl = st;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
41 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
42 if(i->name != i->opt->name)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
43 free(i->name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
44 ct = i->next;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
45 free(i);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
46 ct = i;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
47 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
48 free(config);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
49 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
50
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
51 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
52 m_config_push(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
53 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
54 m_config_save_slot_t *slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
55
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
56 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
57 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
58 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
59 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
60
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
61 config->lvl++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
62
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
63 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
64 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
65 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
66 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
67 continue;
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
68 if((co->opt->flags & M_OPT_OLD) && !(co->flags && M_CFG_OPT_SET))
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
69 continue;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
70 if(co->flags & M_CFG_OPT_ALIAS)
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
71 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
72
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
73 // Update the current status
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
74 m_option_save(co->opt,co->slots->data,co->opt->p);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
75
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
76 // Allocate a new slot
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
77 slot = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + co->opt->type->size);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
78 slot->lvl = config->lvl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
79 slot->prev = co->slots;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
80 co->slots = slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
81 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
82 // Reset our set flag
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
83 co->flags &= ~M_CFG_OPT_SET;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
84 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
85
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
86 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config pushed level is now %d\n",config->lvl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
87 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
88
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
89 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
90 m_config_pop(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
91 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
92 m_config_save_slot_t *slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
93
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
94 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
95 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
96 assert(config->lvl > 1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
97 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
98
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
99 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
100 int pop = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
101 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
102 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
103 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
104 continue;
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
105 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
106 continue;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
107 if(co->slots->lvl > config->lvl)
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
108 mp_msg(MSGT_CFGPARSER, MSGL_WARN,MSGTR_SaveSlotTooOld,config->lvl,co->slots->lvl);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
109
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
110 while(co->slots->lvl >= config->lvl) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
111 m_option_free(co->opt,co->slots->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
112 slot = co->slots;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
113 co->slots = slot->prev;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
114 free(slot);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
115 pop++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
116 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
117 if(pop) // We removed some ctx -> set the previous value
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
118 m_option_set(co->opt,co->opt->p,co->slots->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
119 }
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 config->lvl--;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
122 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config poped level=%d\n",config->lvl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
123 }
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 static void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
126 m_config_add_option(m_config_t *config, m_option_t *arg, char* prefix) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
127 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
128 m_config_save_slot_t* sl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
129
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
130 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
131 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
132 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
133 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
134 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
135
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
136 // Allocate a new entry for this option
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
137 co = (m_config_option_t*)calloc(1,sizeof(m_config_option_t) + arg->type->size);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
138 co->opt = arg;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
139
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
140 // Fill in the full name
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
141 if(prefix && strlen(prefix) > 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
142 int l = strlen(prefix) + 1 + strlen(arg->name) + 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
143 co->name = (char*) malloc(l);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
144 sprintf(co->name,"%s:%s",prefix,arg->name);
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 co->name = arg->name;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
147
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
148 // Option with childs -> add them
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
149 if(arg->type->flags & M_OPT_TYPE_HAS_CHILD) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
150 m_option_t *ol = arg->p;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
151 int i;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
152 for(i = 0 ; ol[i].name != NULL ; i++)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
153 m_config_add_option(config,&ol[i], co->name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
154 } else {
9912
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
155 m_config_option_t *i;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
156 // Check if there is alredy an option pointing to this address
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
157 if(arg->p) {
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
158 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
159 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
160 co->slots = i->slots;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
161 co->flags |= M_CFG_OPT_ALIAS;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
162 break;
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
163 }
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
164 }
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
165 }
39444d65c4cb Don't save restore all options wich point to the same variable.
albeu
parents: 9593
diff changeset
166 if(!(co->flags & M_CFG_OPT_ALIAS)) {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
167 // Allocate a slot for the defaults
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
168 sl = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + arg->type->size);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
169 m_option_save(arg,sl->data,(void**)arg->p);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
170 // Hack to avoid too much trouble with dynamicly allocated data :
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
171 // We always use a dynamic version
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
172 if((arg->type->flags & M_OPT_TYPE_DYNAMIC) && arg->p && (*(void**)arg->p)) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
173 *(void**)arg->p = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
174 m_option_set(arg,arg->p,sl->data);
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 sl->lvl = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
177 co->slots = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + arg->type->size);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
178 co->slots->prev = sl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
179 co->slots->lvl = config->lvl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
180 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
181 } // !M_OPT_ALIAS
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
182 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
183 co->next = config->opts;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
184 config->opts = co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
185 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
186
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
187 int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
188 m_config_register_options(m_config_t *config, m_option_t *args) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
189 int i;
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 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
192 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
193 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
194 assert(args != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
195 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
196
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
197 for(i = 0 ; args[i].name != NULL ; i++)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
198 m_config_add_option(config,&args[i],NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
199
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
200 return 1;
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 static m_config_option_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
204 m_config_get_co(m_config_t *config, char* arg) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
205 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
206
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
207 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
208 int l = strlen(co->name) - 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
209 if((co->opt->type->flags & M_OPT_TYPE_ALLOW_WILDCARD) &&
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
210 (co->name[l] == '*')) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
211 if(strncasecmp(co->name,arg,l) == 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
212 return co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
213 } else if(strcasecmp(co->name,arg) == 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
214 return co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
215 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
216 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
217 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
218
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
219 static int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
220 m_config_parse_option(m_config_t *config, char* arg, char* param,int set) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
221 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
222 int r = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
223
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
224 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
225 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
226 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
227 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
228 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
229
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
230 co = m_config_get_co(config,arg);
8892
06843e67a04b print meaningful error message
arpi
parents: 8512
diff changeset
231 if(!co){
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
232 // 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
233 return M_OPT_UNKNOWN;
8892
06843e67a04b print meaningful error message
arpi
parents: 8512
diff changeset
234 }
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
235
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
236 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
237 // This is the only mandatory function
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
238 assert(co->opt->type->parse);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
239 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
240
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
241 // Check if this option isn't forbiden in the current mode
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
242 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
243 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidCfgfileOption,arg);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
244 return M_OPT_INVALID;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
245 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
246 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
247 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidCmdlineOption,arg);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
248 return M_OPT_INVALID;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
249 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
250
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
251 // Option with childs are a bit different to parse
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
252 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
253 char** lst = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
254 int i,sr;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
255 // 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
256 r = m_option_parse(co->opt,arg,param,&lst,M_COMMAND_LINE);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
257 // Set them now
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
258 if(r >= 0)
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
259 for(i = 0 ; lst && lst[2*i] ; i++) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
260 int l = strlen(co->name) + 1 + strlen(lst[2*i]) + 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
261 if(r >= 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
262 // Build the full name
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
263 char n[l];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
264 sprintf(n,"%s:%s",co->name,lst[2*i]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
265 sr = m_config_parse_option(config,n,lst[2*i+1],set);
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
266 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
267 if(sr == M_OPT_UNKNOWN){
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
268 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidSuboption,co->name,lst[2*i]);
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
269 r = M_OPT_INVALID;
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
270 } else
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
271 if(sr == M_OPT_MISSING_PARAM){
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
272 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_MissingSuboptionParameter,lst[2*i],co->name);
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
273 r = M_OPT_INVALID;
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
274 } else
8894
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
275 r = sr;
e6a83b140b39 better error handling for invalud suboptions
arpi
parents: 8892
diff changeset
276 }
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
277 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
278 free(lst[2*i]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
279 free(lst[2*i+1]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
280 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
281 if(lst) free(lst);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
282 } else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
283 r = m_option_parse(co->opt,arg,param,set ? co->slots->data : NULL,config->mode);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
284
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
285 // Parsing failed ?
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
286 if(r < 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
287 return r;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
288 // Set the option
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
289 if(set) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
290 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
291 co->flags |= M_CFG_OPT_SET;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
292 }
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 return r;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
295 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
296
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
297 int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
298 m_config_set_option(m_config_t *config, char* arg, char* param) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
299 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Setting %s=%s\n",arg,param);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
300 return m_config_parse_option(config,arg,param,1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
301 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
302
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
303 int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
304 m_config_check_option(m_config_t *config, char* arg, char* param) {
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
305 int r;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
306 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Checking %s=%s\n",arg,param);
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
307 r=m_config_parse_option(config,arg,param,0);
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
308 if(r==M_OPT_MISSING_PARAM){
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
309 mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_MissingOptionParameter,arg);
9222
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
310 return M_OPT_INVALID;
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
311 }
d3da9b617aa8 print meaningful error message for missing parameter
arpi
parents: 8894
diff changeset
312 return r;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
313 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
314
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
315
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
316 m_option_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
317 m_config_get_option(m_config_t *config, char* arg) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
318 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
319
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
320 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
321 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
322 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
323 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
324 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
325
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
326 co = m_config_get_co(config,arg);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
327 if(co)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
328 return co->opt;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
329 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
330 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
331 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
332
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
333 void*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
334 m_config_get_option_ptr(m_config_t *config, char* arg) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
335 m_option_t* conf;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
336
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
337 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
338 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
339 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
340 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
341
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
342 conf = m_config_get_option(config,arg);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
343 if(!conf) return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
344 return conf->p;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
345 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
346
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
347 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
348 m_config_print_option_list(m_config_t *config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
349 char min[50],max[50];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
350 m_config_option_t* co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
351 int count = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
352
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
353 if(!config->opts) return;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
354
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
355 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_OptionListHeader);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
356 for(co = config->opts ; co ; co = co->next) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
357 m_option_t* opt = co->opt;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
358 if(opt->type->flags & M_OPT_TYPE_HAS_CHILD) continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
359 if(opt->flags & M_OPT_MIN)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
360 sprintf(min,"%-8.0f",opt->min);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
361 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
362 strcpy(min,"No");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
363 if(opt->flags & M_OPT_MAX)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
364 sprintf(max,"%-8.0f",opt->max);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
365 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
366 strcpy(max,"No");
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
367 mp_msg(MSGT_FIXME, MSGL_FIXME, " %-20.20s %-15.15s %-10.10s %-10.10s %-3.3s %-3.3s %-3.3s\n",
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
368 co->name,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
369 co->opt->type->name,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
370 min,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
371 max,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
372 opt->flags & CONF_GLOBAL ? "Yes" : "No",
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
373 opt->flags & CONF_NOCMD ? "No" : "Yes",
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
374 opt->flags & CONF_NOCFG ? "No" : "Yes");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
375 count++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
376 }
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 10595
diff changeset
377 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_TotalOptions,count);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
378 }