Theme Editor: Added extern C declarations to header files
[kugel-rb.git] / utils / themeeditor / skin_scan.c
blobdfe5d008e5eebe135179b944ebd0cb7368531099
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>
26 #include "skin_scan.h"
27 #include "skin_debug.h"
28 #include "symbols.h"
29 #include "skin_parser.h"
31 /* Scanning Functions */
33 /* Simple function to advance a char* past a comment */
34 void skip_comment(char** document)
36 for(/*NO INIT*/;**document != '\n' && **document != '\0'; (*document)++);
37 if(**document == '\n')
38 (*document)++;
41 void skip_whitespace(char** document)
43 for(/*NO INIT*/; **document == ' ' || **document == '\t'; (*document)++);
46 char* scan_string(char** document)
49 char* cursor = *document;
50 int length = 0;
51 char* buffer = NULL;
52 int i;
54 while(*cursor != ARGLISTSEPERATESYM && *cursor != ARGLISTCLOSESYM &&
55 *cursor != '\0')
57 if(*cursor == COMMENTSYM)
59 skip_comment(&cursor);
60 continue;
63 if(*cursor == '\n')
65 skin_error(UNEXPECTED_NEWLINE);
66 return NULL;
69 length++;
70 cursor++;
73 /* Copying the string */
74 cursor = *document;
75 buffer = skin_alloc_string(length);
76 buffer[length] = '\0';
77 for(i = 0; i < length; i++)
79 if(*cursor == COMMENTSYM)
81 skip_comment(&cursor);
82 i--;
83 continue;
86 buffer[i] = *cursor;
87 cursor++;
90 *document = cursor;
91 return buffer;
94 int scan_int(char** document)
97 char* cursor = *document;
98 int length = 0;
99 char* buffer = NULL;
100 int retval;
101 int i;
103 while(isdigit(*cursor) || *cursor == COMMENTSYM)
105 if(*cursor == COMMENTSYM)
107 skip_comment(&cursor);
108 continue;
111 length++;
112 cursor++;
115 buffer = skin_alloc_string(length);
117 /* Copying to the buffer while avoiding comments */
118 cursor = *document;
119 buffer[length] = '\0';
120 for(i = 0; i < length; i++)
122 if(*cursor == COMMENTSYM)
124 skip_comment(&cursor);
125 i--;
126 continue;
129 buffer[i] = *cursor;
130 cursor++;
133 retval = atoi(buffer);
134 free(buffer);
136 *document = cursor;
137 return retval;