1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
27 #include "skin_scan.h"
28 #include "skin_debug.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')
39 if(**document
== '\n')
43 void skip_whitespace(char** document
)
45 while(**document
== ' ' || **document
== '\t')
49 void skip_arglist(char** document
)
51 if(**document
== ARGLISTOPENSYM
)
53 while(**document
&& **document
!= ARGLISTCLOSESYM
)
55 if(**document
== TAGSYM
)
58 if(**document
== '\0')
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
);
71 if(**document
== ARGLISTCLOSESYM
)
75 void skip_enumlist(char** document
)
77 if(**document
== ENUMLISTOPENSYM
)
79 while(**document
&& **document
!= ENUMLISTCLOSESYM
)
81 if(**document
== TAGSYM
)
84 if(**document
== '\0')
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
);
98 if(**document
== ENUMLISTCLOSESYM
)
102 char* scan_string(char** document
)
105 char* cursor
= *document
;
110 while(*cursor
!= ARGLISTSEPERATESYM
&& *cursor
!= ARGLISTCLOSESYM
&&
113 if(*cursor
== COMMENTSYM
)
115 skip_comment(&cursor
);
119 if(*cursor
== TAGSYM
)
124 skin_error(UNEXPECTED_NEWLINE
);
132 /* Copying the string */
134 buffer
= skin_alloc_string(length
);
135 buffer
[length
] = '\0';
136 for(i
= 0; i
< length
; i
++)
138 if(*cursor
== TAGSYM
)
141 if(*cursor
== COMMENTSYM
)
143 skip_comment(&cursor
);
156 int scan_int(char** document
)
159 char* cursor
= *document
, *end
;
165 while(isdigit(*cursor
) || *cursor
== COMMENTSYM
|| *cursor
== '-')
167 if(*cursor
== COMMENTSYM
)
169 skip_comment(&cursor
);
179 /* Copying to the buffer while avoiding comments */
181 buffer
[length
] = '\0';
182 for(i
= 0; i
< length
; i
++)
184 if(*cursor
== COMMENTSYM
)
186 skip_comment(&cursor
);
195 retval
= atoi(buffer
);
201 int check_viewport(char* document
)
203 if(strlen(document
) < 3)
206 if(document
[0] != TAGSYM
)
209 if(document
[1] != 'V')
212 if(document
[2] != ARGLISTOPENSYM
213 && document
[2] != 'l'
214 && document
[2] != 'i')