blob: 201e06c25709b68fadbd639b5558e15e7180bb77 [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
29
30
Robert Bieberd5b24dd2010-05-25 15:19:52 +000031#define SKIN_MAX_MEMORY 1048576
32
33/********************************************************************
34 ****** A global buffer will be used to store the parse tree *******
35 *******************************************************************/
36extern char skin_parse_tree[];
37
38/********************************************************************
39 ****** Data Structures *********************************************
40 *******************************************************************/
41
42/* Possible types of element in a WPS file */
43enum skin_element_type
44{
Robert Bieber6980c1e2010-05-29 00:04:04 +000045 LINE,
Robert Bieber8ea056d2010-05-27 19:57:15 +000046 SUBLINES,
Robert Bieber6980c1e2010-05-29 00:04:04 +000047 CONDITIONAL,
48 TAG,
49 NEWLINE,
50 TEXT,
51 COMMENT,
Robert Bieberd5b24dd2010-05-25 15:19:52 +000052};
53
54enum skin_errorcode
55{
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
68};
69
70/* Holds a tag parameter, either numeric or text */
71struct skin_tag_parameter
72{
73 enum
74 {
75 NUMERIC,
76 STRING,
77 CODE,
78 DEFAULT
79 } type;
80
81 union
82 {
83 int numeric;
84 char* text;
85 struct skin_element* code;
86 } data;
87
88};
89
90/* Defines an element of a SKIN file */
91struct skin_element
92{
93 /* Defines what type of element it is */
94 enum skin_element_type type;
95
96 /* The line on which it's defined in the source file */
97 int line;
98
99 /* Text for comments and plaintext */
100 char* text;
101
102 /* The tag or conditional name */
Robert Bieber0769fc52010-05-25 22:24:08 +0000103 char name[3];
Robert Bieberd5b24dd2010-05-25 15:19:52 +0000104
105 /* Pointer to and size of an array of parameters */
106 int params_count;
107 struct skin_tag_parameter* params;
108
109 /* Pointer to and size of an array of children */
110 int children_count;
111 struct skin_element** children;
112
113 /* Link to the next element */
114 struct skin_element* next;
115};
116
117/***********************************************************************
118 ***** Functions *******************************************************
119 **********************************************************************/
120
121/* Parses a WPS document and returns a list of skin_element
122 structures. */
123struct skin_element* skin_parse(char* document);
124
125/* Memory management functions */
126struct skin_element* skin_alloc_element();
127struct skin_element** skin_alloc_children(int count);
128struct skin_tag_parameter* skin_alloc_params(int count);
129char* skin_alloc_string(int length);
130
Robert Bieber0769fc52010-05-25 22:24:08 +0000131void skin_free_tree(struct skin_element* root);
132
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 */