Theme Editor: Factored out code to skip over enum/arg lists while scanning for childr...
[kugel-rb.git] / utils / themeeditor / skin_scan.c
blob79f7162aab9c87a1248594666954a66d3dabe163
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Robert Bieber
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdio.h>
23 #include <ctype.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "skin_scan.h"
28 #include "skin_debug.h"
29 #include "symbols.h"
30 #include "skin_parser.h"
32 /* Scanning Functions */
34 /* Simple function to advance a char* past a comment */
35 void skip_comment(char** document)
37 while(**document != '\n' && **document != '\0')
38 (*document)++;
39 if(**document == '\n')
40 (*document)++;
43 void skip_whitespace(char** document)
45 while(**document == ' ' || **document == '\t')
46 (*document)++;
49 void skip_arglist(char** document)
51 if(**document == ARGLISTOPENSYM)
52 (*document)++;
53 while(**document && **document != ARGLISTCLOSESYM)
55 if(**document == TAGSYM)
57 (*document)++;
58 if(**document == '\0')
59 break;
60 (*document)++;
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)++;
71 if(**document == ARGLISTCLOSESYM)
72 (*document)++;
75 void skip_enumlist(char** document)
77 if(**document == ENUMLISTOPENSYM)
78 (*document)++;
79 while(**document && **document != ENUMLISTCLOSESYM)
81 if(**document == TAGSYM)
83 (*document)++;
84 if(**document == '\0')
85 break;
86 (*document)++;
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)++;
98 if(**document == ENUMLISTCLOSESYM)
99 (*document)++;
102 char* scan_string(char** document)
105 char* cursor = *document;
106 int length = 0;
107 char* buffer = NULL;
108 int i;
110 while(*cursor != ARGLISTSEPERATESYM && *cursor != ARGLISTCLOSESYM &&
111 *cursor != '\0')
113 if(*cursor == COMMENTSYM)
115 skip_comment(&cursor);
116 continue;
119 if(*cursor == TAGSYM)
120 cursor++;
122 if(*cursor == '\n')
124 skin_error(UNEXPECTED_NEWLINE);
125 return NULL;
128 length++;
129 cursor++;
132 /* Copying the string */
133 cursor = *document;
134 buffer = skin_alloc_string(length);
135 buffer[length] = '\0';
136 for(i = 0; i < length; i++)
138 if(*cursor == TAGSYM)
139 cursor++;
141 if(*cursor == COMMENTSYM)
143 skip_comment(&cursor);
144 i--;
145 continue;
148 buffer[i] = *cursor;
149 cursor++;
152 *document = cursor;
153 return buffer;
156 int scan_int(char** document)
159 char* cursor = *document, *end;
160 int length = 0;
161 char buffer[16];
162 int retval;
163 int i;
165 while(isdigit(*cursor) || *cursor == COMMENTSYM || *cursor == '-')
167 if(*cursor == COMMENTSYM)
169 skip_comment(&cursor);
170 continue;
173 length++;
174 cursor++;
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++)
184 if(*cursor == COMMENTSYM)
186 skip_comment(&cursor);
187 i--;
188 continue;
191 buffer[i] = *cursor;
192 cursor++;
195 retval = atoi(buffer);
197 *document = end;
198 return retval;
201 int check_viewport(char* document)
203 if(strlen(document) < 3)
204 return 0;
206 if(document[0] != TAGSYM)
207 return 0;
209 if(document[1] != 'V')
210 return 0;
212 if(document[2] != ARGLISTOPENSYM
213 && document[2] != 'l'
214 && document[2] != 'i')
215 return 0;
217 return 1;