Robert Bieber | d5b24dd | 2010-05-25 15:19:52 +0000 | [diff] [blame^] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2010 Robert Bieber |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #ifndef GENERIC_PARSER_H |
| 23 | #define GENERIC_PARSER_H |
| 24 | |
| 25 | #define SKIN_MAX_MEMORY 1048576 |
| 26 | |
| 27 | /******************************************************************** |
| 28 | ****** A global buffer will be used to store the parse tree ******* |
| 29 | *******************************************************************/ |
| 30 | extern char skin_parse_tree[]; |
| 31 | |
| 32 | /******************************************************************** |
| 33 | ****** Data Structures ********************************************* |
| 34 | *******************************************************************/ |
| 35 | |
| 36 | /* Possible types of element in a WPS file */ |
| 37 | enum skin_element_type |
| 38 | { |
| 39 | TEXT, |
| 40 | NEWLINE, |
| 41 | COMMENT, |
| 42 | TAG, |
| 43 | CONDITIONAL, |
| 44 | SUBLINES |
| 45 | }; |
| 46 | |
| 47 | enum skin_errorcode |
| 48 | { |
| 49 | MEMORY_LIMIT_EXCEEDED, |
| 50 | NEWLINE_EXPECTED, |
| 51 | ILLEGAL_TAG, |
| 52 | ARGLIST_EXPECTED, |
| 53 | TOO_MANY_ARGS, |
| 54 | DEFAULT_NOT_ALLOWED, |
| 55 | UNEXPECTED_NEWLINE, |
| 56 | INSUFFICIENT_ARGS, |
| 57 | INT_EXPECTED, |
| 58 | SEPERATOR_EXPECTED, |
| 59 | CLOSE_EXPECTED, |
| 60 | MULTILINE_EXPECTED |
| 61 | }; |
| 62 | |
| 63 | /* Holds a tag parameter, either numeric or text */ |
| 64 | struct skin_tag_parameter |
| 65 | { |
| 66 | enum |
| 67 | { |
| 68 | NUMERIC, |
| 69 | STRING, |
| 70 | CODE, |
| 71 | DEFAULT |
| 72 | } type; |
| 73 | |
| 74 | union |
| 75 | { |
| 76 | int numeric; |
| 77 | char* text; |
| 78 | struct skin_element* code; |
| 79 | } data; |
| 80 | |
| 81 | }; |
| 82 | |
| 83 | /* Defines an element of a SKIN file */ |
| 84 | struct skin_element |
| 85 | { |
| 86 | /* Defines what type of element it is */ |
| 87 | enum skin_element_type type; |
| 88 | |
| 89 | /* The line on which it's defined in the source file */ |
| 90 | int line; |
| 91 | |
| 92 | /* Text for comments and plaintext */ |
| 93 | char* text; |
| 94 | |
| 95 | /* The tag or conditional name */ |
| 96 | char* name; |
| 97 | |
| 98 | /* Pointer to and size of an array of parameters */ |
| 99 | int params_count; |
| 100 | struct skin_tag_parameter* params; |
| 101 | |
| 102 | /* Pointer to and size of an array of children */ |
| 103 | int children_count; |
| 104 | struct skin_element** children; |
| 105 | |
| 106 | /* Link to the next element */ |
| 107 | struct skin_element* next; |
| 108 | }; |
| 109 | |
| 110 | /*********************************************************************** |
| 111 | ***** Functions ******************************************************* |
| 112 | **********************************************************************/ |
| 113 | |
| 114 | /* Parses a WPS document and returns a list of skin_element |
| 115 | structures. */ |
| 116 | struct skin_element* skin_parse(char* document); |
| 117 | |
| 118 | /* Memory management functions */ |
| 119 | struct skin_element* skin_alloc_element(); |
| 120 | struct skin_element** skin_alloc_children(int count); |
| 121 | struct skin_tag_parameter* skin_alloc_params(int count); |
| 122 | char* skin_alloc_string(int length); |
| 123 | |
| 124 | #endif /* GENERIC_PARSER_H */ |