1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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
31 /********************************************************************
32 ****** Data Structures *********************************************
33 *******************************************************************/
35 /* Possible types of element in a WPS file */
36 enum skin_element_type
50 MEMORY_LIMIT_EXCEEDED
,
65 /* Holds a tag parameter, either numeric or text */
66 struct skin_tag_parameter
71 DECIMAL
, /* stored in data.number as (whole*10)+part */
81 struct skin_element
* code
;
88 /* Defines an element of a SKIN file */
91 /* Defines what type of element it is */
92 enum skin_element_type type
;
94 /* The line on which it's defined in the source file */
97 /* Placeholder for element data
98 * TEXT and COMMENT uses it for the text string
99 * TAG, VIEWPORT, LINE, etc may use it for post parse extra storage
103 /* The tag or conditional name */
104 struct tag_info
*tag
;
106 /* Pointer to and size of an array of parameters */
108 struct skin_tag_parameter
* params
;
110 /* Pointer to and size of an array of children */
112 struct skin_element
** children
;
114 /* Link to the next element */
115 struct skin_element
* next
;
118 enum skin_cb_returnvalue
120 CALLBACK_ERROR
= -666,
121 FEATURE_NOT_AVAILABLE
,
123 /* > 0 reserved for future use */
125 typedef int (*skin_callback
)(struct skin_element
* element
, void* data
);
127 /***********************************************************************
128 ***** Functions *******************************************************
129 **********************************************************************/
131 /* Parses a WPS document and returns a list of skin_element
134 struct skin_element
* skin_parse(const char* document
,
135 skin_callback callback
, void* callback_data
);
137 struct skin_element
* skin_parse(const char* document
);
139 /* Memory management functions */
140 struct skin_element
* skin_alloc_element(void);
141 struct skin_element
** skin_alloc_children(int count
);
142 struct skin_tag_parameter
* skin_alloc_params(int count
);
143 char* skin_alloc_string(int length
);
145 void skin_free_tree(struct skin_element
* root
);
152 #endif /* GENERIC_PARSER_H */