]> mj.ucw.cz Git - libucw.git/blobdiff - lib/conf.c
The $(LIBxxx) mechanism proved useful, so I'm switching to it for all other
[libucw.git] / lib / conf.c
index 9e52cf275a12db022e231e41a48eb976841824c5..d2c08de23b5e0ded212290866de3a5675c82f8a5 100644 (file)
@@ -2,6 +2,9 @@
  *     Sherlock Library -- Reading configuration files
  *
  *     (c) 2001 Robert Spalek <robert@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
 #include "lib/lib.h"
@@ -49,8 +52,8 @@ cfg_stralloc(byte *s)
 
 void cf_register(struct cfitem *items)
 {
-       if(items[0].type!=CT_SECTION)
-               die("Invalid configuration section, first item must be of type CT_SECTION");
+       if(items[0].type!=CT_SECTION && items[0].type!=CT_INCOMPLETE_SECTION)
+               die("cf_register: Invalid section type");
        items[0].var=cfsection;
        cfsection=items;
 }
@@ -60,22 +63,25 @@ int cf_item_count(void)
        struct cfitem *sect, *item;
        int count = 0;
        for (sect = cfsection; sect; sect = sect->var)
-               for (item = sect+1; sect->type; sect++)
+               for (item = sect+1; item->type; item++)
                        count++;
        return count;
 }
 
 struct cfitem *cf_get_item(byte *sect, byte *name)
 {
-       struct cfitem *item;
+       struct cfitem *item, *section;
 
        item=cfsection;
        while(item && strcasecmp(item->name,sect))
                item=item->var;
        if(!item)       /* unknown section */
                return NULL;
+       section = item;
 
        for(item++; item->type && strcasecmp(item->name,name); item++);
+       if (!item->type && section->type == CT_INCOMPLETE_SECTION)
+               return NULL;
 
        return item;    /* item->type == 0 if not found */
 }
@@ -85,6 +91,8 @@ byte *cf_set_item(byte *sect, byte *name, byte *value)
        struct cfitem *item;
        byte *msg=NULL;
 
+       if (!*sect)
+               return "Empty section name";
        item=cf_get_item(sect,name);
        if(!item)       /* ignore unknown section */
                return NULL;