]> mj.ucw.cz Git - libucw.git/blob - lib/conf.h
HTML parser basically works. A *lot* of things still needs to be cleaned up.
[libucw.git] / lib / conf.h
1 /*
2  *      Sherlock Library -- Reading configuration files
3  *
4  *      (c) 2001 Robert Spalek <robert@ucw.cz>
5  */
6
7 #include <getopt.h>
8
9 /*
10  * Allocation in configuration memory pool.
11  */
12
13 void *
14 cfg_malloc(uns size);
15
16 byte *
17 cfg_stralloc(byte *s);
18
19 /*
20  * Every module places its configuration setting into some section.  Section is
21  * an array of cfitem, whose first record is of type CT_SECTION and contains
22  * the name of the section.  The configuration sections are registered by
23  * calling cf_register().
24  *
25  * item->var is a pointer to the destination variable or to the special parsing
26  * function.
27  */
28
29 enum cftype { CT_STOP, CT_SECTION, CT_INT, CT_STRING, CT_FUNCTION };
30
31 struct cfitem {
32         byte *name;
33         enum cftype type;
34         void *var;
35 };
36
37 typedef byte *(*ci_func)(struct cfitem *, byte *);
38
39 void cf_register(struct cfitem *items);
40
41 /*
42  * Direct setting of configuration items and parsing the configuration file.
43  */
44
45 byte *cf_set_item(byte *sect, byte *name, byte *value);
46 void cf_read(byte *filename);
47
48 /*
49  * When using cf_getopt, you must prefix your own short/long options by the
50  * CF_(SHORT|LONG)_OPTS.
51  */
52
53 #define CF_SHORT_OPTS   "S:C:"
54 #define CF_LONG_OPTS    \
55         {"set",         1, 0, 'S'},\
56         {"config",      1, 0, 'C'},
57 #define CF_NO_LONG_OPTS (const struct option []){ CF_LONG_OPTS { NULL, 0, 0, 0 } }
58
59 int cf_getopt(int argc,char * const argv[],
60                 const char *shortopts,const struct option *longopts,
61                 int *longindex);
62