Theme Editor: Fixed bugs in code generation and viewport parsing
[kugel-rb.git] / utils / themeeditor / skin_parser.h
blobd3821c0f9b1e9578ad7c55be9a1ee46bd927adb2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Robert Bieber
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef GENERIC_PARSER_H
23 #define GENERIC_PARSER_H
25 #ifdef __cplusplus
26 extern "C"
28 #endif
31 #define SKIN_MAX_MEMORY 1048576
33 /********************************************************************
34 ****** A global buffer will be used to store the parse tree *******
35 *******************************************************************/
36 extern char skin_parse_tree[];
38 /********************************************************************
39 ****** Data Structures *********************************************
40 *******************************************************************/
42 /* Possible types of element in a WPS file */
43 enum skin_element_type
45 VIEWPORT,
46 LINE,
47 SUBLINES,
48 CONDITIONAL,
49 TAG,
50 TEXT,
51 COMMENT,
54 enum skin_errorcode
56 MEMORY_LIMIT_EXCEEDED,
57 NEWLINE_EXPECTED,
58 ILLEGAL_TAG,
59 ARGLIST_EXPECTED,
60 TOO_MANY_ARGS,
61 DEFAULT_NOT_ALLOWED,
62 UNEXPECTED_NEWLINE,
63 INSUFFICIENT_ARGS,
64 INT_EXPECTED,
65 SEPERATOR_EXPECTED,
66 CLOSE_EXPECTED,
67 MULTILINE_EXPECTED
70 /* Holds a tag parameter, either numeric or text */
71 struct skin_tag_parameter
73 enum
75 NUMERIC,
76 STRING,
77 CODE,
78 DEFAULT
79 } type;
81 union
83 int numeric;
84 char* text;
85 struct skin_element* code;
86 } data;
88 char type_code;
92 /* Defines an element of a SKIN file */
93 struct skin_element
95 /* Defines what type of element it is */
96 enum skin_element_type type;
98 /* The line on which it's defined in the source file */
99 int line;
101 /* Text for comments and plaintext */
102 char* text;
104 /* The tag or conditional name */
105 struct tag_info *tag;
107 /* Pointer to and size of an array of parameters */
108 int params_count;
109 struct skin_tag_parameter* params;
111 /* Pointer to and size of an array of children */
112 int children_count;
113 struct skin_element** children;
115 /* Link to the next element */
116 struct skin_element* next;
119 /***********************************************************************
120 ***** Functions *******************************************************
121 **********************************************************************/
123 /* Parses a WPS document and returns a list of skin_element
124 structures. */
125 struct skin_element* skin_parse(const char* document);
127 /* Memory management functions */
128 struct skin_element* skin_alloc_element();
129 struct skin_element** skin_alloc_children(int count);
130 struct skin_tag_parameter* skin_alloc_params(int count);
131 char* skin_alloc_string(int length);
133 void skin_free_tree(struct skin_element* root);
135 #ifdef __cplusplus
137 #endif
139 #endif /* GENERIC_PARSER_H */