diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-06-17 06:52:02 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-06-17 06:52:02 +0000 |
commit | 36b934d241d2560be6693f90c9aba501a1ec0ae7 (patch) | |
tree | 39b57aa3bc373a967e4d1f7d29671226307294c8 /lib/skin_parser/skin_parser.h | |
parent | ca564287ee3f48945d45c7d92be7a83452f53745 (diff) | |
download | rockbox-36b934d241d2560be6693f90c9aba501a1ec0ae7.tar.gz rockbox-36b934d241d2560be6693f90c9aba501a1ec0ae7.zip |
Move the skin parser to a seperate library
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26877 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'lib/skin_parser/skin_parser.h')
-rw-r--r-- | lib/skin_parser/skin_parser.h | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/lib/skin_parser/skin_parser.h b/lib/skin_parser/skin_parser.h new file mode 100644 index 0000000000..1fc4a7ae6b --- /dev/null +++ b/lib/skin_parser/skin_parser.h | |||
@@ -0,0 +1,138 @@ | |||
1 | /*************************************************************************** | ||
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 | #ifdef __cplusplus | ||
26 | extern "C" | ||
27 | { | ||
28 | #endif | ||
29 | #include <stdlib.h> | ||
30 | |||
31 | /******************************************************************** | ||
32 | ****** Data Structures ********************************************* | ||
33 | *******************************************************************/ | ||
34 | |||
35 | /* Possible types of element in a WPS file */ | ||
36 | enum skin_element_type | ||
37 | { | ||
38 | UNKNOWN = -1, | ||
39 | VIEWPORT, | ||
40 | LINE, | ||
41 | SUBLINES, | ||
42 | CONDITIONAL, | ||
43 | TAG, | ||
44 | TEXT, | ||
45 | COMMENT, | ||
46 | }; | ||
47 | |||
48 | enum 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 */ | ||
65 | struct 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 | char type_code; | ||
83 | |||
84 | }; | ||
85 | |||
86 | /* Defines an element of a SKIN file */ | ||
87 | struct skin_element | ||
88 | { | ||
89 | /* Defines what type of element it is */ | ||
90 | enum skin_element_type type; | ||
91 | |||
92 | /* The line on which it's defined in the source file */ | ||
93 | int line; | ||
94 | |||
95 | /* Placeholder for element data | ||
96 | * TEXT and COMMENT uses it for the text string | ||
97 | * TAG, VIEWPORT, LINE, etc may use it for post parse extra storage | ||
98 | */ | ||
99 | void* data; | ||
100 | |||
101 | /* The tag or conditional name */ | ||
102 | struct tag_info *tag; | ||
103 | |||
104 | /* Pointer to and size of an array of parameters */ | ||
105 | int params_count; | ||
106 | struct skin_tag_parameter* params; | ||
107 | |||
108 | /* Pointer to and size of an array of children */ | ||
109 | int children_count; | ||
110 | struct skin_element** children; | ||
111 | |||
112 | /* Link to the next element */ | ||
113 | struct skin_element* next; | ||
114 | }; | ||
115 | |||
116 | /*********************************************************************** | ||
117 | ***** Functions ******************************************************* | ||
118 | **********************************************************************/ | ||
119 | |||
120 | /* Parses a WPS document and returns a list of skin_element | ||
121 | structures. */ | ||
122 | struct skin_element* skin_parse(const char* document); | ||
123 | |||
124 | /* Memory management functions */ | ||
125 | char *skin_alloc(size_t size); | ||
126 | struct skin_element* skin_alloc_element(); | ||
127 | struct skin_element** skin_alloc_children(int count); | ||
128 | struct skin_tag_parameter* skin_alloc_params(int count); | ||
129 | char* skin_alloc_string(int length); | ||
130 | |||
131 | void skin_free_tree(struct skin_element* root); | ||
132 | |||
133 | |||
134 | #ifdef __cplusplus | ||
135 | } | ||
136 | #endif | ||
137 | |||
138 | #endif /* GENERIC_PARSER_H */ | ||