Lumiera  0.pre.03
»edit your freedom«
config.h File Reference

Go to the source code of this file.

Description

Interface for a lumiera configuration system (draft).

This configuration uses ini-style configuration files and supports some simple types. A mechanism for overlay / cascading was planned. After some debate it turned out that we had no clear vision regarding the scope of that effort: should this system also manage (layered) defaults? should it also be able to save user preferences? Anyway, development in that area stalled and never reached the level of just loading and parsing a simple file – yet this was not considered a roadblock and we agreed to revisit the topic when we've gained a better understanding of session storage and management of default values and user preferences.

Todo:
as of 2016, this code is not in any meaningful use
See also
lumiera::BasicSetup simple start-up configuration
http://lumiera.org/documentation/technical/vault/ConfigLoader.html ConfigLoader draft from 2008

Definition in file config.h.

#include "lib/error.h"
#include "lib/mutex.h"
#include "common/config-lookup.h"
#include "common/configitem.h"
#include <nobug.h>
#include <stdio.h>

Classes

struct  lumiera_config
 

Typedefs

typedef lumiera_config * LumieraConfig
 

Macros

#define LUMIERA_CONFIG_ENV_CHARS   "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789__"
 
#define LUMIERA_CONFIG_KEY_CHARS   "abcdefghijklmnopqrstuvwxyz0123456789_."
 
#define LUMIERA_CONFIG_TYPE(name, type)
 
#define LUMIERA_CONFIG_TYPE(name, type)
 
#define LUMIERA_CONFIG_TYPES
 Supported high level types: TODO documenting. More...
 

Functions

void lumiera_config_destroy ()
 Destroys the configuration subsystem. More...
 
void lumiera_config_dump (FILE *out)
 Does a diagnostic dump of the whole config database.
 
const char * lumiera_config_get (const char *key, const char **value)
 
const char * lumiera_config_get_default (const char *key, const char **value)
 
int lumiera_config_info (const char *key, const char **filename, unsigned *line)
 
int lumiera_config_init (const char *path)
 Initialise the configuration subsystem. More...
 
int lumiera_config_load (const char *file)
 
int lumiera_config_purge (const char *filename)
 
LUMIERA_CONFIG_TYPES int lumiera_config_reset (const char *key)
 
int lumiera_config_save ()
 
LumieraConfigitem lumiera_config_set (const char *key, const char *delim_value)
 
LumieraConfigitem lumiera_config_setdefault (const char *line)
 Installs a default value for a config key. More...
 
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. More...
 
int lumiera_config_wordlist_find (const char *key, const char *value, const char *delims)
 Find the index of a word in a wordlist. More...
 
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,;". More...
 
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. More...
 
 LUMIERA_ERROR_DECLARE (CONFIG_SYNTAX)
 
 LUMIERA_ERROR_DECLARE (CONFIG_SYNTAX_KEY)
 
 LUMIERA_ERROR_DECLARE (CONFIG_SYNTAX_VALUE)
 
 LUMIERA_ERROR_DECLARE (CONFIG_NO_ENTRY)
 

Macro Definition Documentation

◆ LUMIERA_CONFIG_TYPES

#define LUMIERA_CONFIG_TYPES
Value:
LUMIERA_CONFIG_TYPE(link, const char*) \
LUMIERA_CONFIG_TYPE(number, long long) \
LUMIERA_CONFIG_TYPE(real, long double) \
LUMIERA_CONFIG_TYPE(string, const char*) \
LUMIERA_CONFIG_TYPE(wordlist, const char*) \
LUMIERA_CONFIG_TYPE(word, const char*) \
LUMIERA_CONFIG_TYPE(bool, int)

Supported high level types: TODO documenting.

Definition at line 82 of file config.h.

◆ LUMIERA_CONFIG_TYPE [1/2]

#define LUMIERA_CONFIG_TYPE (   name,
  type 
)
Value:
const char* \
lumiera_config_##name##_get (const char* key, type* value);
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption

Definition at line 272 of file config.h.

◆ LUMIERA_CONFIG_TYPE [2/2]

#define LUMIERA_CONFIG_TYPE (   name,
  type 
)
Value:
LumieraConfigitem \
lumiera_config_##name##_set (const char* key, type* value);
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption

Definition at line 272 of file config.h.


Class Documentation

◆ lumiera_config_struct

struct lumiera_config_struct
Class Members
lumiera_config_lookup keys
lumiera_configitem defaults
lumiera_configitem files
lumiera_configitem TODO_unknown
lumiera_mutex lock
+ Collaboration diagram for lumiera_config:

Function Documentation

◆ lumiera_config_init()

int lumiera_config_init ( const char *  path)

Initialise the configuration subsystem.

Parameters
pathsearch path for config files. Must be called only once

Definition at line 86 of file config.c.

◆ lumiera_config_destroy()

void lumiera_config_destroy ( )

Destroys the configuration subsystem.

Subsequent calls are no-ops.

Definition at line 114 of file config.c.

◆ lumiera_config_set()

LumieraConfigitem lumiera_config_set ( const char *  key,
const char *  delim_value 
)
Parameters
key
delim_valuedelimiter (= or <) followed by the value to be set

Definition at line 232 of file config.c.

References lumiera_config_lookup_item_find().

+ Here is the call graph for this function:

◆ lumiera_config_setdefault()

LumieraConfigitem lumiera_config_setdefault ( const char *  line)

Installs a default value for a config key.

Any key might have an associated default value which is used when no other configuration is available, this can be set once. Any subsequent call will be a no-op. This function locks the config system.

Parameters
lineline with key, delimiter and value to store as default value
Returns
NULL in case of an error, else a pointer to the default configitem

Definition at line 274 of file config.c.

Referenced by lumiera_plugin_discover().

+ Here is the caller graph for this function:

◆ lumiera_config_wordlist_get_nth()

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,;".

They can be used to store groups of keys and other kinds of simple references into the config system. Here are some functions to manipulate single word entries in a wordlist. Get nth word of a wordlist.

Parameters
keykey under which this wordlist is stored
nthindex of the word to get, starting with 0
delimsa string literal listing all characters which are treated as delimiters
Returns
pointer to a tempbuf holding the nth word or NULL in case of error

Wordlists Wordlists are lists of single words delimited by any of " \t,;".

Definition at line 47 of file config-wordlist.c.

References lumiera_config_wordlist_get().

+ Here is the call graph for this function:

◆ lumiera_config_wordlist_find()

int lumiera_config_wordlist_find ( const char *  key,
const char *  value,
const char *  delims 
)

Find the index of a word in a wordlist.

Parameters
keykey under which this wordlist is stored
valueword to find
delimsa string literal listing all characters which are treated as delimiters
Returns
index of the first occurrence of the word or -1 in case of failure

Definition at line 74 of file config-wordlist.c.

References lumiera_config_wordlist_get().

+ Here is the call graph for this function:

◆ lumiera_config_wordlist_replace()

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.

Replaces a word with up to two new words. This can be used to delete a word (no replacements), insert a new word before an existing word (giving the new word as subst1 and the old word as subst2) insert a new word after an existing word (giving the old word as subst1 and the new word as subst2) or simply give 2 new words.

Parameters
keykey under which this wordlist is stored
valueword to be replaced
subst1first replacement word
subst2second replacement word
delimsa string literal listing all characters which are treated as delimiters
Returns
internal representation of the wordlist in a tmpbuf or NULL in case of an error

Definition at line 97 of file config-wordlist.c.

◆ lumiera_config_wordlist_add()

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.

Parameters
keykey under which this wordlist is stored
valuenew word to add
delimsa string literal listing all characters which are treated as delimiters
Returns
internal representation of the wordlist in a tmpbuf or NULL in case of an error

Definition at line 152 of file config-wordlist.c.