Index: utils/themeeditor/tag_table.c =================================================================== --- utils/themeeditor/tag_table.c (revision 0) +++ utils/themeeditor/tag_table.c (revision 0) @@ -0,0 +1,54 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * 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 "tag_table.h" + +#include + +/* The tag definition table */ +struct tag_info legal_tags[] = { + { "V" , "IIiii|ss" }, + { "Vi" , "SIIiii|ss" }, + { "Vd" , "S" }, + { "" , ""} /* Keep this here to mark the end of the table */ +}; + +/* + * Just does a straight search through the tag table to find one by + * the given name + */ +char* find_tag(char* name) +{ + + struct tag_info* current = legal_tags; + + /* + * Continue searching so long as we have a non-empty name string + * and the name of the current element doesn't match the name + * we're searching for + */ + + while(strcmp(current->name, name) && current->name[0] != '\0') + current++; + + return current->params; + +} Property changes on: utils/themeeditor/tag_table.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Index: utils/themeeditor/main.c =================================================================== --- utils/themeeditor/main.c (revision 0) +++ utils/themeeditor/main.c (revision 0) @@ -0,0 +1,13 @@ +#include "generic_parser.h" + +#include +#include + +int main(int argc, char* argv[]) +{ + char* doc = "This is a sample WPS document"; + + struct skin_element* test = skin_parse(doc); + + return 0; +} Property changes on: utils/themeeditor/main.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Index: utils/themeeditor/tag_table.h =================================================================== --- utils/themeeditor/tag_table.h (revision 0) +++ utils/themeeditor/tag_table.h (revision 0) @@ -0,0 +1,62 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * 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 TAG_TABLE_H +#define TAG_TABLE_H + +/* + * Struct for tag parsing information + * name - The name of the tag, i.e. V for %V + * params - A string specifying all of the tags parameters, each + * character representing a single parameter. Valid + * characters for parameters are: + * I - Required integer + * i - Optional integer + * S - Required string + * s - Optional string + * F - Required file name + * f - Optional file name + * C - Required WPS code + * Any optional parameter may be replaced in the WPS file + * with a '-'. To specify that parameters may be left off + * altogether, place a '|' in the parameter string. For + * instance, with the parameter string... + * Ii|Ss + * one integer must be specified, one integer can be + * specified or set to default with '-', and the user can + * stop providing parameters at any time after that. + * + */ +struct tag_info +{ + + char* name; + char* params; + +}; + +/* + * Finds a tag by name and returns its parameter list, or an empty + * string if the tag is not found in the table + */ +char* find_tag(char* name); + +#endif /* TAG_TABLE_H */ Property changes on: utils/themeeditor/tag_table.h ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Index: utils/themeeditor/generic_parser.c =================================================================== --- utils/themeeditor/generic_parser.c (revision 0) +++ utils/themeeditor/generic_parser.c (revision 0) @@ -0,0 +1,148 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * 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" +#include "tag_table.h" + +/* Declaration of parse tree buffer */ +char skin_parse_tree[SKIN_MAX_MEMORY]; +int skin_current_block = 0; + +/* Global variables for the parser */ +int skin_line = 0; + +struct skin_element* skin_parse(char* document) +{ + + struct skin_element* root = NULL; + struct skin_element* current = NULL; + + while(*document != '\0') + { + //Assembling the parse tree + break; + } + + printf("%s\n", find_tag("Vi")); + printf("%s\n", find_tag("Vd")); + printf("%s\n", find_tag("s")); + + return root; + +} + +/* Memory management */ +struct skin_element* skin_alloc_element() +{ + +#if 0 + + char* retval = &skin_parse_tree[skin_current_block * 4]; + + int delta = sizeof(struct skin_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 skin_element) % (sizeof(char) * 4) != 0) + delta++; + + skin_current_block += delta; + + return (struct skin_element*)retval; + +#endif + + return (struct skin_element*)malloc(sizeof(struct skin_element)); + +} + +struct skin_tag_parameter* skin_alloc_params(int count) +{ + #if 0 + + char* retval = &skin_parse_tree[skin_current_block * 4]; + + int delta = sizeof(struct skin_tag_parameter) / (sizeof(char) * 4); + delta *= count; + + /* Correcting uneven alignment */ + if(count * sizeof(struct skin_tag_parameter) % (sizeof(char) * 4) != 0) + delta++; + + skin_current_block += delta; + + return (struct skin_tag_parameter*) retval; + + #endif + + return (struct skin_tag_parameter*)malloc(sizeof(struct skin_tag_parameter) + * count); + +} + +char* skin_alloc_string(int length) +{ + +#if 0 + char* retval = &skin_parse_tree[skin_current_block * 4]; + + /* Checking alignment */ + length++; /* Accounting for the null terminator */ + int delta = length / 4; + if(length % 4 != 0) + delta++; + + skin_current_block += delta; + + if(skin_current_block >= SKIN_MAX_MEMORY / 4) + skin_error(MEMORY_LIMIT_EXCEEDED); + + return retval; + +#endif + + return (char*)malloc((sizeof(char) + 1) * length); + +} + +/* Debugging functions */ +void skin_error(enum skin_errorcode error) +{ + + fprintf(stderr, "Error on line %d: ", skin_line); + + switch(error) + { + case MEMORY_LIMIT_EXCEEDED: + fprintf(stderr, "Memory limit exceeded\n"); + + }; + +} + +void skin_debug_tree(struct skin_element* root) +{ + +} Property changes on: utils/themeeditor/generic_parser.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Index: utils/themeeditor/makefile =================================================================== --- utils/themeeditor/makefile (revision 0) +++ utils/themeeditor/makefile (revision 0) @@ -0,0 +1,8 @@ +all: generic_parser.o tag_table.o main.c + gcc -o parsetest main.c generic_parser.o tag_table.o + +generic_parser.o: generic_parser.h generic_parser.c + gcc -c -o generic_parser.o generic_parser.c + +tag_table.o: tag_table.h tag_table.c + gcc -c -o tag_table.o tag_table.c \ No newline at end of file Property changes on: utils/themeeditor/makefile ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision 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$ + * + * 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 SKIN_MAX_MEMORY 1048576 + +/******************************************************************** + ****** A global buffer will be used to store the parse tree ******* + *******************************************************************/ +extern char skin_parse_tree[]; + +/******************************************************************** + ****** Data Structures ********************************************* + *******************************************************************/ + +/* Possible types of element in a WPS file */ +enum skin_element_type +{ + TEXT, + NEWLINE, + TAG, + CONDITIONAL, + SUBLINES +}; + +enum skin_errorcode +{ + MEMORY_LIMIT_EXCEEDED +}; + +/* Holds a tag parameter, either numeric or text */ +struct skin_tag_parameter +{ + enum + { + NUMERIC, + STRING, + DEFAULT + } type; + + union + { + int numeric; + char* text; + } data; + +}; + +/* Defines an element of a SKIN file */ +struct skin_element +{ + /* Defines what type of element it is */ + enum skin_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 skin_tag_parameter* params; + + /* Pointer to and size of an array of children */ + int children_count; + struct skin_element* children; + + /* Link to the next element */ + struct skin_element* next; +}; + +/*********************************************************************** + ***** Functions ******************************************************* + **********************************************************************/ + +/* Parses a SKIN document and returns a list of skin_element + structures. */ +struct skin_element* skin_parse(char* document); + +/* Memory management functions */ +struct skin_element* skin_alloc_element(); +struct skin_tag_parameter* skin_alloc_params(int count); +char* skin_alloc_string(int length); + +/* Debugging functions */ +void skin_error(enum skin_errorcode error); +void skin_debug_tree(struct skin_element* root); + +#endif /* GENERIC_PARSER_H */ Property changes on: utils/themeeditor/generic_parser.h ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision