blob: c15ba9da8dfd4dd22f7434d36ed9032de6042480 [file] [log] [blame]
Robert Bieberd5b24dd2010-05-25 15:19:52 +00001/***************************************************************************
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 Bieberc5e14b52010-05-31 17:39:58 +000025#ifdef __cplusplus
26extern "C"
27{
28#endif
Robert Bieber64321ad2010-06-10 21:02:44 +000029#include <stdlib.h>
Robert Bieberd5b24dd2010-05-25 15:19:52 +000030
31/********************************************************************
32 ****** Data Structures *********************************************
33 *******************************************************************/
34
35/* Possible types of element in a WPS file */
36enum skin_element_type
37{
Robert Bieberd1659d62010-06-01 07:11:23 +000038 VIEWPORT,
Robert Bieber6980c1e2010-05-29 00:04:04 +000039 LINE,
Robert Bieber8ea056d2010-05-27 19:57:15 +000040 SUBLINES,
Robert Bieber6980c1e2010-05-29 00:04:04 +000041 CONDITIONAL,
42 TAG,
Robert Bieber6980c1e2010-05-29 00:04:04 +000043 TEXT,
44 COMMENT,
Robert Bieberd5b24dd2010-05-25 15:19:52 +000045};
46
47enum 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 */
64struct 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;
Robert Bieber5943f4c2010-06-01 19:55:20 +000080
81 char type_code;
Robert Bieberd5b24dd2010-05-25 15:19:52 +000082
83};
84
85/* Defines an element of a SKIN file */
86struct skin_element
87{
88 /* Defines what type of element it is */
89 enum skin_element_type type;
90
91 /* The line on which it's defined in the source file */
92 int line;
93
Robert Bieber64321ad2010-06-10 21:02:44 +000094 /* Placeholder for element data
95 * TEXT and COMMENT uses it for the text string
96 * TAG, VIEWPORT, LINE, etc may use it for post parse extra storage
97 */
98 void* data;
Robert Bieberd5b24dd2010-05-25 15:19:52 +000099
100 /* The tag or conditional name */
Robert Bieber0a054b22010-06-01 16:44:52 +0000101 struct tag_info *tag;
Robert Bieberd5b24dd2010-05-25 15:19:52 +0000102
103 /* Pointer to and size of an array of parameters */
104 int params_count;
105 struct skin_tag_parameter* params;
106
107 /* Pointer to and size of an array of children */
108 int children_count;
109 struct skin_element** children;
110
111 /* Link to the next element */
112 struct skin_element* next;
113};
114
115/***********************************************************************
116 ***** Functions *******************************************************
117 **********************************************************************/
118
119/* Parses a WPS document and returns a list of skin_element
120 structures. */
Robert Biebera9848ce2010-06-01 21:25:02 +0000121struct skin_element* skin_parse(const char* document);
Robert Bieberd5b24dd2010-05-25 15:19:52 +0000122
123/* Memory management functions */
Robert Bieber64321ad2010-06-10 21:02:44 +0000124char *skin_alloc(size_t size);
Robert Bieberd5b24dd2010-05-25 15:19:52 +0000125struct skin_element* skin_alloc_element();
126struct skin_element** skin_alloc_children(int count);
127struct skin_tag_parameter* skin_alloc_params(int count);
128char* skin_alloc_string(int length);
129
Robert Bieber0769fc52010-05-25 22:24:08 +0000130void skin_free_tree(struct skin_element* root);
131
Robert Bieber64321ad2010-06-10 21:02:44 +0000132
Robert Bieberc5e14b52010-05-31 17:39:58 +0000133#ifdef __cplusplus
134}
135#endif
136
Robert Bieberd5b24dd2010-05-25 15:19:52 +0000137#endif /* GENERIC_PARSER_H */