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;
|
2011-11-15 14:11:08 +00:00
|
|
|
extern char* skin_buffer;
|
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-07-31 16:33:34 +00:00
|
|
|
const char *error_line_start;
|
2010-06-07 20:29:46 +00:00
|
|
|
char* error_message;
|
|
|
|
|
2011-11-15 14:11:08 +00:00
|
|
|
|
|
|
|
static inline struct skin_element*
|
|
|
|
get_child(OFFSETTYPE(struct skin_element**) children, int child)
|
|
|
|
{
|
|
|
|
struct skin_element **kids = SKINOFFSETTOPTR(skin_buffer, children);
|
|
|
|
return kids[child];
|
|
|
|
}
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
/* Debugging functions */
|
2010-07-31 16:30:22 +00:00
|
|
|
void skin_error(enum skin_errorcode error, const 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-07-29 12:37:48 +00:00
|
|
|
error_line_start = cursor+1;
|
2010-07-18 00:59:02 +00:00
|
|
|
|
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:
|
2011-01-27 11:27:53 +00:00
|
|
|
error_line_start = NULL;
|
|
|
|
printf("Error: Memory limit exceeded at Line %d\n", skin_line);
|
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-11-05 09:51:19 +00:00
|
|
|
case SEPARATOR_EXPECTED:
|
|
|
|
error_message = "Expected argument separator";
|
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-11-05 09:51:19 +00:00
|
|
|
error_message = "Expected subline separator";
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
2013-02-26 10:12:00 +00:00
|
|
|
case GOT_CALLBACK_ERROR:
|
|
|
|
error_message = "Parser callback returned error";
|
|
|
|
break;
|
2010-05-25 15:19:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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-08-03 12:14:50 +00:00
|
|
|
#if !defined(ROCKBOX) || defined(__PCTOOL__)
|
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:
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("* Unknown element.. error *\n");
|
2010-06-13 03:13:01 +00:00
|
|
|
break;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
2010-06-01 07:11:23 +00:00
|
|
|
case VIEWPORT:
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("{ Viewport \n");
|
2010-06-01 07:11:23 +00:00
|
|
|
|
|
|
|
debug_indent_level++;
|
2011-11-15 14:11:08 +00:00
|
|
|
skin_debug_tree(get_child(current->children, 0));
|
2010-06-01 07:11:23 +00:00
|
|
|
debug_indent_level--;
|
|
|
|
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("}");
|
2010-06-01 07:11:23 +00:00
|
|
|
break;
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
case TEXT:
|
2011-11-15 14:11:08 +00:00
|
|
|
text = SKINOFFSETTOPTR(skin_buffer, current->data);
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("* Plain text on line %d: \"%s\"\n", current->line, text);
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMENT:
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("# Comment on line %d\n ", current->line);
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG:
|
2010-11-11 12:05:34 +00:00
|
|
|
if (current->params_count)
|
|
|
|
{
|
|
|
|
printf("( %%%s tag on line %d with %d arguments\n",
|
|
|
|
current->tag->name,
|
|
|
|
current->line, current->params_count);
|
|
|
|
debug_indent_level++;
|
2011-11-15 14:11:08 +00:00
|
|
|
skin_debug_params(current->params_count, SKINOFFSETTOPTR(skin_buffer, current->params));
|
2010-11-11 12:05:34 +00:00
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
|
|
|
printf(")\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("[ %%%s tag on line %d ]\n",
|
|
|
|
current->tag->name, current->line);
|
|
|
|
}
|
2010-05-25 15:19:52 +00:00
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
2011-11-15 14:11:08 +00:00
|
|
|
skin_debug_tree(get_child(current->children, i));
|
2010-05-25 15:19:52 +00:00
|
|
|
}
|
|
|
|
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:
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("< Conditional tag %%?%s on line %d with %d enumerations \n",
|
|
|
|
current->tag->name, current->line, current->children_count);
|
2010-05-25 15:19:52 +00:00
|
|
|
debug_indent_level++;
|
|
|
|
|
2010-11-11 12:05:34 +00:00
|
|
|
for(i = 0; i < current->children_count; i++)
|
2010-05-25 15:19:52 +00:00
|
|
|
{
|
|
|
|
skin_debug_indent();
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("[ Enumeration %d\n", i);
|
2010-05-25 15:19:52 +00:00
|
|
|
debug_indent_level++;
|
2011-11-15 14:11:08 +00:00
|
|
|
skin_debug_tree(get_child(current->children, i));
|
2010-05-25 15:19:52 +00:00
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
2010-11-11 12:05:34 +00:00
|
|
|
printf(">\n");
|
2010-05-25 15:19:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-05-27 19:57:15 +00:00
|
|
|
case LINE:
|
|
|
|
printf("[ Logical line on line %d\n", current->line);
|
|
|
|
|
|
|
|
debug_indent_level++;
|
2010-08-03 12:14:50 +00:00
|
|
|
if (current->children)
|
2011-11-15 14:11:08 +00:00
|
|
|
skin_debug_tree(get_child(current->children, 0));
|
2010-05-27 19:57:15 +00:00
|
|
|
debug_indent_level--;
|
|
|
|
|
|
|
|
skin_debug_indent();
|
|
|
|
printf("]\n");
|
|
|
|
break;
|
2010-05-25 15:19:52 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 14:11:08 +00:00
|
|
|
current = SKINOFFSETTOPTR(skin_buffer, current->next);
|
2010-05-25 15:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("-");
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STRING:
|
2011-11-15 14:11:08 +00:00
|
|
|
printf("string: \"%s\"", SKINOFFSETTOPTR(skin_buffer, params[i].data.text));
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
|
2010-07-15 06:24:11 +00:00
|
|
|
case INTEGER:
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("integer: %d", params[i].data.number);
|
2010-07-15 06:24:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DECIMAL:
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("decimal: %d.%d", params[i].data.number/10,
|
2010-07-15 06:24:11 +00:00
|
|
|
params[i].data.number%10);
|
2010-05-25 15:19:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CODE:
|
2010-11-11 12:05:34 +00:00
|
|
|
printf("Skin Code: \n");
|
2010-05-25 15:19:52 +00:00
|
|
|
debug_indent_level++;
|
2011-11-15 14:11:08 +00:00
|
|
|
skin_debug_tree(SKINOFFSETTOPTR(skin_buffer, params[i].data.code));
|
2010-05-25 15:19:52 +00:00
|
|
|
debug_indent_level--;
|
|
|
|
skin_debug_indent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-15 12:26:07 +00:00
|
|
|
void skin_debug_indent(void)
|
2010-05-25 15:19:52 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < debug_indent_level; i++)
|
|
|
|
printf(" ");
|
|
|
|
}
|
2010-07-29 12:37:48 +00:00
|
|
|
|
2010-06-17 11:04:32 +00:00
|
|
|
#endif
|
2010-07-29 12:37:48 +00:00
|
|
|
|
|
|
|
#define MIN(a,b) ((a<b)?(a):(b))
|
2012-03-15 12:26:07 +00:00
|
|
|
void skin_error_format_message(void)
|
2010-07-29 12:37:48 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char text[128];
|
2010-11-11 09:57:37 +00:00
|
|
|
if (!error_line_start)
|
|
|
|
return;
|
2010-07-29 12:37:48 +00:00
|
|
|
char* line_end = strchr(error_line_start, '\n');
|
|
|
|
int len = MIN(line_end - error_line_start, 80);
|
|
|
|
if (!line_end)
|
|
|
|
len = strlen(error_line_start);
|
|
|
|
printf("Error on line %d.\n", error_line);
|
|
|
|
error_col--;
|
|
|
|
if (error_col <= 10)
|
|
|
|
{
|
|
|
|
strncpy(text, error_line_start, len);
|
|
|
|
text[len] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
/* make it fit nicely.. "<start few chars>...<10 chars><error>" */
|
|
|
|
strncpy(text, error_line_start, 6);
|
|
|
|
i = 5;
|
|
|
|
text[i++] = '.';
|
|
|
|
text[i++] = '.';
|
|
|
|
text[i++] = '.';
|
|
|
|
for (j=error_col-10; error_line_start[j] && error_line_start[j] != '\n'; j++)
|
|
|
|
text[i++] = error_line_start[j];
|
|
|
|
text[i] = '\0';
|
|
|
|
error_col = 18;
|
|
|
|
}
|
|
|
|
printf("%s\n", text);
|
|
|
|
for (i=0; i<error_col; i++)
|
|
|
|
text[i] = ' ';
|
|
|
|
snprintf(&text[i],64, "^ \'%s\' Here", error_message);
|
|
|
|
printf("%s\n", text);
|
|
|
|
}
|