2010-05-25 15:19:52 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Robert Bieber
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
2010-06-01 07:11:23 +00:00
|
|
|
#include <string.h>
|
2010-05-25 15:19:52 +00:00
|
|
|
|
|
|
|
#include "skin_scan.h"
|
|
|
|
#include "skin_debug.h"
|
|
|
|
#include "symbols.h"
|
|
|
|
#include "skin_parser.h"
|
|
|
|
|
|
|
|
/* Scanning Functions */
|
|
|
|
|
|
|
|
/* Simple function to advance a char* past a comment */
|
|
|
|
void skip_comment(char** document)
|
|
|
|
{
|
2010-06-07 23:49:06 +00:00
|
|
|
while(**document != '\n' && **document != '\0')
|
|
|
|
(*document)++;
|
2010-05-25 15:19:52 +00:00
|
|
|
if(**document == '\n')
|
|
|
|
(*document)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void skip_whitespace(char** document)
|
|
|
|
{
|
2010-06-07 23:49:06 +00:00
|
|
|
while(**document == ' ' || **document == '\t')
|
|
|
|
(*document)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void skip_arglist(char** document)
|
|
|
|
{
|
|
|
|
if(**document == ARGLISTOPENSYM)
|
|
|
|
(*document)++;
|
|
|
|
while(**document && **document != ARGLISTCLOSESYM)
|
|
|
|
{
|
|
|
|
if(**document == TAGSYM)
|
|
|
|
{
|
|
|
|
(*document)++;
|
|
|
|
if(**document == '\0')
|
|
|
|
break;
|
|
|
|
(*document)++;
|
|
|
|
}
|
|
|
|
else if(**document == ARGLISTOPENSYM)
|
|
|
|
skip_arglist(document);
|
|
|
|
else if(**document == ENUMLISTOPENSYM)
|
|
|
|
skip_enumlist(document);
|
|
|
|
else if(**document == COMMENTSYM)
|
|
|
|
skip_comment(document);
|
|
|
|
else
|
|
|
|
(*document)++;
|
|
|
|
}
|
|
|
|
if(**document == ARGLISTCLOSESYM)
|
|
|
|
(*document)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void skip_enumlist(char** document)
|
|
|
|
{
|
|
|
|
if(**document == ENUMLISTOPENSYM)
|
|
|
|
(*document)++;
|
|
|
|
while(**document && **document != ENUMLISTCLOSESYM)
|
|
|
|
{
|
|
|
|
if(**document == TAGSYM)
|
|
|
|
{
|
|
|
|
(*document)++;
|
|
|
|
if(**document == '\0')
|
|
|
|
break;
|
|
|
|
(*document)++;
|
|
|
|
}
|
|
|
|
else if(**document == ARGLISTOPENSYM)
|
|
|
|
skip_arglist(document);
|
|
|
|
else if(**document == ENUMLISTOPENSYM)
|
|
|
|
skip_enumlist(document);
|
|
|
|
else if(**document == COMMENTSYM)
|
|
|
|
skip_comment(document);
|
|
|
|
else
|
|
|
|
(*document)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(**document == ENUMLISTCLOSESYM)
|
|
|
|
(*document)++;
|
2010-05-25 15:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char* scan_string(char** document)
|
|
|
|
{
|
|
|
|
|
|
|
|
char* cursor = *document;
|
|
|
|
int length = 0;
|
|
|
|
char* buffer = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while(*cursor != ARGLISTSEPERATESYM && *cursor != ARGLISTCLOSESYM &&
|
|
|
|
*cursor != '\0')
|
|
|
|
{
|
|
|
|
if(*cursor == COMMENTSYM)
|
|
|
|
{
|
|
|
|
skip_comment(&cursor);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-02 05:45:34 +00:00
|
|
|
if(*cursor == TAGSYM)
|
|
|
|
cursor++;
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
if(*cursor == '\n')
|
|
|
|
{
|
2010-07-18 08:58:04 +00:00
|
|
|
skin_error(UNEXPECTED_NEWLINE, cursor);
|
2010-05-25 15:19:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
length++;
|
|
|
|
cursor++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copying the string */
|
|
|
|
cursor = *document;
|
|
|
|
buffer = skin_alloc_string(length);
|
2010-05-25 17:22:39 +00:00
|
|
|
buffer[length] = '\0';
|
2010-05-25 15:19:52 +00:00
|
|
|
for(i = 0; i < length; i++)
|
|
|
|
{
|
2010-06-02 05:45:34 +00:00
|
|
|
if(*cursor == TAGSYM)
|
|
|
|
cursor++;
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
if(*cursor == COMMENTSYM)
|
|
|
|
{
|
|
|
|
skip_comment(&cursor);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[i] = *cursor;
|
|
|
|
cursor++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*document = cursor;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
int scan_int(char** document)
|
|
|
|
{
|
|
|
|
|
2010-06-02 10:35:19 +00:00
|
|
|
char* cursor = *document, *end;
|
2010-05-25 15:19:52 +00:00
|
|
|
int length = 0;
|
2010-06-02 10:35:19 +00:00
|
|
|
char buffer[16];
|
2010-05-25 15:19:52 +00:00
|
|
|
int retval;
|
|
|
|
int i;
|
|
|
|
|
2010-06-02 06:52:17 +00:00
|
|
|
while(isdigit(*cursor) || *cursor == COMMENTSYM || *cursor == '-')
|
2010-05-25 15:19:52 +00:00
|
|
|
{
|
|
|
|
if(*cursor == COMMENTSYM)
|
|
|
|
{
|
|
|
|
skip_comment(&cursor);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
length++;
|
|
|
|
cursor++;
|
|
|
|
}
|
2010-06-02 10:35:19 +00:00
|
|
|
if (length > 15)
|
|
|
|
length = 15;
|
|
|
|
end = cursor;
|
2010-05-25 15:19:52 +00:00
|
|
|
/* Copying to the buffer while avoiding comments */
|
|
|
|
cursor = *document;
|
|
|
|
buffer[length] = '\0';
|
|
|
|
for(i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
if(*cursor == COMMENTSYM)
|
|
|
|
{
|
|
|
|
skip_comment(&cursor);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[i] = *cursor;
|
|
|
|
cursor++;
|
|
|
|
|
|
|
|
}
|
|
|
|
retval = atoi(buffer);
|
|
|
|
|
2010-06-02 10:35:19 +00:00
|
|
|
*document = end;
|
2010-05-25 15:19:52 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2010-06-01 07:11:23 +00:00
|
|
|
|
|
|
|
int check_viewport(char* document)
|
|
|
|
{
|
|
|
|
if(strlen(document) < 3)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(document[0] != TAGSYM)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(document[1] != 'V')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(document[2] != ARGLISTOPENSYM
|
|
|
|
&& document[2] != 'l'
|
|
|
|
&& document[2] != 'i')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|