annotate m_config.c @ 8506:55e80f13c826

pci_names.c creation fixup
author alex
date Sat, 21 Dec 2002 17:49:52 +0000
parents 487cfc28525d
children 9c784bd027ad
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 <stdlib.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
7 #include <stdio.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
8 #include <errno.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
9 #include <string.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
10 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
11 #include <assert.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
12 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
13
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 "m_config.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 "mp_msg.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
18
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
19 m_config_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
20 m_config_new(void) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
21 m_config_t* config;
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 config = (m_config_t*)calloc(1,sizeof(m_config_t));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
24 config->lvl = 1; // 0 Is the defaults
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
25 return config;
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
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
28 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
29 m_config_free(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
30 m_config_option_t *i = config->opts, *ct;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
31 m_config_save_slot_t *sl,*st;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
32
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
33 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
34 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
35 #endif
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 while(i) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
38 sl = i->slots;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
39 while(sl) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
40 m_option_free(i->opt,sl->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
41 st = sl->prev;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
42 free(sl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
43 sl = st;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
44 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
45 if(i->name != i->opt->name)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
46 free(i->name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
47 ct = i->next;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
48 free(i);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
49 ct = i;
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 free(config);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
52 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
53
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
54 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
55 m_config_push(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
56 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
57 m_config_save_slot_t *slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
58
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
59 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
60 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
61 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
62 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
63
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
64 config->lvl++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
65
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
66 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
67 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
68 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
69 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
70 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
71 if((co->opt->flags & M_OPT_OLD) && !co->flags)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
72 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
73
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
74 // Update the current status
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
75 m_option_save(co->opt,co->slots->data,co->opt->p);
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 // Allocate a new slot
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
78 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
79 slot->lvl = config->lvl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
80 slot->prev = co->slots;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
81 co->slots = slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
82 m_option_copy(co->opt,co->slots->data,co->slots->prev->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
83 // Reset our flags
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
84 co->flags=0;
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
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
87 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
88 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
89
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
90 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
91 m_config_pop(m_config_t* config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
92 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
93 m_config_save_slot_t *slot;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
94
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
95 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
96 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
97 assert(config->lvl > 1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
98 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
99
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
100 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
101 int pop = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
102 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
103 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
104 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
105 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
106 if(co->slots->lvl > config->lvl)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
107 mp_msg(MSGT_CFGPARSER, MSGL_WARN,"Too old save slot found from lvl %d : %d !!!\n",config->lvl,co->slots->lvl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
108
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
109 while(co->slots->lvl >= config->lvl) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
110 m_option_free(co->opt,co->slots->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
111 slot = co->slots;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
112 co->slots = slot->prev;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
113 free(slot);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
114 pop++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
115 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
116 if(pop) // We removed some ctx -> set the previous value
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
117 m_option_set(co->opt,co->opt->p,co->slots->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
118 }
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 config->lvl--;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
121 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
122 }
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 static void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
125 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
126 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
127 m_config_save_slot_t* sl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
128
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
129 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
130 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
131 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
132 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
133 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
134
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
135 // Allocate a new entry for this option
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
136 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
137 co->opt = arg;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
138
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
139 // Fill in the full name
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
140 if(prefix && strlen(prefix) > 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
141 int l = strlen(prefix) + 1 + strlen(arg->name) + 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
142 co->name = (char*) malloc(l);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
143 sprintf(co->name,"%s:%s",prefix,arg->name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
144 } else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
145 co->name = arg->name;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
146
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
147 // Option with childs -> add them
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
148 if(arg->type->flags & M_OPT_TYPE_HAS_CHILD) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
149 m_option_t *ol = arg->p;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
150 int i;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
151 for(i = 0 ; ol[i].name != NULL ; i++)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
152 m_config_add_option(config,&ol[i], co->name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
153 } else {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
154 // Allocate a slot for the defaults
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
155 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
156 m_option_save(arg,sl->data,(void**)arg->p);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
157 // Hack to avoid too much trouble with dynamicly allocated data :
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
158 // We always use a dynamic version
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
159 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
160 *(void**)arg->p = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
161 m_option_set(arg,arg->p,sl->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
162 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
163 sl->lvl = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
164 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
165 co->slots->prev = sl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
166 co->slots->lvl = config->lvl;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
167 m_option_copy(co->opt,co->slots->data,sl->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
168 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
169 co->next = config->opts;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
170 config->opts = co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
171 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
172
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
173 int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
174 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
175 int i;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
176
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
177 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
178 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
179 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
180 assert(args != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
181 #endif
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 for(i = 0 ; args[i].name != NULL ; i++)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
184 m_config_add_option(config,&args[i],NULL);
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 return 1;
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
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
189 static m_config_option_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
190 m_config_get_co(m_config_t *config, char* arg) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
191 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
192
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
193 for(co = config->opts ; co ; co = co->next ) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
194 int l = strlen(co->name) - 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
195 if((co->opt->type->flags & M_OPT_TYPE_ALLOW_WILDCARD) &&
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
196 (co->name[l] == '*')) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
197 if(strncasecmp(co->name,arg,l) == 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
198 return co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
199 } else if(strcasecmp(co->name,arg) == 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
200 return co;
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 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
203 }
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 static int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
206 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
207 m_config_option_t *co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
208 int r = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
209
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
210 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
211 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
212 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
213 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
214 #endif
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 co = m_config_get_co(config,arg);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
217 if(!co)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
218 return M_OPT_UNKNOW;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
219
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
220 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
221 // This is the only mandatory function
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
222 assert(co->opt->type->parse);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
223 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
224
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
225 // Check if this option isn't forbiden in the current mode
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
226 if((config->mode == M_CONFIG_FILE) && (co->opt->flags & M_OPT_NOCFG)) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
227 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"The %s option can't be used in a config file\n",config->lvl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
228 return M_OPT_INVALID;
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 if((config->mode == M_COMMAND_LINE) && (co->opt->flags & M_OPT_NOCMD)) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
231 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"The %s option can't be used on the command line\n",config->lvl);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
232 return M_OPT_INVALID;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
233 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
234
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
235 // Option with childs are a bit different to parse
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
236 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
237 char** lst = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
238 int i,sr;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
239 // Parse the child options
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
240 r = m_option_parse(co->opt,arg,param,&lst,config->mode);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
241 // Set them now
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
242 for(i = 0 ; lst && lst[2*i] ; i++) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
243 int l = strlen(co->name) + 1 + strlen(lst[2*i]) + 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
244 if(r >= 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
245 // Build the full name
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
246 char n[l];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
247 sprintf(n,"%s:%s",co->name,lst[2*i]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
248 sr = m_config_parse_option(config,n,lst[2*i+1],set);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
249 if(sr < 0) r = sr;
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 free(lst[2*i]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
252 free(lst[2*i+1]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
253 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
254 if(lst) free(lst);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
255 } else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
256 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
257
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
258 // Parsing failed ?
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
259 if(r < 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
260 return r;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
261 // Set the option
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
262 if(set) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
263 m_option_set(co->opt,co->opt->p,co->slots->data);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
264 co->flags = 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
265 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
266
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
267 return r;
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 int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
271 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
272 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
273 return m_config_parse_option(config,arg,param,1);
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
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
276 int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
277 m_config_check_option(m_config_t *config, char* arg, char* param) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
278 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Checking %s=%s\n",arg,param);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
279 return m_config_parse_option(config,arg,param,0);
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
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
282
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
283 m_option_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
284 m_config_get_option(m_config_t *config, char* arg) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
285 m_config_option_t *co;
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 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
288 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
289 assert(config->lvl > 0);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
290 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
291 #endif
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 co = m_config_get_co(config,arg);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
294 if(co)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
295 return co->opt;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
296 else
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 void*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
301 m_config_get_option_ptr(m_config_t *config, char* arg) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
302 m_option_t* conf;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
303
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
304 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
305 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
306 assert(arg != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
307 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
308
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
309 conf = m_config_get_option(config,arg);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
310 if(!conf) return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
311 return conf->p;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
312 }
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 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
315 m_config_print_option_list(m_config_t *config) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
316 char min[50],max[50];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
317 m_config_option_t* co;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
318 int count = 0;
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 if(!config->opts) return;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
321
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
322 printf("\n Name Type Min Max Global CL Cfg\n\n");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
323 for(co = config->opts ; co ; co = co->next) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
324 m_option_t* opt = co->opt;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
325 if(opt->type->flags & M_OPT_TYPE_HAS_CHILD) continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
326 if(opt->flags & M_OPT_MIN)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
327 sprintf(min,"%-8.0f",opt->min);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
328 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
329 strcpy(min,"No");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
330 if(opt->flags & M_OPT_MAX)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
331 sprintf(max,"%-8.0f",opt->max);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
332 else
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
333 strcpy(max,"No");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
334 printf(" %-20.20s %-15.15s %-10.10s %-10.10s %-3.3s %-3.3s %-3.3s\n",
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
335 co->name,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
336 co->opt->type->name,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
337 min,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
338 max,
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
339 opt->flags & CONF_GLOBAL ? "Yes" : "No",
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
340 opt->flags & CONF_NOCMD ? "No" : "Yes",
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
341 opt->flags & CONF_NOCFG ? "No" : "Yes");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
342 count++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
343 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
344 printf("\nTotal: %d options\n",count);
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 #endif // NEW_CONFIG