36 static LumieraConfigitem parse_directive (LumieraConfigitem
self,
char* itr);
38 static LumieraConfigitem parse_section (LumieraConfigitem
self,
char* itr);
40 static LumieraConfigitem parse_configentry (LumieraConfigitem
self,
char* itr);
47 lumiera_configitem_init (LumieraConfigitem
self)
49 TRACE (configitem_dbg);
52 llist_init (&self->link);
54 llist_init (&self->children);
56 llist_init (&self->lookup);
70 lumiera_configitem_destroy (LumieraConfigitem
self, LumieraConfigLookup lookup)
72 TRACE (configitem_dbg);
77 lumiera_configitem_delete ((LumieraConfigitem) node, lookup);
79 ENSURE (llist_is_empty (&self->children),
"destructor didn't remove children");
81 if (self->vtable && self->vtable->destroy)
82 self->vtable->destroy (
self);
84 if (!llist_is_empty (&self->lookup))
87 llist_unlink (&self->link);
96 lumiera_configitem_new (
const char* line)
98 TRACE (configitem_dbg,
"%s", line);
100 lumiera_configitem tmp;
101 lumiera_configitem_init (&tmp);
103 lumiera_configitem_parse (&tmp, line);
105 LumieraConfigitem
self = tmp.vtable && tmp.vtable->newitem
106 ? tmp.vtable->newitem (&tmp)
107 : lumiera_configitem_move (
lumiera_malloc (
sizeof (*
self)), &tmp);
114 lumiera_configitem_delete (LumieraConfigitem
self, LumieraConfigLookup lookup)
116 TRACE (configitem_dbg);
117 lumiera_free (lumiera_configitem_destroy (
self, lookup));
122 lumiera_configitem_set_value (LumieraConfigitem
self,
const char* delim_value)
125 REQUIRE (self->delim);
128 lumiera_configitem_parse (
self, line);
135 lumiera_configitem_move (LumieraConfigitem
self, LumieraConfigitem source)
137 TRACE (configitem_dbg);
141 llist_init (&self->link);
142 llist_insertlist_next (&self->link, &source->link);
144 self->parent = source->parent;
146 llist_init (&self->children);
147 llist_insertlist_next (&self->children, &source->children);
149 llist_init (&self->lookup);
150 llist_insertlist_next (&self->lookup, &source->lookup);
152 self->line = source->line;
155 self->key = source->key;
156 self->key_size = source->key_size;
157 self->delim = source->delim;
158 self->vtable = source->vtable;
165 lumiera_configitem_parse (LumieraConfigitem
self,
const char* line)
167 TRACE (configitem_dbg);
174 char* itr =
self->line;
177 while (*itr && isspace (*itr))
181 if (!*itr || *itr ==
'#' )
185 else if (*itr ==
'@' )
188 self = parse_directive (
self, itr);
190 else if (*itr ==
'[' )
193 self = parse_section (
self, itr);
198 self = parse_configentry (
self, itr);
205 static LumieraConfigitem
206 parse_directive (LumieraConfigitem
self,
char* itr)
213 if (*itr && !isspace(*itr))
216 self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS);
218 itr +=
self->key_size;
223 if ( self->key_size && ( !*itr || (*itr && isspace(*itr)) ))
228 while (*itr && isspace (*itr))
234 self->delim = itr - 1;
264 static LumieraConfigitem
265 parse_section (LumieraConfigitem
self,
char* itr)
269 while (*itr && isspace(*itr))
276 self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS);
278 itr +=
self->key_size;
282 if (self->key_size && *itr && *itr ==
']')
285 TODO(
"self->vtable = &lumiera_configsection_funcs;");
287 else if (self->key_size && *itr && isspace(*itr))
290 while (*itr && isspace(*itr))
293 if (*itr && *itr ==
']')
297 self->delim = itr - 1;
298 TODO(
"self->vtable = &lumiera_configsection_funcs;");
302 TODO(
"check wheter suffix is made of legal characters");
306 self->delim = itr - 1;
307 TODO(
"self->vtable = &lumiera_configsection_funcs;");
334 static LumieraConfigitem
335 parse_configentry (LumieraConfigitem
self,
char* itr)
341 self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS);
344 itr +=
self->key_size;
345 while (*itr && isspace (*itr))
348 if (self->key_size && *itr ==
'=')
352 self->vtable = &lumiera_configentry_funcs;
354 else if (self->key_size && *itr ==
'<')
358 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.