]> mj.ucw.cz Git - libucw.git/blobdiff - lib/conf.c
Removed obsolete examples of custom attributes. The image search attributes
[libucw.git] / lib / conf.c
index c96d9fb304cd71e029eab9353e4abdbde4baab8f..c37bb98b81b7982d4409c77f4d1f962e4875f8ae 100644 (file)
@@ -49,8 +49,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 +60,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 +88,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;
@@ -255,13 +260,11 @@ int cf_getopt(int argc,char * const argv[],
 
                }else if(res=='C'){
                        cf_read(optarg);
-               }else if(res==-1){
+               }else{
+                       /* unhandled option or end of options */
                        if(cfdeffile)
                                cf_read(cfdeffile);
                        return res;
-               }else{  /* unhandled option */
-                       return res;
                }
        }while(1);
 }
-