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 ****************************************************************************/
26 #include "skin_scan.h"
27 #include "skin_debug.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')
41 void skip_whitespace(char** document
)
43 for(/*NO INIT*/; **document
== ' ' || **document
== '\t'; (*document
)++);
46 char* scan_string(char** document
)
49 char* cursor
= *document
;
54 while(*cursor
!= ARGLISTSEPERATESYM
&& *cursor
!= ARGLISTCLOSESYM
&&
57 if(*cursor
== COMMENTSYM
)
59 skip_comment(&cursor
);
65 skin_error(UNEXPECTED_NEWLINE
);
73 /* Copying the string */
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
);
94 int scan_int(char** document
)
97 char* cursor
= *document
;
103 while(isdigit(*cursor
) || *cursor
== COMMENTSYM
)
105 if(*cursor
== COMMENTSYM
)
107 skip_comment(&cursor
);
115 buffer
= skin_alloc_string(length
);
117 /* Copying to the buffer while avoiding comments */
119 buffer
[length
] = '\0';
120 for(i
= 0; i
< length
; i
++)
122 if(*cursor
== COMMENTSYM
)
124 skip_comment(&cursor
);
133 retval
= atoi(buffer
);