Theme Editor: Fixed bugs in code generation and viewport parsing
[kugel-rb.git] / utils / themeeditor / skin_scan.c
blob28d097125aca76a5afed282b3e2441d1e5345d69
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 for(/*NO INIT*/;**document != '\n' && **document != '\0'; (*document)++);
38 if(**document == '\n')
39 (*document)++;
42 void skip_whitespace(char** document)
44 for(/*NO INIT*/; **document == ' ' || **document == '\t'; (*document)++);
47 char* scan_string(char** document)
50 char* cursor = *document;
51 int length = 0;
52 char* buffer = NULL;
53 int i;
55 while(*cursor != ARGLISTSEPERATESYM && *cursor != ARGLISTCLOSESYM &&
56 *cursor != '\0')
58 if(*cursor == COMMENTSYM)
60 skip_comment(&cursor);
61 continue;
64 if(*cursor == TAGSYM)
65 cursor++;
67 if(*cursor == '\n')
69 skin_error(UNEXPECTED_NEWLINE);
70 return NULL;
73 length++;
74 cursor++;
77 /* Copying the string */
78 cursor = *document;
79 buffer = skin_alloc_string(length);
80 buffer[length] = '\0';
81 for(i = 0; i < length; i++)
83 if(*cursor == TAGSYM)
84 cursor++;
86 if(*cursor == COMMENTSYM)
88 skip_comment(&cursor);
89 i--;
90 continue;
93 buffer[i] = *cursor;
94 cursor++;
97 *document = cursor;
98 return buffer;
101 int scan_int(char** document)
104 char* cursor = *document;
105 int length = 0;
106 char* buffer = NULL;
107 int retval;
108 int i;
110 while(isdigit(*cursor) || *cursor == COMMENTSYM)
112 if(*cursor == COMMENTSYM)
114 skip_comment(&cursor);
115 continue;
118 length++;
119 cursor++;
122 buffer = skin_alloc_string(length);
124 /* Copying to the buffer while avoiding comments */
125 cursor = *document;
126 buffer[length] = '\0';
127 for(i = 0; i < length; i++)
129 if(*cursor == COMMENTSYM)
131 skip_comment(&cursor);
132 i--;
133 continue;
136 buffer[i] = *cursor;
137 cursor++;
140 retval = atoi(buffer);
141 free(buffer);
143 *document = cursor;
144 return retval;
147 int check_viewport(char* document)
149 if(strlen(document) < 3)
150 return 0;
152 if(document[0] != TAGSYM)
153 return 0;
155 if(document[1] != 'V')
156 return 0;
158 if(document[2] != ARGLISTOPENSYM
159 && document[2] != 'l'
160 && document[2] != 'i')
161 return 0;
163 return 1;