Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1/*
2 CONFIG.h - Lumiera configuration system
3
4 Copyright (C)
5 2008, Christian Thaeter <ct@pipapo.org>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
33#ifndef COMMON_CONFIG_H
34#define COMMON_CONFIG_H
35
36#include "lib/error.h"
37#include "lib/mutex.h"
39#include "common/configitem.h"
40
41#include <nobug.h>
42#include <stdio.h>
43
44
45LUMIERA_ERROR_DECLARE (CONFIG_SYNTAX);
46LUMIERA_ERROR_DECLARE (CONFIG_SYNTAX_KEY);
47LUMIERA_ERROR_DECLARE (CONFIG_SYNTAX_VALUE);
48LUMIERA_ERROR_DECLARE (CONFIG_NO_ENTRY);
49
50#define LUMIERA_CONFIG_KEY_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_."
51#define LUMIERA_CONFIG_ENV_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789__"
52
53
54
56{
57 lumiera_config_lookup keys;
58
59 lumiera_configitem defaults; /* registered default values */
60 lumiera_configitem files; /* all loaded files */
61 lumiera_configitem TODO_unknown; /* all values which are not part of a file and not default TODO: this will be removed when file support is finished */
62
63 lumiera_mutex lock;
64};
65
66typedef struct lumiera_config_struct lumiera_config;
67typedef lumiera_config* LumieraConfig;
68
72/* TODO: add here as 'LUMIERA_CONFIG_TYPE(name, ctype)' the _get/_set prototypes are declared automatically below, you still have to implement them in config.c */
73#define LUMIERA_CONFIG_TYPES \
74 LUMIERA_CONFIG_TYPE(link, const char*) \
75 LUMIERA_CONFIG_TYPE(number, long long) \
76 LUMIERA_CONFIG_TYPE(real, long double) \
77 LUMIERA_CONFIG_TYPE(string, const char*) \
78 LUMIERA_CONFIG_TYPE(wordlist, const char*) \
79 LUMIERA_CONFIG_TYPE(word, const char*) \
80 LUMIERA_CONFIG_TYPE(bool, int)
81
82
88int
89lumiera_config_init (const char* path);
90
91
92
97void
99
100
101// * reads '''one''' single configuration file that will include all settings from other files.
102// * does not read itself but give delegates reading. The actual reading and parsing will be done in configfile object. s.later.
106int
107lumiera_config_load (const char* file);
108
109
110//{{{ lumiera_config_save () { LLIST_FOREACH(config_singleton.files, f) { LumieraFile file = (LumieraFile) f; if(lumiera_configfile_isdirty (file)) lumiera_configfile_save(file); } } }}}
111// * saves all the changed settings to user's configuration files, but recognizes where settings came from and will write them to an appropriate named file. Example: '''changed''' values from ''/usr/local/share/lumiera/plugins/blur.conf'' will be saved into ''~/.lumiera/plugins/blur.conf''
112// * finds out which files are dirty and which settings have to be written to user's config files.
113// * does initiate the actual saving procedure by delegating the save to the actual configfile objects, see below.
114// * empty user configuration files in RAM will be deleted from disk on write.
115// * checks whether the file has changed since last read, and will print out an error if necessary instead of overriding it without notification.
119int
121
122
123// * `lumiera_config_purge(const char* filename)` removes all configs loaded from filename
127int
128lumiera_config_purge (const char* filename);
129
130
134void
135lumiera_config_dump (FILE* out);
136
137
138// * {{{ lumiera_config_get(...) }}}
139// * get a value by key
140// * handles internally everything as string:string key:value pair.
141// * lowlevel function
142// * lumiera_config_integer_get (const char* key, int *value) will return integers instead of strings and return 0 if succeeded and -1 if it failed.
146const char*
147lumiera_config_get (const char* key, const char** value);
148
149
150const char*
151lumiera_config_get_default (const char* key, const char** value);
152
153
154// * {{{ lumiera_config_set(...) }}}
155// * set a value by key
156// * handles internally everything as string:string key:value pair.
157// * lowlevel function
158// * tag file as dirty
159// * set will create a new user configuration file if it does not exist yet or will append a line to the existing one in RAM. These files, tagged as 'dirty', will be only written if save() is called.
160
169lumiera_config_set (const char* key, const char* delim_value);
170
171
181lumiera_config_setdefault (const char* line);
182
183
184
185// * {{{int lumiera_config_TYPE_get(const char* key, TYPE* value, const char* default) }}}
186// High level config interface for different types.
187// if default is given (!NULL) then value is set to default in case key was not found or any other error occurred.
188// error code is still set and -1 (fail) is returned in case of an error, but it might be cleared with no ill effects.
189// NOTE: errors are persistent in our error handler, they must still be cleared, even when ignored.
190// if default is given then 'KEY_NOT_FOUND' is not a error here, if default is NULL then it is
191// NOTE2: default values are given as strings, the config loader remembers a given default value and checks if it got changed
192// when it is _set(). Thus a default value can be suppressed when set/written
196#define LUMIERA_CONFIG_TYPE(name, type) \
197 const char* \
198 lumiera_config_##name##_get (const char* key, type* value);
200#undef LUMIERA_CONFIG_TYPE
201
216const char*
217lumiera_config_wordlist_get_nth (const char* key, unsigned nth, const char* delims);
218
219
227int
228lumiera_config_wordlist_find (const char* key, const char* value, const char* delims);
229
230
244const char*
245lumiera_config_wordlist_replace (const char* key, const char* value, const char* subst1, const char* subst2, const char* delims);
246
247
255const char*
256lumiera_config_wordlist_add (const char* key, const char* value, const char* delims);
257
258// * {{{ lumiera_config_TYPE_set (const char* key, TYPE*value, const char* fmt) }}}
259// Highlevel interface for different types, fmt is a printf format specifier for the desired format, when NULL, defaults apply.
263#define LUMIERA_CONFIG_TYPE(name, type) \
264 LumieraConfigitem \
265 lumiera_config_##name##_set (const char* key, type* value);
267#undef LUMIERA_CONFIG_TYPE
268
269
270
271// * {{{ lumiera_config_reset(...) }}}
272// * reset a value by key to the system default values, thus removes a user's configuration line.
276int
277lumiera_config_reset (const char* key);
278
279
280// * Find exact place of a setting.
284int
285lumiera_config_info (const char* key, const char** filename, unsigned* line);
286
287#endif /*COMMON_CONFIG_H*/
288/*
289// Local Variables:
290// mode: C
291// c-file-style: "gnu"
292// indent-tabs-mode: nil
293// End:
294*/
Lookup of configuration keys in a low-level configuration system.
int lumiera_config_purge(const char *filename)
Definition config.c:143
#define LUMIERA_CONFIG_TYPES
Supported high level types: TODO documenting.
Definition config.h:73
lumiera_config_lookup keys
Definition config.h:57
void lumiera_config_dump(FILE *out)
Does a diagnostic dump of the whole config database.
Definition config.c:303
const char * lumiera_config_wordlist_replace(const char *key, const char *value, const char *subst1, const char *subst2, const char *delims)
Universal word replacement function.
int lumiera_config_info(const char *key, const char **filename, unsigned *line)
Definition config.c:332
LumieraConfigitem lumiera_config_set(const char *key, const char *delim_value)
Definition config.c:223
int lumiera_config_load(const char *file)
Definition config.c:124
LUMIERA_CONFIG_TYPES const char * lumiera_config_wordlist_get_nth(const char *key, unsigned nth, const char *delims)
Wordlists Wordlists are lists of single words delimited by any of " \t,;".
lumiera_configitem defaults
Definition config.h:59
int lumiera_config_init(const char *path)
Initialise the configuration subsystem.
Definition config.c:77
int lumiera_config_wordlist_find(const char *key, const char *value, const char *delims)
Find the index of a word in a wordlist.
lumiera_configitem files
Definition config.h:60
int lumiera_config_save()
Definition config.c:134
LumieraConfigitem lumiera_config_setdefault(const char *line)
Installs a default value for a config key.
Definition config.c:265
lumiera_mutex lock
Definition config.h:63
lumiera_config * LumieraConfig
Definition config.h:67
const char * lumiera_config_get(const char *key, const char **value)
Definition config.c:154
void lumiera_config_destroy()
Destroys the configuration subsystem.
Definition config.c:105
const char * lumiera_config_wordlist_add(const char *key, const char *value, const char *delims)
Add a word to the end of a wordlist if it doesn't exist already.
LUMIERA_CONFIG_TYPES int lumiera_config_reset(const char *key)
Definition config.c:322
const char * lumiera_config_get_default(const char *key, const char **value)
Definition config.c:201
lumiera_configitem TODO_unknown
Definition config.h:61
Draft for a configuration system (2008).
lumiera_configitem * LumieraConfigitem
Definition configitem.h:53
Lumiera error handling (C interface).
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition error.h:62
Mutual exclusion locking, header.