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