45 static LumieraConfigitem parse_directive (LumieraConfigitem
self,
char* itr);
47 static LumieraConfigitem parse_section (LumieraConfigitem
self,
char* itr);
49 static LumieraConfigitem parse_configentry (LumieraConfigitem
self,
char* itr);
56 lumiera_configitem_init (LumieraConfigitem
self)
58 TRACE (configitem_dbg);
61 llist_init (&self->link);
63 llist_init (&self->children);
65 llist_init (&self->lookup);
79 lumiera_configitem_destroy (LumieraConfigitem
self, LumieraConfigLookup lookup)
81 TRACE (configitem_dbg);
86 lumiera_configitem_delete ((LumieraConfigitem) node, lookup);
88 ENSURE (llist_is_empty (&self->children),
"destructor didn't remove children");
90 if (self->vtable && self->vtable->destroy)
91 self->vtable->destroy (
self);
93 if (!llist_is_empty (&self->lookup))
96 llist_unlink (&self->link);
105 lumiera_configitem_new (
const char* line)
107 TRACE (configitem_dbg,
"%s", line);
109 lumiera_configitem tmp;
110 lumiera_configitem_init (&tmp);
112 lumiera_configitem_parse (&tmp, line);
114 LumieraConfigitem
self = tmp.vtable && tmp.vtable->newitem
115 ? tmp.vtable->newitem (&tmp)
116 : lumiera_configitem_move (
lumiera_malloc (
sizeof (*
self)), &tmp);
123 lumiera_configitem_delete (LumieraConfigitem
self, LumieraConfigLookup lookup)
125 TRACE (configitem_dbg);
126 lumiera_free (lumiera_configitem_destroy (
self, lookup));
131 lumiera_configitem_set_value (LumieraConfigitem
self,
const char* delim_value)
134 REQUIRE (self->delim);
137 lumiera_configitem_parse (
self, line);
144 lumiera_configitem_move (LumieraConfigitem
self, LumieraConfigitem source)
146 TRACE (configitem_dbg);
150 llist_init (&self->link);
151 llist_insertlist_next (&self->link, &source->link);
153 self->parent = source->parent;
155 llist_init (&self->children);
156 llist_insertlist_next (&self->children, &source->children);
158 llist_init (&self->lookup);
159 llist_insertlist_next (&self->lookup, &source->lookup);
161 self->line = source->line;
164 self->key = source->key;
165 self->key_size = source->key_size;
166 self->delim = source->delim;
167 self->vtable = source->vtable;
174 lumiera_configitem_parse (LumieraConfigitem
self,
const char* line)
176 TRACE (configitem_dbg);
183 char* itr =
self->line;
186 while (*itr && isspace (*itr))
190 if (!*itr || *itr ==
'#' )
194 else if (*itr ==
'@' )
197 self = parse_directive (
self, itr);
199 else if (*itr ==
'[' )
202 self = parse_section (
self, itr);
207 self = parse_configentry (
self, itr);
214 static LumieraConfigitem
215 parse_directive (LumieraConfigitem
self,
char* itr)
222 if (*itr && !isspace(*itr))
225 self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS);
227 itr +=
self->key_size;
232 if ( self->key_size && ( !*itr || (*itr && isspace(*itr)) ))
237 while (*itr && isspace (*itr))
243 self->delim = itr - 1;
273 static LumieraConfigitem
274 parse_section (LumieraConfigitem
self,
char* itr)
278 while (*itr && isspace(*itr))
285 self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS);
287 itr +=
self->key_size;
291 if (self->key_size && *itr && *itr ==
']')
294 TODO(
"self->vtable = &lumiera_configsection_funcs;");
296 else if (self->key_size && *itr && isspace(*itr))
299 while (*itr && isspace(*itr))
302 if (*itr && *itr ==
']')
306 self->delim = itr - 1;
307 TODO(
"self->vtable = &lumiera_configsection_funcs;");
311 TODO(
"check wheter suffix is made of legal characters");
315 self->delim = itr - 1;
316 TODO(
"self->vtable = &lumiera_configsection_funcs;");
343 static LumieraConfigitem
344 parse_configentry (LumieraConfigitem
self,
char* itr)
350 self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS);
353 itr +=
self->key_size;
354 while (*itr && isspace (*itr))
357 if (self->key_size && *itr ==
'=')
361 self->vtable = &lumiera_configentry_funcs;
363 else if (self->key_size && *itr ==
'<')
367 self->vtable = &lumiera_configentry_funcs;
Portable and safe wrappers around some C-Lib functions.
#define LUMIERA_ERROR_SET(flag, err, extra)
Helper macro to raise an error for the current thread.
Draft for a configuration system (2008).
Draft for a configuration system (2008).
Interface for a lumiera configuration system (draft).
This header is for including and configuring NoBug.
Round robin temporary buffers.
static void lumiera_free(void *mem)
Free previously allocated memory.
void * lumiera_malloc(size_t size)
Allocate memory.
LumieraConfigitem lumiera_config_lookup_remove(LumieraConfigLookup self, LumieraConfigitem item)
Remove a config item from a lookup structure.
Intrusive cyclic double linked list There is only one node type which contains a forward and a backwa...
char * lumiera_strndup(const char *str, size_t len)
Duplicate a C string.
#define LLIST_WHILE_HEAD(list, head)
Consume a list from head.
char * lumiera_tmpbuf_snprintf(size_t size, const char *fmt,...)
Construct a string in a tmpbuf.