diff --git a/src/backend/configitem.c b/src/backend/configitem.c index 8015a6e20..457692794 100644 --- a/src/backend/configitem.c +++ b/src/backend/configitem.c @@ -30,13 +30,183 @@ #include "backend/configitem.h" #include "backend/configentry.h" -//TODO: internal/static forward declarations// - //TODO: System includes// #include #include + +//TODO: internal/static forward declarations// + +static LumieraConfigitem +parse_directive(LumieraConfigitem self, char* itr) +{ + /*itr points now to @*/ + self->key = itr; + + /*check whether there are illegal whitespaces after @*/ + itr++; + if (*itr && !isspace(*itr)) + { + /*now look for the end of the directive and set the keysize*/ + self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS); + + itr += self->key_size; + + /*we need a key with a length greather than zero and + * either end of line + * or whitespace after key */ + + if ( self->key_size && ( !*itr || (*itr && isspace(*itr)) )) + { + /*look for given arguments*/ + + /*skip blanks*/ + while (*itr && isspace (*itr)) + itr++; + + if (*itr) + { + /*there are arguments given, thus set delim*/ + self->delim = itr - 1; + } + else + { + /*no arguments were given*/ + self->delim = NULL; + } + } + else + { + /*malformed lines shall be treated like if they were comments*/ + self->key = NULL; + self->key_size = 0; + + LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); + } + } + else + { + /*there occurred already an error right after the @!*/ + /*malformed lines shall be treated like if they were comments*/ + self->key = NULL; + self->key_size = 0; + + LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); + } + return self; +} + +static LumieraConfigitem +parse_section(LumieraConfigitem self, char* itr) +{ + /*skip blanks before prefix*/ + itr++; + while (*itr && isspace(*itr)) + itr++; + + /*itr points now to the begin of the key*/ + self->key = itr; + + /*now look for the end of the key and set the keysize*/ + self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS); + + itr += self->key_size; + + /*if the line ends ends with prefix] delim points to ] + * and not the last (blank) character before the final square bracket*/ + if (self->key_size && *itr && *itr == ']') + { + self->delim = itr; + TODO("self->vtable = &lumiera_configsection_funcs;"); + } + else if (self->key_size && *itr && isspace(*itr)) + { + /* skip blanks until we reach the suffix or the final square bracket*/ + while (*itr && isspace(*itr)) + itr++; + + if (*itr && *itr == ']') + { + /*final square bracket reached, so place delim one char before the + * actual position which must be a whitespace: no extra check necessary*/ + self->delim = itr - 1; + TODO("self->vtable = &lumiera_configsection_funcs;"); + } + else if (*itr) + { + TODO("check wheter suffix is made of legal characters"); + + /*delim points to the last whitespace before the actual position; + * no extra check needed*/ + self->delim = itr - 1; + TODO("self->vtable = &lumiera_configsection_funcs;"); + } + else + { + /*malformed section line, treat this line like a comment*/ + self->key = NULL; + self->key_size = 0; + + LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); + + } + } + else + { + /*error: either *itr is false, points neither to a blank nor to a closed square + * bracket or the key_size is zero*/ + + /*treat this line like a comment*/ + self->key = NULL; + self->key_size = 0; + + LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); + + } + + return self; +} + +static LumieraConfigitem +parse_configentry(LumieraConfigitem self, char* itr) +{ + /*itr points now to the first not-whitespace-character*/ + self->key = itr; + + /*now look for the end of the key and set the keysize*/ + self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS); + + /* skip blanks */ + itr += self->key_size; + while (*itr && isspace (*itr)) + itr++; + + if (self->key_size && *itr == '=') + { + /*this configentry assigns a value to a key*/ + self->delim = itr; + self->vtable = &lumiera_configentry_funcs; + } + else if (self->key_size && *itr == '<') + { + /*this configentry is a redirect*/ + self->delim = itr; + self->vtable = &lumiera_configentry_funcs; + } + else + { + /*this is not a valid configentry; treat this line like a comment*/ + self->key = NULL; + self->key_size = 0; + + LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); + } + + return self; +} + + /** * @file * @@ -172,47 +342,6 @@ lumiera_configitem_parse (LumieraConfigitem self, const char* line) FIXME ("MOCKUP START"); - TODO ("parsing here"); - /* - HOWTO parse (for simav) - in self->line liegt jetzt der 'rohe' string - - parsen setzt folgende werte in self: .key, .key_size, .delim und vtable. den rest macht dann die 'new' funktion aus der vtable - - es geht jetzt da drum rauszufinden ob diese zeile einses der folgenden sachen ist: - (ich zeig hier nur die grundsyntax, das parsen sollte auch entartete situationen behandeln, insbesondere leerzeichen/tabulatoren an allen moeglichen stellen) - auserdem sollt hier alles soweit wie moeglich validiert werden z.b. keys auf erlaubte zeichen gescheckt (siehe die _tr function) - - section: - '[prefix suffix]' - .key == prefix - .delim == das leerzeichen (oder tab) vor suffix oder aufs abschliessende ] wenn kein suffix - - kommentar: - leere zeile, zeile nur aus leerzeichen und tabulatoren, leerzeichen und tabulatoren gefolgt von # bis zum zeilenende - alles ausser vtable auf NULL - - direktive: - '@direktive argumente' - .key == @ - .delim == leerzeichen oder tab vor argumente, NULL wenn keine argumente - - configentry: - 'key = value' - .key == key begin - .delim == '=' - 'key < redirect' - .key == key begin - .delim == '>' - - */ - /* - * What should be working (for cehteh) or not yet.. - * - * die Elemente sollten bereits richtig unterschieden werden, die {} sind noch zu füllen. - * - * */ - char* itr = self->line; /*skip leading whitespaces*/ @@ -226,172 +355,17 @@ lumiera_configitem_parse (LumieraConfigitem self, const char* line) } else if (*itr == '@' ) { - /*this is a directive*/ - - /*itr points now to @*/ - self->key = itr; - - /*check whether there are illegal whitespaces after @*/ - itr++; - if (*itr && !isspace(*itr)) - { - /*now look for the end of the directive and set the keysize*/ - self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS); - - itr += self->key_size; - - /*we need a key with a length greather than zero and - * either end of line - * or whitespace after key */ - - if ( self->key_size && ( !*itr || (*itr && isspace(*itr)) )) - { - /*look for given arguments*/ - - /*skip blanks*/ - while (*itr && isspace (*itr)) - itr++; - - if (*itr) - { - /*there are arguments given, thus set delim*/ - self->delim = itr - 1; - } - else - { - /*no arguments were given*/ - self->delim = NULL; - } - } - else - { - /*malformed lines shall be treated like if they were comments*/ - self->key = NULL; - self->key_size = 0; - - LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); - } - } - else - { - /*there occurred already an error right after the @!*/ - /*malformed lines shall be treated like if they were comments*/ - self->key = NULL; - self->key_size = 0; - - LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); - } + self = parse_directive (self, itr); /*this is a directive*/ } else if (*itr == '[' ) { - /*this is a section*/ - - /*skip blanks before prefix*/ - itr++; - while (*itr && isspace(*itr)) - itr++; - - /*itr points now to the begin of the key*/ - self->key = itr; - - /*now look for the end of the key and set the keysize*/ - self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS); - - itr += self->key_size; - - /*if the line ends ends with prefix] delim points to ] - * and not the last (blank) character before the final square bracket*/ - if (self->key_size && *itr && *itr == ']') - { - self->delim = itr; - TODO("self->vtable = &lumiera_configsection_funcs;"); - } - else if (self->key_size && *itr && isspace(*itr)) - { - /* skip blanks until we reach the suffix or the final square bracket*/ - while (*itr && isspace(*itr)) - itr++; - - if (*itr && *itr == ']') - { - /*final square bracket reached, so place delim one char before the - * actual position which must be a whitespace: no extra check necessary*/ - self->delim = itr - 1; - TODO("self->vtable = &lumiera_configsection_funcs;"); - } - else if (*itr) - { - TODO("check wheter suffix is made of legal characters"); - - /*delim points to the last whitespace before the actual position; - * no extra check needed*/ - self->delim = itr - 1; - TODO("self->vtable = &lumiera_configsection_funcs;"); - } - else - { - /*malformed section line, treat this line like a comment*/ - self->key = NULL; - self->key_size = 0; - - LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); - - } - } - else - { - /*error: either *itr is false, points neither to a blank nor to a closed square - * bracket or the key_size is zero*/ - - /*treat this line like a comment*/ - self->key = NULL; - self->key_size = 0; - - LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); - - } + self = parse_section (self, itr); /*this is a section*/ } else { - /*this is probably a configentry*/ - - /*itr points now to the first not-whitespace-character*/ - self->key = itr; - - /*now look for the end of the key and set the keysize*/ - self->key_size = strspn (itr, LUMIERA_CONFIG_KEY_CHARS); - - /* skip blanks */ - itr += self->key_size; - while (*itr && isspace (*itr)) - itr++; - - if (self->key_size && *itr == '=') - { - /*this configentry assigns a value to a key*/ - self->delim = itr; - self->vtable = &lumiera_configentry_funcs; - } - else if (self->key_size && *itr == '<') - { - /*this configentry is a redirect*/ - self->delim = itr; - self->vtable = &lumiera_configentry_funcs; - } - else - { - /*this is not a valid configentry; treat this line like a comment*/ - self->key = NULL; - self->key_size = 0; - - LUMIERA_ERROR_SET (config_item, CONFIG_SYNTAX); - } - - + self = parse_configentry (self, itr); /*this is probably a configentry*/ } - - return self; }