44 "config.formatstr.link = '< %s'",
45 "config.formatstr.number.dec = '= %lld'",
46 "config.formatstr.number.hex = '= 0x%llX'",
47 "config.formatstr.number.oct = '= 0%llo'",
48 "config.formatstr.real = '= %Lg'",
49 "config.formatstr.real.dec = '= %Lf'",
50 "config.formatstr.real.sci = '= %Le'",
51 "config.formatstr.string = '= %s'",
52 "config.formatstr.string.dquoted = '= \"%s\"'",
53 "config.formatstr.string.quoted = '= ''%s'''",
54 "config.formatstr.word = '= %s'",
55 "config.formatstr.bool = '= %d'",
58 "config.formatdef.link < config.formatstr.link",
59 "config.formatdef.number < config.formatstr.number.dec",
60 "config.formatdef.real < config.formatstr.real",
61 "config.formatdef.string < config.formatstr.string",
62 "config.formatdef.word < config.formatstr.word",
63 "config.formatdef.bool < config.formatstr.bool",
66 "config.formatkey ='config.format.%s'",
73 LumieraConfig lumiera_global_config = NULL;
80 REQUIRE (!lumiera_global_config,
"Configuration subsystem already initialised");
84 lumiera_global_config =
lumiera_malloc (
sizeof (*lumiera_global_config));
87 lumiera_configitem_init (&lumiera_global_config->defaults);
88 lumiera_configitem_init (&lumiera_global_config->files);
89 lumiera_configitem_init (&lumiera_global_config->TODO_unknown);
91 lumiera_mutex_init (&lumiera_global_config->lock,
"config mutex", &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT);
108 if (lumiera_global_config)
111 lumiera_configitem_destroy (&lumiera_global_config->defaults, &lumiera_global_config->keys);
112 lumiera_configitem_destroy (&lumiera_global_config->files, &lumiera_global_config->keys);
113 lumiera_configitem_destroy (&lumiera_global_config->TODO_unknown, &lumiera_global_config->keys);
116 lumiera_global_config = NULL;
119 WARN (config_dbg,
"Config system not initialised or already destroyed");
124 lumiera_config_load (
const char* file)
134 lumiera_config_save ()
143 lumiera_config_purge (
const char* filename)
154 lumiera_config_get (
const char* key,
const char** value)
165 LUMIERA_CONFIG_KEY_CHARS,
166 LUMIERA_CONFIG_ENV_CHARS,
173 *value = getenv (env);
176 NOTICE (config,
"envvar override for config %s = %s", env, *value);
185 *value = item->delim+1;
201 lumiera_config_get_default (
const char* key,
const char** value)
213 if (item && item->parent == &lumiera_global_config->defaults)
215 *value = item->delim+1;
228 if (item && item->parent != &lumiera_global_config->defaults)
230 TODO (
"is a user writable file?");
231 TODO (
" replace delim_value");
232 lumiera_configitem_set_value (item, delim_value);
236 TODO (
"create item");
237 TODO (
" find matching prefix");
238 TODO (
" find matching suffix");
239 TODO (
" find proper prefix indentation, else use config.indent");
240 TODO (
" create configitem with prefix/suffix removed");
243 item = lumiera_configitem_new (line);
247 TODO (
"next 2 ensure must generate runtime errors");
248 ENSURE (item->delim,
"syntax error");
249 ENSURE (*item->delim ==
'=' || *item->delim ==
'<',
"syntax error,");
251 TODO (
"insert in proper parent (file)");
252 llist_insert_tail (&lumiera_global_config->TODO_unknown.children, &item->link);
253 item->parent = &lumiera_global_config->TODO_unknown;
256 TODO (
"tag file as dirty");
270 LumieraConfigitem item = NULL;
274 const char* key = line;
275 while (*key && isspace (*key))
282 item = lumiera_configitem_new (line);
286 ENSURE (item->delim,
"default must be a configentry with key=value or key<delegate syntax");
287 ENSURE (*item->delim ==
'=' || *item->delim ==
'<',
"default must be a configentry with key=value or key<delegate syntax");
288 TRACE (config_dbg,
"registering default: '%s'", item->line);
290 llist_insert_head (&lumiera_global_config->defaults.children, &item->link);
291 item->parent = &lumiera_global_config->defaults;
305 fprintf (out,
"# registered defaults:\n");
307 LLIST_FOREACH (&lumiera_global_config->defaults.children, node)
308 fprintf (out,
"%s\n", ((LumieraConfigitem) node)->line);
310 fprintf (out,
"# end of defaults\n\n");
313 fprintf (out,
"# files:\n");
314 lumiera_configitem files;
315 fprintf (out,
"# volatiles:")
316 lumiera_configitem TODO_unknown;
322 lumiera_config_reset (
const char* key)
332 lumiera_config_info (
const char* key,
const char** filename,
unsigned* line)
Portable and safe wrappers around some C-Lib functions.
LumieraConfigLookupentry lumiera_config_lookup_insert(LumieraConfigLookup self, LumieraConfigitem item)
Add a config item to a lookup structure.
#define LUMIERA_ERROR_SET(flag, err, extra)
Helper macro to raise an error for the current thread.
LumieraConfigitem lumiera_config_lookup_item_find(LumieraConfigLookup self, const char *key)
Find a the topmost config item stored to a given key.
#define LUMIERA_ERROR_SET_WARNING(flag, err, extra)
Helper macro to raise an error for the current thread.
char * lumiera_tmpbuf_strndup(const char *src, size_t size)
Duplicate string to a tmpbuf.
const char * lumiera_config_defaults[]
defaults for the configuration system itself
Interface for a lumiera configuration system (draft).
#define LUMIERA_MUTEX_SECTION(nobugflag, mtx)
Mutual exclusive section.
LumieraConfigitem lumiera_config_lookup_item_tail_find(LumieraConfigLookup self, const char *key)
Find a the bottom most config item stored to a given key.
This header is for including and configuring NoBug.
Round robin temporary buffers.
static void lumiera_free(void *mem)
Free previously allocated memory.
LumieraConfigitem lumiera_config_setdefault(const char *line)
Installs a default value for a config key.
void * lumiera_malloc(size_t size)
Allocate memory.
char * lumiera_tmpbuf_tr(const char *in, const char *from, const char *to, const char *def)
Translates characters in a string, similar to the shell 'tr' utility.
void lumiera_config_destroy()
Destroys the configuration subsystem.
void lumiera_config_dump(FILE *out)
Does a diagnostic dump of the whole config database.
#define LLIST_FOREACH(list, node)
Iterate forward over a list.
LumieraConfigLookup lumiera_config_lookup_destroy(LumieraConfigLookup self)
Destroy a lookup structure.
LumieraMutex lumiera_mutex_init(LumieraMutex self, const char *purpose, struct nobug_flag *flag, const struct nobug_context ctx)
Initialise a mutex variable This initialises a 'fast' default mutex which must not be locked recursiv...
LumieraConfigLookup lumiera_config_lookup_init(LumieraConfigLookup self)
Initialise a lookup structure.
LumieraConfigitem lumiera_config_set(const char *key, const char *delim_value)
int lumiera_config_init(const char *path)
Initialise the configuration subsystem.
LumieraMutex lumiera_mutex_destroy(LumieraMutex self, struct nobug_flag *flag, const struct nobug_context ctx)
Destroy a mutex variable.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
char * lumiera_tmpbuf_snprintf(size_t size, const char *fmt,...)
Construct a string in a tmpbuf.