diff options
Diffstat (limited to 'lib/skin_parser/skin_scan.c')
-rw-r--r-- | lib/skin_parser/skin_scan.c | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/lib/skin_parser/skin_scan.c b/lib/skin_parser/skin_scan.c new file mode 100644 index 0000000000..79f7162aab --- /dev/null +++ b/lib/skin_parser/skin_scan.c | |||
@@ -0,0 +1,218 @@ | |||
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 | #include <stdio.h> | ||
23 | #include <ctype.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #include "skin_scan.h" | ||
28 | #include "skin_debug.h" | ||
29 | #include "symbols.h" | ||
30 | #include "skin_parser.h" | ||
31 | |||
32 | /* Scanning Functions */ | ||
33 | |||
34 | /* Simple function to advance a char* past a comment */ | ||
35 | void skip_comment(char** document) | ||
36 | { | ||
37 | while(**document != '\n' && **document != '\0') | ||
38 | (*document)++; | ||
39 | if(**document == '\n') | ||
40 | (*document)++; | ||
41 | } | ||
42 | |||
43 | void skip_whitespace(char** document) | ||
44 | { | ||
45 | while(**document == ' ' || **document == '\t') | ||
46 | (*document)++; | ||
47 | } | ||
48 | |||
49 | void skip_arglist(char** document) | ||
50 | { | ||
51 | if(**document == ARGLISTOPENSYM) | ||
52 | (*document)++; | ||
53 | while(**document && **document != ARGLISTCLOSESYM) | ||
54 | { | ||
55 | if(**document == TAGSYM) | ||
56 | { | ||
57 | (*document)++; | ||
58 | if(**document == '\0') | ||
59 | break; | ||
60 | (*document)++; | ||
61 | } | ||
62 | else if(**document == ARGLISTOPENSYM) | ||
63 | skip_arglist(document); | ||
64 | else if(**document == ENUMLISTOPENSYM) | ||
65 | skip_enumlist(document); | ||
66 | else if(**document == COMMENTSYM) | ||
67 | skip_comment(document); | ||
68 | else | ||
69 | (*document)++; | ||
70 | } | ||
71 | if(**document == ARGLISTCLOSESYM) | ||
72 | (*document)++; | ||
73 | } | ||
74 | |||
75 | void skip_enumlist(char** document) | ||
76 | { | ||
77 | if(**document == ENUMLISTOPENSYM) | ||
78 | (*document)++; | ||
79 | while(**document && **document != ENUMLISTCLOSESYM) | ||
80 | { | ||
81 | if(**document == TAGSYM) | ||
82 | { | ||
83 | (*document)++; | ||
84 | if(**document == '\0') | ||
85 | break; | ||
86 | (*document)++; | ||
87 | } | ||
88 | else if(**document == ARGLISTOPENSYM) | ||
89 | skip_arglist(document); | ||
90 | else if(**document == ENUMLISTOPENSYM) | ||
91 | skip_enumlist(document); | ||
92 | else if(**document == COMMENTSYM) | ||
93 | skip_comment(document); | ||
94 | else | ||
95 | (*document)++; | ||
96 | } | ||
97 | |||
98 | if(**document == ENUMLISTCLOSESYM) | ||
99 | (*document)++; | ||
100 | } | ||
101 | |||
102 | char* scan_string(char** document) | ||
103 | { | ||
104 | |||
105 | char* cursor = *document; | ||
106 | int length = 0; | ||
107 | char* buffer = NULL; | ||
108 | int i; | ||
109 | |||
110 | while(*cursor != ARGLISTSEPERATESYM && *cursor != ARGLISTCLOSESYM && | ||
111 | *cursor != '\0') | ||
112 | { | ||
113 | if(*cursor == COMMENTSYM) | ||
114 | { | ||
115 | skip_comment(&cursor); | ||
116 | continue; | ||
117 | } | ||
118 | |||
119 | if(*cursor == TAGSYM) | ||
120 | cursor++; | ||
121 | |||
122 | if(*cursor == '\n') | ||
123 | { | ||
124 | skin_error(UNEXPECTED_NEWLINE); | ||
125 | return NULL; | ||
126 | } | ||
127 | |||
128 | length++; | ||
129 | cursor++; | ||
130 | } | ||
131 | |||
132 | /* Copying the string */ | ||
133 | cursor = *document; | ||
134 | buffer = skin_alloc_string(length); | ||
135 | buffer[length] = '\0'; | ||
136 | for(i = 0; i < length; i++) | ||
137 | { | ||
138 | if(*cursor == TAGSYM) | ||
139 | cursor++; | ||
140 | |||
141 | if(*cursor == COMMENTSYM) | ||
142 | { | ||
143 | skip_comment(&cursor); | ||
144 | i--; | ||
145 | continue; | ||
146 | } | ||
147 | |||
148 | buffer[i] = *cursor; | ||
149 | cursor++; | ||
150 | } | ||
151 | |||
152 | *document = cursor; | ||
153 | return buffer; | ||
154 | } | ||
155 | |||
156 | int scan_int(char** document) | ||
157 | { | ||
158 | |||
159 | char* cursor = *document, *end; | ||
160 | int length = 0; | ||
161 | char buffer[16]; | ||
162 | int retval; | ||
163 | int i; | ||
164 | |||
165 | while(isdigit(*cursor) || *cursor == COMMENTSYM || *cursor == '-') | ||
166 | { | ||
167 | if(*cursor == COMMENTSYM) | ||
168 | { | ||
169 | skip_comment(&cursor); | ||
170 | continue; | ||
171 | } | ||
172 | |||
173 | length++; | ||
174 | cursor++; | ||
175 | } | ||
176 | if (length > 15) | ||
177 | length = 15; | ||
178 | end = cursor; | ||
179 | /* Copying to the buffer while avoiding comments */ | ||
180 | cursor = *document; | ||
181 | buffer[length] = '\0'; | ||
182 | for(i = 0; i < length; i++) | ||
183 | { | ||
184 | if(*cursor == COMMENTSYM) | ||
185 | { | ||
186 | skip_comment(&cursor); | ||
187 | i--; | ||
188 | continue; | ||
189 | } | ||
190 | |||
191 | buffer[i] = *cursor; | ||
192 | cursor++; | ||
193 | |||
194 | } | ||
195 | retval = atoi(buffer); | ||
196 | |||
197 | *document = end; | ||
198 | return retval; | ||
199 | } | ||
200 | |||
201 | int check_viewport(char* document) | ||
202 | { | ||
203 | if(strlen(document) < 3) | ||
204 | return 0; | ||
205 | |||
206 | if(document[0] != TAGSYM) | ||
207 | return 0; | ||
208 | |||
209 | if(document[1] != 'V') | ||
210 | return 0; | ||
211 | |||
212 | if(document[2] != ARGLISTOPENSYM | ||
213 | && document[2] != 'l' | ||
214 | && document[2] != 'i') | ||
215 | return 0; | ||
216 | |||
217 | return 1; | ||
218 | } | ||