53 "config.formatstr.link = '< %s'",
54 "config.formatstr.number.dec = '= %lld'",
55 "config.formatstr.number.hex = '= 0x%llX'",
56 "config.formatstr.number.oct = '= 0%llo'",
57 "config.formatstr.real = '= %Lg'",
58 "config.formatstr.real.dec = '= %Lf'",
59 "config.formatstr.real.sci = '= %Le'",
60 "config.formatstr.string = '= %s'",
61 "config.formatstr.string.dquoted = '= \"%s\"'",
62 "config.formatstr.string.quoted = '= ''%s'''",
63 "config.formatstr.word = '= %s'",
64 "config.formatstr.bool = '= %d'",
67 "config.formatdef.link < config.formatstr.link",
68 "config.formatdef.number < config.formatstr.number.dec",
69 "config.formatdef.real < config.formatstr.real",
70 "config.formatdef.string < config.formatstr.string",
71 "config.formatdef.word < config.formatstr.word",
72 "config.formatdef.bool < config.formatstr.bool",
75 "config.formatkey ='config.format.%s'",
82 LumieraConfig lumiera_global_config = NULL;
89 REQUIRE (!lumiera_global_config,
"Configuration subsystem already initialised");
93 lumiera_global_config =
lumiera_malloc (
sizeof (*lumiera_global_config));
96 lumiera_configitem_init (&lumiera_global_config->defaults);
97 lumiera_configitem_init (&lumiera_global_config->files);
98 lumiera_configitem_init (&lumiera_global_config->TODO_unknown);
100 lumiera_mutex_init (&lumiera_global_config->lock,
"config mutex", &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT);
117 if (lumiera_global_config)
120 lumiera_configitem_destroy (&lumiera_global_config->defaults, &lumiera_global_config->keys);
121 lumiera_configitem_destroy (&lumiera_global_config->files, &lumiera_global_config->keys);
122 lumiera_configitem_destroy (&lumiera_global_config->TODO_unknown, &lumiera_global_config->keys);
125 lumiera_global_config = NULL;
128 WARN (config_dbg,
"Config system not initialised or already destroyed");
133 lumiera_config_load (
const char* file)
143 lumiera_config_save ()
152 lumiera_config_purge (
const char* filename)
163 lumiera_config_get (
const char* key,
const char** value)
174 LUMIERA_CONFIG_KEY_CHARS,
175 LUMIERA_CONFIG_ENV_CHARS,
182 *value = getenv (env);
185 NOTICE (config,
"envvar override for config %s = %s", env, *value);
194 *value = item->delim+1;
210 lumiera_config_get_default (
const char* key,
const char** value)
222 if (item && item->parent == &lumiera_global_config->defaults)
224 *value = item->delim+1;
237 if (item && item->parent != &lumiera_global_config->defaults)
239 TODO (
"is a user writable file?");
240 TODO (
" replace delim_value");
241 lumiera_configitem_set_value (item, delim_value);
245 TODO (
"create item");
246 TODO (
" find matching prefix");
247 TODO (
" find matching suffix");
248 TODO (
" find proper prefix indentation, else use config.indent");
249 TODO (
" create configitem with prefix/suffix removed");
252 item = lumiera_configitem_new (line);
256 TODO (
"next 2 ensure must generate runtime errors");
257 ENSURE (item->delim,
"syntax error");
258 ENSURE (*item->delim ==
'=' || *item->delim ==
'<',
"syntax error,");
260 TODO (
"insert in proper parent (file)");
261 llist_insert_tail (&lumiera_global_config->TODO_unknown.children, &item->link);
262 item->parent = &lumiera_global_config->TODO_unknown;
265 TODO (
"tag file as dirty");
279 LumieraConfigitem item = NULL;
283 const char* key = line;
284 while (*key && isspace (*key))
291 item = lumiera_configitem_new (line);
295 ENSURE (item->delim,
"default must be a configentry with key=value or key<delegate syntax");
296 ENSURE (*item->delim ==
'=' || *item->delim ==
'<',
"default must be a configentry with key=value or key<delegate syntax");
297 TRACE (config_dbg,
"registering default: '%s'", item->line);
299 llist_insert_head (&lumiera_global_config->defaults.children, &item->link);
300 item->parent = &lumiera_global_config->defaults;
314 fprintf (out,
"# registered defaults:\n");
316 LLIST_FOREACH (&lumiera_global_config->defaults.children, node)
317 fprintf (out,
"%s\n", ((LumieraConfigitem) node)->line);
319 fprintf (out,
"# end of defaults\n\n");
322 fprintf (out,
"# files:\n");
323 lumiera_configitem files;
324 fprintf (out,
"# volatiles:")
325 lumiera_configitem TODO_unknown;
331 lumiera_config_reset (
const char* key)
341 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.