2 * UCW Library -- Parsing of configuration and command-line options
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 #ifdef CONFIG_OWN_GETOPT
15 #include "lib/getopt/getopt-sh.h"
20 void reset_getopt(void);
22 /* Safe loading and reloading of configuration files: conf-input.c */
24 extern char *cf_def_file; /* DEFAULT_CONFIG; NULL if already loaded */
25 int cf_reload(const char *file);
26 int cf_load(const char *file);
27 int cf_set(const char *string);
29 /* Direct access to configuration items: conf-intr.c */
31 #define CF_OPERATIONS T(CLOSE) T(SET) T(CLEAR) T(ALL) \
32 T(APPEND) T(PREPEND) T(REMOVE) T(EDIT) T(AFTER) T(BEFORE) T(COPY)
33 /* Closing brace finishes previous block.
34 * Basic attributes (static, dynamic, parsed) can be used with SET.
35 * Dynamic arrays can be used with SET, APPEND, PREPEND.
36 * Sections can be used with SET.
37 * Lists can be used with everything. */
39 enum cf_operation { CF_OPERATIONS };
43 char *cf_find_item(const char *name, struct cf_item *item);
44 char *cf_write_item(struct cf_item *item, enum cf_operation op, int number, char **pars);
46 /* Debug dumping: conf-dump.c */
49 void cf_dump_sections(struct fastbuf *fb);
51 /* Journaling control: conf-journal.c */
53 struct cf_journal_item;
54 struct cf_journal_item *cf_journal_new_transaction(uns new_pool);
55 void cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj);
56 void cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj);
59 * cf_getopt() takes care of parsing the command-line arguments, loading the
60 * default configuration file (cf_def_file) and processing configuration options.
61 * The calling convention is the same as with GNU getopt_long(), but you must prefix
62 * your own short/long options by the CF_(SHORT|LONG)_OPTS or pass CF_NO_LONG_OPTS
63 * of there are no long options.
65 * The default configuration file can be overriden by the --config options,
66 * which must come first. During parsing of all other options, the configuration
67 * is already available.
70 #define CF_SHORT_OPTS "C:S:"
71 #define CF_LONG_OPTS {"config", 1, 0, 'C'}, {"set", 1, 0, 'S'}, CF_LONG_OPTS_DEBUG
72 #define CF_NO_LONG_OPTS (const struct option []) { CF_LONG_OPTS { NULL, 0, 0, 0 } }
74 #define CF_USAGE_TAB ""
77 "-C, --config filename\t" CF_USAGE_TAB "Override the default configuration file\n\
78 -S, --set sec.item=val\t" CF_USAGE_TAB "Manual setting of a configuration item\n" CF_USAGE_DEBUG
81 #define CF_LONG_OPTS_DEBUG { "dumpconfig", 0, 0, 0x64436667 } ,
82 #define CF_USAGE_DEBUG " --dumpconfig\t" CF_USAGE_TAB "Dump program configuration\n"
84 #define CF_LONG_OPTS_DEBUG
85 #define CF_USAGE_DEBUG
89 int cf_getopt(int argc, char * const argv[], const char *short_opts, const struct option *long_opts, int *long_index);