25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: settings.c,v 1.15 2006/12/30 13:30:52 debug Exp $ |
* $Id: settings.c,v 1.16 2007/06/15 17:02:38 debug Exp $ |
29 |
* |
* |
30 |
* A generic settings object. (This module should be 100% indepedent of GXemul |
* A generic settings object. (This module should be 100% indepedent of GXemul |
31 |
* and hence easily reusable.) It is basically a tree structure of nodes, |
* and hence easily reusable.) It is basically a tree structure of nodes, |
89 |
*/ |
*/ |
90 |
struct settings *settings_new(void) |
struct settings *settings_new(void) |
91 |
{ |
{ |
92 |
struct settings *settings = malloc(sizeof(struct settings)); |
struct settings *settings; |
93 |
|
|
94 |
if (settings == NULL) { |
CHECK_ALLOCATION(settings = malloc(sizeof(struct settings))); |
|
fprintf(stderr, "settings_new(): out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
|
|
|
|
/* No settings. */ |
|
95 |
memset(settings, 0, sizeof(struct settings)); |
memset(settings, 0, sizeof(struct settings)); |
96 |
|
|
97 |
return settings; |
return settings; |
267 |
int recurse) |
int recurse) |
268 |
{ |
{ |
269 |
size_t name_buflen = strlen(prefix) + 100; |
size_t name_buflen = strlen(prefix) + 100; |
270 |
char *name = malloc(name_buflen); |
char *name; |
271 |
int i; |
int i; |
272 |
uint64_t value = 0; |
uint64_t value = 0; |
273 |
|
|
274 |
|
CHECK_ALLOCATION(name = malloc(name_buflen)); |
275 |
|
|
276 |
for (i=0; i<settings->n_settings; i++) { |
for (i=0; i<settings->n_settings; i++) { |
277 |
snprintf(name, name_buflen, "%s.%s", prefix, settings->name[i]); |
snprintf(name, name_buflen, "%s.%s", prefix, settings->name[i]); |
278 |
|
|
351 |
|
|
352 |
settings->n_settings ++; |
settings->n_settings ++; |
353 |
|
|
354 |
if ((settings->name = realloc(settings->name, settings->n_settings |
CHECK_ALLOCATION(settings->name = realloc(settings->name, |
355 |
* sizeof(char *))) == NULL) |
settings->n_settings * sizeof(char *))); |
356 |
goto out_of_mem; |
CHECK_ALLOCATION(settings->writable = realloc(settings->writable, |
357 |
if ((settings->writable = realloc(settings->writable, |
settings->n_settings * sizeof(int))); |
358 |
settings->n_settings * sizeof(int))) == NULL) |
CHECK_ALLOCATION(settings->storage_type = realloc( |
359 |
goto out_of_mem; |
settings->storage_type, settings->n_settings * sizeof(int))); |
360 |
if ((settings->storage_type = realloc(settings->storage_type, |
CHECK_ALLOCATION(settings->presentation_format = realloc(settings-> |
361 |
settings->n_settings * sizeof(int))) == NULL) |
presentation_format, settings->n_settings * sizeof(int))); |
362 |
goto out_of_mem; |
CHECK_ALLOCATION(settings->ptr = realloc(settings->ptr, |
363 |
if ((settings->presentation_format = realloc(settings-> |
settings->n_settings * sizeof(void *))); |
364 |
presentation_format, settings->n_settings * sizeof(int))) == NULL) |
|
365 |
goto out_of_mem; |
CHECK_ALLOCATION(settings->name[settings->n_settings - 1] = |
366 |
if ((settings->ptr = realloc(settings->ptr, settings->n_settings |
strdup(name)); |
|
* sizeof(void *))) == NULL) |
|
|
goto out_of_mem; |
|
|
|
|
|
settings->name[settings->n_settings - 1] = strdup(name); |
|
|
if (settings->name[settings->n_settings - 1] == NULL) |
|
|
goto out_of_mem; |
|
367 |
settings->writable[settings->n_settings - 1] = writable; |
settings->writable[settings->n_settings - 1] = writable; |
368 |
settings->storage_type[settings->n_settings - 1] = type; |
settings->storage_type[settings->n_settings - 1] = type; |
369 |
settings->presentation_format[settings->n_settings - 1] = format; |
settings->presentation_format[settings->n_settings - 1] = format; |
371 |
|
|
372 |
if (type == SETTINGS_TYPE_SUBSETTINGS) { |
if (type == SETTINGS_TYPE_SUBSETTINGS) { |
373 |
((struct settings *)ptr)->parent = settings; |
((struct settings *)ptr)->parent = settings; |
374 |
((struct settings *)ptr)->name_in_parent = strdup(name); |
CHECK_ALLOCATION( ((struct settings *)ptr)->name_in_parent = |
375 |
if (((struct settings *)ptr)->name_in_parent == NULL) |
strdup(name) ); |
|
goto out_of_mem; |
|
376 |
} |
} |
|
|
|
|
return; |
|
|
|
|
|
out_of_mem: |
|
|
fprintf(stderr, "settings_add(): fatal error: out of memory\n"); |
|
|
exit(1); |
|
377 |
} |
} |
378 |
|
|
379 |
|
|