comparison m_config.c @ 9912:39444d65c4cb

Don't save restore all options wich point to the same variable.
author albeu
date Sat, 12 Apr 2003 13:40:30 +0000
parents e9a2af584986
children 57bdcdb061d7
comparison
equal deleted inserted replaced
9911:fa45d335a43b 9912:39444d65c4cb
66 for(co = config->opts ; co ; co = co->next ) { 66 for(co = config->opts ; co ; co = co->next ) {
67 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) 67 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
68 continue; 68 continue;
69 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE)) 69 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
70 continue; 70 continue;
71 if((co->opt->flags & M_OPT_OLD) && !co->flags) 71 if((co->opt->flags & M_OPT_OLD) && !(co->flags && M_CFG_OPT_SET))
72 continue;
73 if(co->flags & M_CFG_OPT_ALIAS)
72 continue; 74 continue;
73 75
74 // Update the current status 76 // Update the current status
75 m_option_save(co->opt,co->slots->data,co->opt->p); 77 m_option_save(co->opt,co->slots->data,co->opt->p);
76 78
78 slot = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + co->opt->type->size); 80 slot = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + co->opt->type->size);
79 slot->lvl = config->lvl; 81 slot->lvl = config->lvl;
80 slot->prev = co->slots; 82 slot->prev = co->slots;
81 co->slots = slot; 83 co->slots = slot;
82 m_option_copy(co->opt,co->slots->data,co->slots->prev->data); 84 m_option_copy(co->opt,co->slots->data,co->slots->prev->data);
83 // Reset our flags 85 // Reset our set flag
84 co->flags=0; 86 co->flags &= ~M_CFG_OPT_SET;
85 } 87 }
86 88
87 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config pushed level is now %d\n",config->lvl); 89 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config pushed level is now %d\n",config->lvl);
88 } 90 }
89 91
100 for(co = config->opts ; co ; co = co->next ) { 102 for(co = config->opts ; co ; co = co->next ) {
101 int pop = 0; 103 int pop = 0;
102 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) 104 if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
103 continue; 105 continue;
104 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE)) 106 if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
107 continue;
108 if(co->flags & M_CFG_OPT_ALIAS)
105 continue; 109 continue;
106 if(co->slots->lvl > config->lvl) 110 if(co->slots->lvl > config->lvl)
107 mp_msg(MSGT_CFGPARSER, MSGL_WARN,"Too old save slot found from lvl %d : %d !!!\n",config->lvl,co->slots->lvl); 111 mp_msg(MSGT_CFGPARSER, MSGL_WARN,"Too old save slot found from lvl %d : %d !!!\n",config->lvl,co->slots->lvl);
108 112
109 while(co->slots->lvl >= config->lvl) { 113 while(co->slots->lvl >= config->lvl) {
149 m_option_t *ol = arg->p; 153 m_option_t *ol = arg->p;
150 int i; 154 int i;
151 for(i = 0 ; ol[i].name != NULL ; i++) 155 for(i = 0 ; ol[i].name != NULL ; i++)
152 m_config_add_option(config,&ol[i], co->name); 156 m_config_add_option(config,&ol[i], co->name);
153 } else { 157 } else {
158 m_config_option_t *i;
159 // Check if there is alredy an option pointing to this address
160 if(arg->p) {
161 for(i = config->opts ; i ; i = i->next ) {
162 if(i->opt->p == arg->p) { // So we don't save the same vars more than 1 time
163 co->slots = i->slots;
164 co->flags |= M_CFG_OPT_ALIAS;
165 break;
166 }
167 }
168 }
169 if(!(co->flags & M_CFG_OPT_ALIAS)) {
154 // Allocate a slot for the defaults 170 // Allocate a slot for the defaults
155 sl = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + arg->type->size); 171 sl = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + arg->type->size);
156 m_option_save(arg,sl->data,(void**)arg->p); 172 m_option_save(arg,sl->data,(void**)arg->p);
157 // Hack to avoid too much trouble with dynamicly allocated data : 173 // Hack to avoid too much trouble with dynamicly allocated data :
158 // We always use a dynamic version 174 // We always use a dynamic version
163 sl->lvl = 0; 179 sl->lvl = 0;
164 co->slots = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + arg->type->size); 180 co->slots = (m_config_save_slot_t*)calloc(1,sizeof(m_config_save_slot_t) + arg->type->size);
165 co->slots->prev = sl; 181 co->slots->prev = sl;
166 co->slots->lvl = config->lvl; 182 co->slots->lvl = config->lvl;
167 m_option_copy(co->opt,co->slots->data,sl->data); 183 m_option_copy(co->opt,co->slots->data,sl->data);
184 } // !M_OPT_ALIAS
168 } 185 }
169 co->next = config->opts; 186 co->next = config->opts;
170 config->opts = co; 187 config->opts = co;
171 } 188 }
172 189
272 if(r < 0) 289 if(r < 0)
273 return r; 290 return r;
274 // Set the option 291 // Set the option
275 if(set) { 292 if(set) {
276 m_option_set(co->opt,co->opt->p,co->slots->data); 293 m_option_set(co->opt,co->opt->p,co->slots->data);
277 co->flags = 1; 294 co->flags |= M_CFG_OPT_SET;
278 } 295 }
279 296
280 return r; 297 return r;
281 } 298 }
282 299