Add "elfzip" target to make which creates a zip of all elf files, as mapzip does...
[maemo-rb.git] / lib / skin_parser / skin_scan.c
blob50d58bc250f3e65859b0e637d9dfe7c4924a4d16
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(const char** document)
37 while(**document != '\n' && **document != '\0')
38 (*document)++;
39 if(**document == '\n')
40 (*document)++;
43 void skip_arglist(const char** document)
45 if(**document == ARGLISTOPENSYM)
46 (*document)++;
47 while(**document && **document != ARGLISTCLOSESYM)
49 if(**document == TAGSYM)
51 (*document)++;
52 if(**document == '\0')
53 break;
54 (*document)++;
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);
62 else
63 (*document)++;
65 if(**document == ARGLISTCLOSESYM)
66 (*document)++;
69 void skip_enumlist(const char** document)
71 if(**document == ENUMLISTOPENSYM)
72 (*document)++;
73 while(**document && **document != ENUMLISTCLOSESYM)
75 if(**document == TAGSYM)
77 (*document)++;
78 if(**document == '\0')
79 break;
80 (*document)++;
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);
88 else
89 (*document)++;
92 if(**document == ENUMLISTCLOSESYM)
93 (*document)++;
96 char* scan_string(const char** document)
99 const char* cursor = *document;
100 int length = 0;
101 char* buffer = NULL;
102 int i;
104 while(*cursor != ARGLISTSEPARATESYM && *cursor != ARGLISTCLOSESYM &&
105 *cursor != '\0')
107 if(*cursor == COMMENTSYM)
109 skip_comment(&cursor);
110 continue;
113 if(*cursor == TAGSYM)
114 cursor++;
116 if(*cursor == '\n')
118 skin_error(UNEXPECTED_NEWLINE, cursor);
119 return NULL;
122 length++;
123 cursor++;
126 /* Copying the string */
127 cursor = *document;
128 buffer = skin_alloc_string(length);
129 if (!buffer)
130 return NULL;
131 buffer[length] = '\0';
132 for(i = 0; i < length; i++)
134 if(*cursor == TAGSYM)
135 cursor++;
137 if(*cursor == COMMENTSYM)
139 skip_comment(&cursor);
140 i--;
141 continue;
144 buffer[i] = *cursor;
145 cursor++;
148 *document = cursor;
149 return buffer;
152 int scan_int(const char** document)
155 const char *cursor = *document, *end;
156 int length = 0;
157 char buffer[16];
158 int retval;
159 int i;
161 while(isdigit(*cursor) || *cursor == COMMENTSYM || *cursor == '-')
163 if(*cursor == COMMENTSYM)
165 skip_comment(&cursor);
166 continue;
169 length++;
170 cursor++;
172 if (length > 15)
173 length = 15;
174 end = cursor;
175 /* Copying to the buffer while avoiding comments */
176 cursor = *document;
177 buffer[length] = '\0';
178 for(i = 0; i < length; i++)
180 if(*cursor == COMMENTSYM)
182 skip_comment(&cursor);
183 i--;
184 continue;
187 buffer[i] = *cursor;
188 cursor++;
191 retval = atoi(buffer);
193 *document = end;
194 return retval;
197 int check_viewport(const char* document)
199 if(strlen(document) < 3)
200 return 0;
202 if(document[0] != TAGSYM)
203 return 0;
205 if(document[1] != 'V')
206 return 0;
208 if(document[2] != ARGLISTOPENSYM
209 && document[2] != 'l'
210 && document[2] != 'i')
211 return 0;
213 return 1;