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 <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "skin_parser.h"
|
|
|
|
#include "skin_debug.h"
|
2010-06-01 16:44:52 +00:00
|
|
|
#include "tag_table.h"
|
2010-05-25 15:19:52 +00:00
|
|
|
|
|
|
|
/* Global variables for debug output */
|
|
|
|
int debug_indent_level = 0;
|
|
|
|
extern int skin_line;
|
2010-07-18 00:59:02 +00:00
|
|
|
extern char* skin_start;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
2010-06-07 20:29:46 +00:00
|
|
|
/* Global error variables */
|
|
|
|
int error_line;
|
2010-07-18 00:59:02 +00:00
|
|
|
int error_col;
|
2010-06-07 20:29:46 +00:00
|
|
|
char* error_message;
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
/* Debugging functions */
|
2010-07-18 00:59:02 +00:00
|
|
|
void skin_error(enum skin_errorcode error, char* cursor)
|
2010-05-25 15:19:52 +00:00
|
|
|
{
|
|
|
|
|
2010-07-18 00:59:02 +00:00
|
|
|
error_col = 0;
|
|
|
|
|
|
|
|
while(cursor > skin_start && *cursor != '\n')
|
|
|
|
{
|
|
|
|
cursor--;
|
|
|
|
error_col++;
|
|
|
|
}
|
|
|
|
|
2010-06-07 20:29:46 +00:00
|
|
|
error_line = skin_line;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
|
|
|
switch(error)
|
|
|
|
{
|
|
|
|
case MEMORY_LIMIT_EXCEEDED:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Memory limit exceeded";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case NEWLINE_EXPECTED:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Newline expected";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case ILLEGAL_TAG:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Illegal tag";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case ARGLIST_EXPECTED:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Argument list expected";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case TOO_MANY_ARGS:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Too many arguments given";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case DEFAULT_NOT_ALLOWED:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Argument can not be set to default";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case UNEXPECTED_NEWLINE:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Unexpected newline";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case INSUFFICIENT_ARGS:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Not enough arguments";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case INT_EXPECTED:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Expected integer";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
2010-07-15 06:24:11 +00:00
|
|
|
case DECIMAL_EXPECTED:
|
|
|
|
error_message = "Expected decimal";
|
|
|
|
break;
|
2010-05-25 15:19:52 +00:00
|
|
|
case SEPERATOR_EXPECTED:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Expected argument seperator";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case CLOSE_EXPECTED:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Expected list close";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
case MULTILINE_EXPECTED:
|
2010-06-07 20:29:46 +00:00
|
|
|
error_message = "Expected subline seperator";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-07 20:29:46 +00:00
|
|
|
int skin_error_line()
|
|
|
|
{
|
|
|
|
return error_line;
|
|
|
|
}
|
|
|
|
|
2010-07-18 00:59:02 +00:00
|
|
|
int skin_error_col()
|
|
|
|
{
|
|
|
|
return error_col;
|
|
|
|
}
|
|
|
|
|
2010-06-07 20:29:46 +00:00
|
|
|
char* skin_error_message()
|
|
|
|
{
|
|
|
|
return error_message;
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:09:13 +00:00
|
|
|
void skin_clear_errors()
|
|
|
|
{
|
|
|
|
error_line = 0;
|
2010-07-18 00:59:02 +00:00
|
|
|
error_col = 0;
|
2010-06-07 21:09:13 +00:00
|
|
|
error_message = NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-17 11:04:32 +00:00
|
|
|
#ifndef ROCKBOX
|
2010-05-25 15:19:52 +00:00
|
|
|
void skin_debug_tree(struct skin_element* root)
|
|
|
|
{
|
|
|
|
int i;
|
2010-06-10 21:02:44 +00:00
|
|
|
char *text;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
|
|
|
struct skin_element* current = root;
|
|
|
|
|
|
|
|
while(current)
|
|
|
|
{
|
|
|
|
skin_debug_indent();
|
|
|
|
|
|
|
|
switch(current->type)
|
|
|
|
{
|
2010-06-13 03:13:01 +00:00
|
|
|
case UNKNOWN:
|
|
|
|
printf("[ Unknown element.. error\n]");
|
|
|
|
break;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
2010-06-01 07:11:23 +00:00
|
|
|
case VIEWPORT:
|
|
|
|
printf("[ Viewport \n");
|
|
|
|
|
|
|
|
debug_indent_level++;
|
|
|
|
skin_debug_tree(current->children[0]);
|
|
|
|
debug_indent_level--;
|
|
|
|
|
|
|
|
printf("]");
|
|
|
|
break;
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
case TEXT:
|
2010-06-10 21:02:44 +00:00
|
|
|
text = current->data;
|
|
|
|
printf("[ Plain text on line %d : %s ]\n", current->line, text);
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMENT:
|
2010-06-10 21:02:44 +00:00
|
|
|
text = current->data;
|
2010-05-25 15:19:52 +00:00
|
|
|
printf("[ Comment on line %d: ", current->line);
|
2010-06-10 21:02:44 +00:00
|
|
|
for(i = 0; i < (int)strlen(text); i++)
|
2010-05-25 15:19:52 +00:00
|
|
|
{
|
2010-06-10 21:02:44 +00:00
|
|
|
if(text[i] == '\n')
|
2010-05-25 15:19:52 +00:00
|
|
|
printf("\\n");
|
|
|
|
else
|
2010-06-10 21:02:44 +00:00
|
|
|
printf("%c", text[i]);
|
2010-05-25 15:19:52 +00:00
|
|
|
}
|
|
|
|
printf(" ]\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG:
|
2010-06-01 16:44:52 +00:00
|
|
|
printf("[ %s tag on line %d with %d arguments\n",
|
|
|
|
current->tag->name,
|
2010-05-25 15:19:52 +00:00
|
|
|
current->line, current->params_count);
|
|
|
|
debug_indent_level++;
|
|
|
|
skin_debug_params(current->params_count, current->params);
|
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("]\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-07-04 02:04:14 +00:00
|
|
|
case LINE_ALTERNATOR:
|
2010-05-25 15:19:52 +00:00
|
|
|
printf("[ Alternator on line %d with %d sublines \n", current->line,
|
|
|
|
current->children_count);
|
|
|
|
debug_indent_level++;
|
|
|
|
for(i = 0; i < current->children_count; i++)
|
|
|
|
{
|
|
|
|
skin_debug_tree(current->children[i]);
|
|
|
|
}
|
|
|
|
debug_indent_level--;
|
2010-05-27 19:57:15 +00:00
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
skin_debug_indent();
|
|
|
|
printf("]\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONDITIONAL:
|
|
|
|
printf("[ Conditional tag on line %d with %d enumerations \n",
|
|
|
|
current->line, current->children_count - 1);
|
|
|
|
debug_indent_level++;
|
|
|
|
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("[ Condition tag \n");
|
|
|
|
debug_indent_level++;
|
|
|
|
skin_debug_tree(current->children[0]);
|
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("]\n");
|
|
|
|
|
|
|
|
for(i = 1; i < current->children_count; i++)
|
|
|
|
{
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("[ Enumeration %d\n", i - 1);
|
|
|
|
debug_indent_level++;
|
|
|
|
skin_debug_tree(current->children[i]);
|
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("]\n");
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-05-27 19:57:15 +00:00
|
|
|
case LINE:
|
|
|
|
printf("[ Logical line on line %d\n", current->line);
|
|
|
|
|
|
|
|
debug_indent_level++;
|
|
|
|
skin_debug_tree(current->children[0]);
|
|
|
|
debug_indent_level--;
|
|
|
|
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("]\n");
|
|
|
|
break;
|
2010-05-25 15:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void skin_debug_params(int count, struct skin_tag_parameter params[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
skin_debug_indent();
|
|
|
|
switch(params[i].type)
|
|
|
|
{
|
|
|
|
case DEFAULT:
|
|
|
|
printf("[-]");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STRING:
|
|
|
|
printf("[%s]", params[i].data.text);
|
|
|
|
break;
|
|
|
|
|
2010-07-15 06:24:11 +00:00
|
|
|
case INTEGER:
|
|
|
|
printf("[%d]", params[i].data.number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DECIMAL:
|
|
|
|
printf("[%d.%d]", params[i].data.number/10,
|
|
|
|
params[i].data.number%10);
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CODE:
|
|
|
|
printf("[ WPS Code: \n");
|
|
|
|
debug_indent_level++;
|
|
|
|
skin_debug_tree(params[i].data.code);
|
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void skin_debug_indent()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < debug_indent_level; i++)
|
|
|
|
printf(" ");
|
|
|
|
}
|
2010-06-17 11:04:32 +00:00
|
|
|
#endif
|