X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fgetopt.h;h=6f29af8a182607990bf41d59275a074d7fdcf2b4;hb=99ddd86376fcb9ad5795f60377c3203944821860;hp=ca3eaf000c30a7b32665d19d2933cd8389ba5446;hpb=a86e328ab75068b1c27e17e3fb33a9b5845f63aa;p=libucw.git diff --git a/lib/getopt.h b/lib/getopt.h index ca3eaf00..6f29af8a 100644 --- a/lib/getopt.h +++ b/lib/getopt.h @@ -1,5 +1,5 @@ /* - * UCW Library -- Reading of configuration files + * UCW Library -- Parsing of configuration and command-line options * * (c) 2001--2006 Robert Spalek * (c) 2003--2006 Martin Mares @@ -11,16 +11,25 @@ #ifndef _UCW_GETOPT_H #define _UCW_GETOPT_H -/* Safe reloading and loading of configuration files */ -extern byte *cf_def_file; +#ifdef CONFIG_OWN_GETOPT +#include "lib/getopt/getopt-sh.h" +#else +#include +#endif + +void reset_getopt(void); + +/* Safe loading and reloading of configuration files: conf-input.c */ + +extern byte *cf_def_file; /* DEFAULT_CONFIG; NULL if already loaded */ int cf_reload(byte *file); int cf_load(byte *file); int cf_set(byte *string); -/* Direct access to configuration items */ +/* Direct access to configuration items: conf-intr.c */ -#define CF_OPERATIONS T(CLOSE) T(SET) T(CLEAR) T(APPEND) T(PREPEND) \ - T(REMOVE) T(EDIT) T(AFTER) T(BEFORE) T(COPY) +#define CF_OPERATIONS T(CLOSE) T(SET) T(CLEAR) T(ALL) \ + T(APPEND) T(PREPEND) T(REMOVE) T(EDIT) T(AFTER) T(BEFORE) T(COPY) /* Closing brace finishes previous block. * Basic attributes (static, dynamic, parsed) can be used with SET. * Dynamic arrays can be used with SET, APPEND, PREPEND. @@ -31,22 +40,31 @@ enum cf_operation { CF_OPERATIONS }; #undef T struct cf_item; -struct fastbuf; byte *cf_find_item(byte *name, struct cf_item *item); byte *cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **pars); + +/* Debug dumping: conf-dump.c */ + +struct fastbuf; void cf_dump_sections(struct fastbuf *fb); +/* Journaling control: conf-journal.c */ + +struct cf_journal_item; +struct cf_journal_item *cf_journal_new_transaction(uns new_pool); +void cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj); +void cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj); + /* - * When using cf_get_opt(), you must prefix your own short/long options by the - * CF_(SHORT|LONG)_OPTS. + * cf_getopt() takes care of parsing the command-line arguments, loading the + * default configuration file (cf_def_file) and processing configuration options. + * The calling convention is the same as with GNU getopt_long(), but you must prefix + * your own short/long options by the CF_(SHORT|LONG)_OPTS or pass CF_NO_LONG_OPTS + * of there are no long options. * - * cf_def_file contains the name of a configuration file that will be - * automatically loaded before the first --set option is executed. If no --set - * option occurs, it will be loaded after getopt() returns -1 (i.e. at the end - * of the configuration options). cf_def_file will be ignored if another - * configuration file has already been loaded using the --config option. The - * initial value of cf_def_file is DEFAULT_CONFIG from config.h, but you can - * override it manually before calling cf_get_opt(). + * The default configuration file can be overriden by the --config options, + * which must come first. During parsing of all other options, the configuration + * is already available. */ #define CF_SHORT_OPTS "C:S:" @@ -67,7 +85,7 @@ void cf_dump_sections(struct fastbuf *fb); #define CF_USAGE_DEBUG #endif -#include +// conf-input.c int cf_getopt(int argc, char * const argv[], const char *short_opts, const struct option *long_opts, int *long_index); #endif