/[gxemul]/trunk/src/settings.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/settings.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 41 by dpavlin, Mon Oct 8 16:21:17 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 25  Line 25 
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,
# Line 89  struct settings { Line 89  struct settings {
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;
# Line 272  void settings_debugdump(struct settings Line 267  void settings_debugdump(struct 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    
# Line 354  void settings_add(struct settings *setti Line 351  void settings_add(struct settings *setti
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;
# Line 380  void settings_add(struct settings *setti Line 371  void settings_add(struct settings *setti
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    

Legend:
Removed from v.41  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26