]> mj.ucw.cz Git - libucw.git/blobdiff - lib/conf-section.c
Cleaned up tracing levels. Array sorter now has its own control knob.
[libucw.git] / lib / conf-section.c
index 590dec96bcd99e7ee8116b9a788df61691049307..1a9ae171e01443411390be56a9ea9ca467d49c54 100644 (file)
@@ -16,8 +16,6 @@
 
 #include <string.h>
 
 
 #include <string.h>
 
-#define TRY(f) do { byte *_msg = f; if (_msg) return _msg; } while (0)
-
 /* Dirty sections */
 
 struct dirty_section {
 /* Dirty sections */
 
 struct dirty_section {
@@ -72,7 +70,7 @@ sort_dirty(void)
 struct cf_section cf_sections; // root section
 
 struct cf_item *
 struct cf_section cf_sections; // root section
 
 struct cf_item *
-cf_find_subitem(struct cf_section *sec, byte *name)
+cf_find_subitem(struct cf_section *sec, const char *name)
 {
   struct cf_item *ci = sec->cfg;
   for (; ci->cls; ci++)
 {
   struct cf_item *ci = sec->cfg;
   for (; ci->cls; ci++)
@@ -93,7 +91,7 @@ inspect_section(struct cf_section *sec)
     } else if (ci->cls == CC_LIST) {
       inspect_section(ci->u.sec);
       sec->flags |= SEC_FLAG_DYNAMIC | SEC_FLAG_CANT_COPY;
     } else if (ci->cls == CC_LIST) {
       inspect_section(ci->u.sec);
       sec->flags |= SEC_FLAG_DYNAMIC | SEC_FLAG_CANT_COPY;
-    } else if (ci->cls == CC_DYNAMIC)
+    } else if (ci->cls == CC_DYNAMIC || ci->cls == CC_BITMAP)
       sec->flags |= SEC_FLAG_DYNAMIC;
     else if (ci->cls == CC_PARSER) {
       sec->flags |= SEC_FLAG_CANT_COPY;
       sec->flags |= SEC_FLAG_DYNAMIC;
     else if (ci->cls == CC_PARSER) {
       sec->flags |= SEC_FLAG_CANT_COPY;
@@ -106,7 +104,7 @@ inspect_section(struct cf_section *sec)
 }
 
 void
 }
 
 void
-cf_declare_section(byte *name, struct cf_section *sec, uns allow_unknown)
+cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown)
 {
   if (!cf_sections.cfg)
   {
 {
   if (!cf_sections.cfg)
   {
@@ -134,40 +132,46 @@ cf_declare_section(byte *name, struct cf_section *sec, uns allow_unknown)
 }
 
 void
 }
 
 void
-cf_init_section(byte *name, struct cf_section *sec, void *ptr, uns do_bzero)
+cf_init_section(const char *name, struct cf_section *sec, void *ptr, uns do_bzero)
 {
   if (do_bzero) {
     ASSERT(sec->size);
     bzero(ptr, sec->size);
   }
 {
   if (do_bzero) {
     ASSERT(sec->size);
     bzero(ptr, sec->size);
   }
-  for (uns i=0; sec->cfg[i].cls; i++)
-    if (sec->cfg[i].cls == CC_SECTION)
-      cf_init_section(sec->cfg[i].name, sec->cfg[i].u.sec, ptr + (addr_int_t) sec->cfg[i].ptr, 0);
-    else if (sec->cfg[i].cls == CC_LIST)
-      clist_init(ptr + (addr_int_t) sec->cfg[i].ptr);
+  for (struct cf_item *ci=sec->cfg; ci->cls; ci++)
+    if (ci->cls == CC_SECTION)
+      cf_init_section(ci->name, ci->u.sec, ptr + (uintptr_t) ci->ptr, 0);
+    else if (ci->cls == CC_LIST)
+      clist_init(ptr + (uintptr_t) ci->ptr);
+    else if (ci->cls == CC_DYNAMIC) {
+      void **dyn = ptr + (uintptr_t) ci->ptr;
+      if (!*dyn) {                     // replace NULL by an empty array
+       static uns zero = 0;
+       *dyn = (&zero) + 1;
+      }
+    }
   if (sec->init) {
   if (sec->init) {
-    byte *msg = sec->init(ptr);
+    char *msg = sec->init(ptr);
     if (msg)
       die("Cannot initialize section %s: %s", name, msg);
   }
 }
 
     if (msg)
       die("Cannot initialize section %s: %s", name, msg);
   }
 }
 
-static byte *
+static char *
 commit_section(struct cf_section *sec, void *ptr, uns commit_all)
 {
 commit_section(struct cf_section *sec, void *ptr, uns commit_all)
 {
-  struct cf_item *ci;
-  byte *err;
-  for (ci=sec->cfg; ci->cls; ci++)
+  char *err;
+  for (struct cf_item *ci=sec->cfg; ci->cls; ci++)
     if (ci->cls == CC_SECTION) {
     if (ci->cls == CC_SECTION) {
-      if ((err = commit_section(ci->u.sec, ptr + (addr_int_t) ci->ptr, commit_all))) {
-       log(L_ERROR, "Cannot commit section %s: %s", ci->name, err);
+      if ((err = commit_section(ci->u.sec, ptr + (uintptr_t) ci->ptr, commit_all))) {
+       msg(L_ERROR, "Cannot commit section %s: %s", ci->name, err);
        return "commit of a subsection failed";
       }
     } else if (ci->cls == CC_LIST) {
       uns idx = 0;
        return "commit of a subsection failed";
       }
     } else if (ci->cls == CC_LIST) {
       uns idx = 0;
-      CLIST_FOR_EACH(cnode *, n, * (clist*) (ptr + (addr_int_t) ci->ptr))
+      CLIST_FOR_EACH(cnode *, n, * (clist*) (ptr + (uintptr_t) ci->ptr))
        if (idx++, err = commit_section(ci->u.sec, n, commit_all)) {
        if (idx++, err = commit_section(ci->u.sec, n, commit_all)) {
-         log(L_ERROR, "Cannot commit node #%d of list %s: %s", idx, ci->name, err);
+         msg(L_ERROR, "Cannot commit node #%d of list %s: %s", idx, ci->name, err);
          return "commit of a list failed";
        }
     }
          return "commit of a list failed";
        }
     }
@@ -180,9 +184,8 @@ commit_section(struct cf_section *sec, void *ptr, uns commit_all)
     uns pos = BIN_SEARCH_FIRST_GE_CMP(dirty.ptr, dirties, comp, ARY_LT_X);
 
     if (commit_all
     uns pos = BIN_SEARCH_FIRST_GE_CMP(dirty.ptr, dirties, comp, ARY_LT_X);
 
     if (commit_all
-       || (pos < dirties && dirty.ptr[pos].sec == sec && dirty.ptr[pos].ptr == ptr)) {
+       || (pos < dirties && dirty.ptr[pos].sec == sec && dirty.ptr[pos].ptr == ptr))
       return sec->commit(ptr);
       return sec->commit(ptr);
-    }
   }
   return 0;
 }
   }
   return 0;
 }