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 | |
Robert Bieber | c5e14b5 | 2010-05-31 17:39:58 +0000 | [diff] [blame] | 25 | #ifdef __cplusplus |
| 26 | extern "C" |
| 27 | { |
| 28 | #endif |
| 29 | |
| 30 | |
Robert Bieber | d5b24dd | 2010-05-25 15:19:52 +0000 | [diff] [blame] | 31 | #define SKIN_MAX_MEMORY 1048576 |
| 32 | |
| 33 | /******************************************************************** |
| 34 | ****** A global buffer will be used to store the parse tree ******* |
| 35 | *******************************************************************/ |
| 36 | extern char skin_parse_tree[]; |
| 37 | |
| 38 | /******************************************************************** |
| 39 | ****** Data Structures ********************************************* |
| 40 | *******************************************************************/ |
| 41 | |
| 42 | /* Possible types of element in a WPS file */ |
| 43 | enum skin_element_type |
| 44 | { |
Robert Bieber | d1659d6 | 2010-06-01 07:11:23 +0000 | [diff] [blame] | 45 | VIEWPORT, |
Robert Bieber | 6980c1e | 2010-05-29 00:04:04 +0000 | [diff] [blame] | 46 | LINE, |
Robert Bieber | 8ea056d | 2010-05-27 19:57:15 +0000 | [diff] [blame] | 47 | SUBLINES, |
Robert Bieber | 6980c1e | 2010-05-29 00:04:04 +0000 | [diff] [blame] | 48 | CONDITIONAL, |
| 49 | TAG, |
| 50 | NEWLINE, |
| 51 | TEXT, |
| 52 | COMMENT, |
Robert Bieber | d5b24dd | 2010-05-25 15:19:52 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | enum skin_errorcode |
| 56 | { |
| 57 | MEMORY_LIMIT_EXCEEDED, |
| 58 | NEWLINE_EXPECTED, |
| 59 | ILLEGAL_TAG, |
| 60 | ARGLIST_EXPECTED, |
| 61 | TOO_MANY_ARGS, |
| 62 | DEFAULT_NOT_ALLOWED, |
| 63 | UNEXPECTED_NEWLINE, |
| 64 | INSUFFICIENT_ARGS, |
| 65 | INT_EXPECTED, |
| 66 | SEPERATOR_EXPECTED, |
| 67 | CLOSE_EXPECTED, |
| 68 | MULTILINE_EXPECTED |
| 69 | }; |
| 70 | |
| 71 | /* Holds a tag parameter, either numeric or text */ |
| 72 | struct skin_tag_parameter |
| 73 | { |
| 74 | enum |
| 75 | { |
| 76 | NUMERIC, |
| 77 | STRING, |
| 78 | CODE, |
| 79 | DEFAULT |
| 80 | } type; |
| 81 | |
| 82 | union |
| 83 | { |
| 84 | int numeric; |
| 85 | char* text; |
| 86 | struct skin_element* code; |
| 87 | } data; |
Robert Bieber | 5943f4c | 2010-06-01 19:55:20 +0000 | [diff] [blame] | 88 | |
| 89 | char type_code; |
Robert Bieber | d5b24dd | 2010-05-25 15:19:52 +0000 | [diff] [blame] | 90 | |
| 91 | }; |
| 92 | |
| 93 | /* Defines an element of a SKIN file */ |
| 94 | struct skin_element |
| 95 | { |
| 96 | /* Defines what type of element it is */ |
| 97 | enum skin_element_type type; |
| 98 | |
| 99 | /* The line on which it's defined in the source file */ |
| 100 | int line; |
| 101 | |
| 102 | /* Text for comments and plaintext */ |
| 103 | char* text; |
| 104 | |
| 105 | /* The tag or conditional name */ |
Robert Bieber | 0a054b2 | 2010-06-01 16:44:52 +0000 | [diff] [blame] | 106 | struct tag_info *tag; |
Robert Bieber | d5b24dd | 2010-05-25 15:19:52 +0000 | [diff] [blame] | 107 | |
| 108 | /* Pointer to and size of an array of parameters */ |
| 109 | int params_count; |
| 110 | struct skin_tag_parameter* params; |
| 111 | |
| 112 | /* Pointer to and size of an array of children */ |
| 113 | int children_count; |
| 114 | struct skin_element** children; |
| 115 | |
| 116 | /* Link to the next element */ |
| 117 | struct skin_element* next; |
| 118 | }; |
| 119 | |
| 120 | /*********************************************************************** |
| 121 | ***** Functions ******************************************************* |
| 122 | **********************************************************************/ |
| 123 | |
| 124 | /* Parses a WPS document and returns a list of skin_element |
| 125 | structures. */ |
Robert Bieber | a9848ce | 2010-06-01 21:25:02 +0000 | [diff] [blame^] | 126 | struct skin_element* skin_parse(const char* document); |
Robert Bieber | d5b24dd | 2010-05-25 15:19:52 +0000 | [diff] [blame] | 127 | |
| 128 | /* Memory management functions */ |
| 129 | struct skin_element* skin_alloc_element(); |
| 130 | struct skin_element** skin_alloc_children(int count); |
| 131 | struct skin_tag_parameter* skin_alloc_params(int count); |
| 132 | char* skin_alloc_string(int length); |
| 133 | |
Robert Bieber | 0769fc5 | 2010-05-25 22:24:08 +0000 | [diff] [blame] | 134 | void skin_free_tree(struct skin_element* root); |
| 135 | |
Robert Bieber | c5e14b5 | 2010-05-31 17:39:58 +0000 | [diff] [blame] | 136 | #ifdef __cplusplus |
| 137 | } |
| 138 | #endif |
| 139 | |
Robert Bieber | d5b24dd | 2010-05-25 15:19:52 +0000 | [diff] [blame] | 140 | #endif /* GENERIC_PARSER_H */ |