From fd563a02848477f6b939723a14ff6ceea9655164 Mon Sep 17 00:00:00 2001 From: Simeon Voelkel Date: Mon, 11 Aug 2008 22:08:17 +0200 Subject: [PATCH] WIP: started low-level parser --- src/backend/configitem.c | 79 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/src/backend/configitem.c b/src/backend/configitem.c index 70c397e82..0907c63e9 100644 --- a/src/backend/configitem.c +++ b/src/backend/configitem.c @@ -3,6 +3,7 @@ Copyright (C) Lumiera.org 2008, Christian Thaeter + Simeon Voelkel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -178,9 +179,85 @@ lumiera_configitem_parse (LumieraConfigitem self, const char* line) .delim == '=' 'key < redirect' .key == key begin - .delim == '=' + .delim == '>' */ + /* + * What should be working (for cehteh) or not yet.. + * + * die Elemente sollten bereits richtig unterschieden werden, die {} sind noch zu füllen. + * + * TODO: include für verwendete Funkionen wie strlen und isspace + * + * */ + + int linelength = strlen(self->line); + int pos = 0; + + char* tmp1 = self->line; + + /*skip leading whitespaces*/ + while ( isspace(tmp1[0]) && pos < linelength ) + { + tmp1++; + pos++: + } + + /*decide what this line represents*/ + if ( tmp1[0] == '\0' || pos == linelenght ) + { + /*this was an empty line*/ + } + else + if ( tmp1[0] == '#' ) + { + /*this was a comment*/ + } + else + if ( tmp1[0] == '@' ) + { + /*this was a directive*/ + } + else + if ( tmp1[0] == '[' ) + { + /*this was a section*/ + } + else + { + /*this was a configentry*/ + + /*tmp1 points now to the first not-whitespace-character*/ + self->key = tmp1; + + /*now look for the end of the key and set the keysize*/ + self->keysize = 0; + + while ( ! isspace(tmp1[0]) && pos < linelength ) + { + tmp1++; + self->keysize++; + pos++; + } + + if ( tmp1[0] == '\0' || pos == linelength ) + { + /*error: line ended with end of the key*/ + } + else + { + /*skip the following whitespaces until we reach the delimeter*/ + while ( isspace(tmp1[0]) && pos < linelength ) + { + tmp1++; + pos++; + } + /*TODO: keep on parsing... ;^)*/ + } + + } + + self->vtable = &lumiera_configentry_funcs; // MOCKUP pretend this is a configentry return self;