Index: utils/themeeditor/main.c =================================================================== --- utils/themeeditor/main.c (revision 0) +++ utils/themeeditor/main.c (revision 0) @@ -0,0 +1,12 @@ +#include "generic_parser.h" +#include +#include + +int main(int argc, char* argv[]) +{ + char* doc = "This is a sample WPS document"; + + struct wps_element* test = wps_parse(doc); + + return 0; +} Index: utils/themeeditor/generic_parser.c =================================================================== --- utils/themeeditor/generic_parser.c (revision 0) +++ utils/themeeditor/generic_parser.c (revision 0) @@ -0,0 +1,122 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: skin_fonts.c 25967 2010-05-12 11:51:59Z jdgordon $ + * + * Copyright (C) 2010 Robert Bieber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include + +#include "generic_parser.h" + +/* Declaration of parse tree buffer */ +char wps_parse_tree[WPS_MAX_MEMORY]; +int wps_current_block = 0; + +/* Global variables for the parser */ +int wps_line = 0; + +struct wps_element* wps_parse(char* document) +{ + + struct wps_element* root = NULL; + struct wps_element* current = NULL; + + while(*document != '\0') + { + //Assembling the parse tree + } + + + return root; + +} + +/* Memory management */ +struct wps_element* wps_alloc_element() +{ + char* retval = &wps_parse_tree[wps_current_block * 4]; + + int delta = sizeof(struct wps_element) / (sizeof(char) * 4); + + /* If one block is partially filled, make sure to advance to the + * next one for the next allocation + */ + if(sizeof(struct wps_element) % (sizeof(char) * 4) != 0) + delta++; + + wps_current_block += delta; + + return (struct wps_element*)retval; +} + +struct wps_tag_parameter* wps_alloc_param(int count) +{ + char* retval = &wps_parse_tree[wps_current_block * 4]; + + int delta = sizeof(struct wps_tag_parameter) / (sizeof(char) * 4); + delta *= count; + + /* Correcting uneven alignment */ + if(count * sizeof(struct wps_tag_parameter) % (sizeof(char) * 4) != 0) + delta++; + + wps_current_block += delta; + + return (struct wps_tag_parameter*) retval; + +} + +char* wps_alloc_string(int length) +{ + char* retval = &wps_parse_tree[wps_current_block * 4]; + + /* Checking alignment */ + length++; /* Accounting for the null terminator */ + int delta = length / 4; + if(length % 4 != 0) + delta++; + + wps_current_block += delta; + + if(wps_current_block >= WPS_MAX_MEMORY / 4) + wps_error(MEMORY_LIMIT_EXCEEDED); + + return retval; + +} + +/* Debugging functions */ +void wps_error(enum wps_errorcode error) +{ + + fprintf(stderr, "Error on line %d: ", wps_line); + + switch(error) + { + case MEMORY_LIMIT_EXCEEDED: + fprintf(stderr, "Memory limit exceeded\n"); + + }; + +} + +void wps_debug_tree(struct wps_element* root) +{ + +} Index: utils/themeeditor/makefile =================================================================== --- utils/themeeditor/makefile (revision 0) +++ utils/themeeditor/makefile (revision 0) @@ -0,0 +1,5 @@ +all: generic_parser.o main.c + gcc -o parsetest main.c generic_parser.o + +generic_parser.o: generic_parser.h generic_parser.c + gcc -c -o generic_parser.o generic_parser.c \ No newline at end of file Index: utils/themeeditor/generic_parser.h =================================================================== --- utils/themeeditor/generic_parser.h (revision 0) +++ utils/themeeditor/generic_parser.h (revision 0) @@ -0,0 +1,113 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: skin_fonts.c 25967 2010-05-12 11:51:59Z jdgordon $ + * + * Copyright (C) 2010 Robert Bieber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef GENERIC_PARSER_H +#define GENERIC_PARSER_H + +#define WPS_MAX_MEMORY 1048576 + +/******************************************************************** + ****** A global buffer will be used to store the parse tree ******* + *******************************************************************/ +extern char wps_parse_tree[]; + +/******************************************************************** + ****** Data Structures ********************************************* + *******************************************************************/ + +/* Possible types of element in a WPS file */ +enum wps_element_type +{ + TEXT, + NEWLINE, + TAG, + CONDITIONAL, + SEMICOLON +}; + +enum wps_errorcode +{ + MEMORY_LIMIT_EXCEEDED +}; + +/* Holds a tag parameter, either numeric or text */ +struct wps_tag_parameter +{ + enum + { + NUMERIC, + STRING, + NIL + } type; + + union + { + int numeric; + char* text; + } data; + +}; + +/* Defines an element of a WPS file */ +struct wps_element +{ + /* Defines what type of element it is */ + enum wps_element_type type; + + /* The line on which it's defined in the source file */ + int line; + + /* The original text of the tag */ + char* text; + + /* The tag or conditional name */ + char* name; + + /* Pointer to and size of an array of parameters */ + int params_count; + struct wps_tag_parameter* params; + + /* Pointer to and size of an array of children */ + int children_count; + struct wps_element* children; + + /* Link to the next element */ + struct wps_element* next; +}; + +/*********************************************************************** + ***** Functions ******************************************************* + **********************************************************************/ + +/* Parses a WPS document and returns a list of wps_element + structures. */ +struct wps_element* wps_parse(char* document); + +/* Memory management functions */ +struct wps_element* wps_alloc_element(); +struct wps_tag_parameter* wps_alloc_param(int count); +char* wps_alloc_string(int length); + +/* Debugging functions */ +void wps_error(enum wps_errorcode error); +void wps_debug_tree(struct wps_element* root); + +#endif /* GENERIC_PARSER_H */