2 * UCW Library -- Reading of configuration files
4 * (c) 2001--2006 Robert Spalek <robert@ucw.cz>
5 * (c) 2003--2006 Martin Mares <mj@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
14 /* Safe reloading and loading of configuration files */
15 extern byte *cf_def_file;
16 int cf_reload(byte *file);
17 int cf_load(byte *file);
18 int cf_set(byte *string);
20 /* Direct access to configuration items */
22 #define CF_OPERATIONS T(CLOSE) T(SET) T(CLEAR) T(APPEND) T(PREPEND) \
23 T(REMOVE) T(EDIT) T(AFTER) T(BEFORE) T(COPY)
24 /* Closing brace finishes previous block.
25 * Basic attributes (static, dynamic, parsed) can be used with SET.
26 * Dynamic arrays can be used with SET, APPEND, PREPEND.
27 * Sections can be used with SET.
28 * Lists can be used with everything. */
30 enum cf_operation { CF_OPERATIONS };
35 byte *cf_find_item(byte *name, struct cf_item *item);
36 byte *cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **pars);
37 void cf_dump_sections(struct fastbuf *fb);
40 * When using cf_get_opt(), you must prefix your own short/long options by the
41 * CF_(SHORT|LONG)_OPTS.
43 * cf_def_file contains the name of a configuration file that will be
44 * automatically loaded before the first --set option is executed. If no --set
45 * option occurs, it will be loaded after getopt() returns -1 (i.e. at the end
46 * of the configuration options). cf_def_file will be ignored if another
47 * configuration file has already been loaded using the --config option. The
48 * initial value of cf_def_file is DEFAULT_CONFIG from config.h, but you can
49 * override it manually before calling cf_get_opt().
52 #define CF_SHORT_OPTS "C:S:"
53 #define CF_LONG_OPTS {"config", 1, 0, 'C'}, {"set", 1, 0, 'S'}, CF_LONG_OPTS_DEBUG
54 #define CF_NO_LONG_OPTS (const struct option []) { CF_LONG_OPTS { NULL, 0, 0, 0 } }
56 #define CF_USAGE_TAB ""
59 "-C, --config filename\t" CF_USAGE_TAB "Override the default configuration file\n\
60 -S, --set sec.item=val\t" CF_USAGE_TAB "Manual setting of a configuration item\n" CF_USAGE_DEBUG
63 #define CF_LONG_OPTS_DEBUG { "dumpconfig", 0, 0, 0x64436667 } ,
64 #define CF_USAGE_DEBUG " --dumpconfig\t" CF_USAGE_TAB "Dump program configuration\n"
66 #define CF_LONG_OPTS_DEBUG
67 #define CF_USAGE_DEBUG
71 int cf_getopt(int argc, char * const argv[], const char *short_opts, const struct option *long_opts, int *long_index);