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