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"
31 #include "tag_table.h"
33 /* Scanning Functions */
35 /* Simple function to advance a char* past a comment */
36 void skip_comment(const char** document
)
38 while(**document
!= '\n' && **document
!= '\0')
40 if(**document
== '\n')
44 void skip_tag(const char** document
)
46 char tag_name
[MAX_TAG_LENGTH
];
49 const struct tag_info
*tag
;
52 if(**document
== TAGSYM
)
54 qmark
= (**document
== CONDITIONSYM
);
58 if (!qmark
&& find_escape_character(**document
))
66 /* Checking the tag name */
67 for (i
=0; cursor
[i
] && i
<MAX_TAG_LENGTH
; i
++)
68 tag_name
[i
] = cursor
[i
];
70 /* First we check the two characters after the '%', then a single char */
76 tag
= find_tag(tag_name
);
82 *document
+= strlen(tag
->name
);
85 if (**document
== ARGLISTOPENSYM
)
86 skip_arglist(document
);
88 if (**document
== ENUMLISTOPENSYM
)
89 skip_enumlist(document
);
92 void skip_arglist(const char** document
)
94 if(**document
== ARGLISTOPENSYM
)
96 while(**document
&& **document
!= ARGLISTCLOSESYM
)
98 if(**document
== TAGSYM
)
100 else if(**document
== COMMENTSYM
)
101 skip_comment(document
);
105 if(**document
== ARGLISTCLOSESYM
)
109 void skip_enumlist(const char** document
)
111 if(**document
== ENUMLISTOPENSYM
)
113 while(**document
&& **document
!= ENUMLISTCLOSESYM
)
115 if(**document
== TAGSYM
)
117 else if(**document
== COMMENTSYM
)
118 skip_comment(document
);
123 if(**document
== ENUMLISTCLOSESYM
)
127 char* scan_string(const char** document
)
130 const char* cursor
= *document
;
135 while(*cursor
!= ARGLISTSEPARATESYM
&& *cursor
!= ARGLISTCLOSESYM
&&
138 if(*cursor
== COMMENTSYM
)
140 skip_comment(&cursor
);
144 if(*cursor
== TAGSYM
)
149 skin_error(UNEXPECTED_NEWLINE
, cursor
);
157 /* Copying the string */
159 buffer
= skin_alloc_string(length
);
162 buffer
[length
] = '\0';
163 for(i
= 0; i
< length
; i
++)
165 if(*cursor
== TAGSYM
)
168 if(*cursor
== COMMENTSYM
)
170 skip_comment(&cursor
);
183 int scan_int(const char** document
)
186 const char *cursor
= *document
, *end
;
192 while(isdigit(*cursor
) || *cursor
== COMMENTSYM
|| *cursor
== '-')
194 if(*cursor
== COMMENTSYM
)
196 skip_comment(&cursor
);
206 /* Copying to the buffer while avoiding comments */
208 buffer
[length
] = '\0';
209 for(i
= 0; i
< length
; i
++)
211 if(*cursor
== COMMENTSYM
)
213 skip_comment(&cursor
);
222 retval
= atoi(buffer
);
228 int check_viewport(const char* document
)
230 if(strlen(document
) < 3)
233 if(document
[0] != TAGSYM
)
236 if(document
[1] != 'V')
239 if(document
[2] != ARGLISTOPENSYM
240 && document
[2] != 'l'
241 && document
[2] != 'i')