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_arglist(char** document
)
45 if(**document
== ARGLISTOPENSYM
)
47 while(**document
&& **document
!= ARGLISTCLOSESYM
)
49 if(**document
== TAGSYM
)
52 if(**document
== '\0')
56 else if(**document
== ARGLISTOPENSYM
)
57 skip_arglist(document
);
58 else if(**document
== ENUMLISTOPENSYM
)
59 skip_enumlist(document
);
60 else if(**document
== COMMENTSYM
)
61 skip_comment(document
);
65 if(**document
== ARGLISTCLOSESYM
)
69 void skip_enumlist(char** document
)
71 if(**document
== ENUMLISTOPENSYM
)
73 while(**document
&& **document
!= ENUMLISTCLOSESYM
)
75 if(**document
== TAGSYM
)
78 if(**document
== '\0')
82 else if(**document
== ARGLISTOPENSYM
)
83 skip_arglist(document
);
84 else if(**document
== ENUMLISTOPENSYM
)
85 skip_enumlist(document
);
86 else if(**document
== COMMENTSYM
)
87 skip_comment(document
);
92 if(**document
== ENUMLISTCLOSESYM
)
96 char* scan_string(char** document
)
99 char* cursor
= *document
;
104 while(*cursor
!= ARGLISTSEPERATESYM
&& *cursor
!= ARGLISTCLOSESYM
&&
107 if(*cursor
== COMMENTSYM
)
109 skip_comment(&cursor
);
113 if(*cursor
== TAGSYM
)
118 skin_error(UNEXPECTED_NEWLINE
, cursor
);
126 /* Copying the string */
128 buffer
= skin_alloc_string(length
);
131 buffer
[length
] = '\0';
132 for(i
= 0; i
< length
; i
++)
134 if(*cursor
== TAGSYM
)
137 if(*cursor
== COMMENTSYM
)
139 skip_comment(&cursor
);
152 int scan_int(char** document
)
155 char* cursor
= *document
, *end
;
161 while(isdigit(*cursor
) || *cursor
== COMMENTSYM
|| *cursor
== '-')
163 if(*cursor
== COMMENTSYM
)
165 skip_comment(&cursor
);
175 /* Copying to the buffer while avoiding comments */
177 buffer
[length
] = '\0';
178 for(i
= 0; i
< length
; i
++)
180 if(*cursor
== COMMENTSYM
)
182 skip_comment(&cursor
);
191 retval
= atoi(buffer
);
197 int check_viewport(char* document
)
199 if(strlen(document
) < 3)
202 if(document
[0] != TAGSYM
)
205 if(document
[1] != 'V')
208 if(document
[2] != ARGLISTOPENSYM
209 && document
[2] != 'l'
210 && document
[2] != 'i')