X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fgetopt.h;h=b4ff823ffb4f43bb9087535d79a5f658dc330a53;hb=706c64a62fc9bcf0a86c3f0cbd07374066427cb7;hp=ca3eaf000c30a7b32665d19d2933cd8389ba5446;hpb=a86e328ab75068b1c27e17e3fb33a9b5845f63aa;p=libucw.git diff --git a/lib/getopt.h b/lib/getopt.h index ca3eaf00..b4ff823f 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,26 @@ #ifndef _UCW_GETOPT_H #define _UCW_GETOPT_H -/* Safe reloading and loading of configuration files */ -extern byte *cf_def_file; -int cf_reload(byte *file); -int cf_load(byte *file); -int cf_set(byte *string); +#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 char *cf_def_file; /* DEFAULT_CONFIG; NULL if already loaded */ +extern char *cf_env_file; /* ENV_VAR_CONFIG */ +int cf_reload(const char *file); +int cf_load(const char *file); +int cf_set(const char *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 +41,31 @@ enum cf_operation { CF_OPERATIONS }; #undef T struct cf_item; +char *cf_find_item(const char *name, struct cf_item *item); +char *cf_write_item(struct cf_item *item, enum cf_operation op, int number, char **pars); + +/* Debug dumping: conf-dump.c */ + 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); 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 +86,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