blob: 7b3ab13ad0b69967e04830e6e7c834aa21469628 [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
25#define SKIN_MAX_MEMORY 1048576
26
27/********************************************************************
28 ****** A global buffer will be used to store the parse tree *******
29 *******************************************************************/
30extern char skin_parse_tree[];
31
32/********************************************************************
33 ****** Data Structures *********************************************
34 *******************************************************************/
35
36/* Possible types of element in a WPS file */
37enum skin_element_type
38{
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,
43 NEWLINE,
44 TEXT,
45 COMMENT,
Robert Bieberd5b24dd2010-05-25 15:19:52 +000046};
47
48enum skin_errorcode
49{
50 MEMORY_LIMIT_EXCEEDED,
51 NEWLINE_EXPECTED,
52 ILLEGAL_TAG,
53 ARGLIST_EXPECTED,
54 TOO_MANY_ARGS,
55 DEFAULT_NOT_ALLOWED,
56 UNEXPECTED_NEWLINE,
57 INSUFFICIENT_ARGS,
58 INT_EXPECTED,
59 SEPERATOR_EXPECTED,
60 CLOSE_EXPECTED,
61 MULTILINE_EXPECTED
62};
63
64/* Holds a tag parameter, either numeric or text */
65struct skin_tag_parameter
66{
67 enum
68 {
69 NUMERIC,
70 STRING,
71 CODE,
72 DEFAULT
73 } type;
74
75 union
76 {
77 int numeric;
78 char* text;
79 struct skin_element* code;
80 } data;
81
82};
83
84/* Defines an element of a SKIN file */
85struct skin_element
86{
87 /* Defines what type of element it is */
88 enum skin_element_type type;
89
90 /* The line on which it's defined in the source file */
91 int line;
92
93 /* Text for comments and plaintext */
94 char* text;
95
96 /* The tag or conditional name */
Robert Bieber0769fc52010-05-25 22:24:08 +000097 char name[3];
Robert Bieberd5b24dd2010-05-25 15:19:52 +000098
99 /* Pointer to and size of an array of parameters */
100 int params_count;
101 struct skin_tag_parameter* params;
102
103 /* Pointer to and size of an array of children */
104 int children_count;
105 struct skin_element** children;
106
107 /* Link to the next element */
108 struct skin_element* next;
109};
110
111/***********************************************************************
112 ***** Functions *******************************************************
113 **********************************************************************/
114
115/* Parses a WPS document and returns a list of skin_element
116 structures. */
117struct skin_element* skin_parse(char* document);
118
119/* Memory management functions */
120struct skin_element* skin_alloc_element();
121struct skin_element** skin_alloc_children(int count);
122struct skin_tag_parameter* skin_alloc_params(int count);
123char* skin_alloc_string(int length);
124
Robert Bieber0769fc52010-05-25 22:24:08 +0000125void skin_free_tree(struct skin_element* root);
126
Robert Bieberd5b24dd2010-05-25 15:19:52 +0000127#endif /* GENERIC_PARSER_H */