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_parser.h"
27 #include "skin_debug.h"
28 #include "tag_table.h"
30 /* Global variables for debug output */
31 int debug_indent_level
= 0;
33 extern char* skin_start
;
35 /* Global error variables */
38 const char *error_line_start
;
41 /* Debugging functions */
42 void skin_error(enum skin_errorcode error
, const char* cursor
)
47 while(cursor
> skin_start
&& *cursor
!= '\n')
52 error_line_start
= cursor
+1;
54 error_line
= skin_line
;
58 case MEMORY_LIMIT_EXCEEDED
:
59 error_line_start
= NULL
;
60 printf("Error: Memory limit exceeded at Line %d\n", skin_line
);
61 error_message
= "Memory limit exceeded";
63 case NEWLINE_EXPECTED
:
64 error_message
= "Newline expected";
67 error_message
= "Illegal tag";
69 case ARGLIST_EXPECTED
:
70 error_message
= "Argument list expected";
73 error_message
= "Too many arguments given";
75 case DEFAULT_NOT_ALLOWED
:
76 error_message
= "Argument can not be set to default";
78 case UNEXPECTED_NEWLINE
:
79 error_message
= "Unexpected newline";
81 case INSUFFICIENT_ARGS
:
82 error_message
= "Not enough arguments";
85 error_message
= "Expected integer";
87 case DECIMAL_EXPECTED
:
88 error_message
= "Expected decimal";
90 case SEPARATOR_EXPECTED
:
91 error_message
= "Expected argument separator";
94 error_message
= "Expected list close";
96 case MULTILINE_EXPECTED
:
97 error_message
= "Expected subline separator";
103 int skin_error_line()
113 char* skin_error_message()
115 return error_message
;
118 void skin_clear_errors()
122 error_message
= NULL
;
125 #if !defined(ROCKBOX) || defined(__PCTOOL__)
126 void skin_debug_tree(struct skin_element
* root
)
131 struct skin_element
* current
= root
;
137 switch(current
->type
)
140 printf("* Unknown element.. error *\n");
144 printf("{ Viewport \n");
146 debug_indent_level
++;
147 skin_debug_tree(current
->children
[0]);
148 debug_indent_level
--;
154 text
= current
->data
;
155 printf("* Plain text on line %d: \"%s\"\n", current
->line
, text
);
159 printf("# Comment on line %d\n ", current
->line
);
163 if (current
->params_count
)
165 printf("( %%%s tag on line %d with %d arguments\n",
167 current
->line
, current
->params_count
);
168 debug_indent_level
++;
169 skin_debug_params(current
->params_count
, current
->params
);
170 debug_indent_level
--;
176 printf("[ %%%s tag on line %d ]\n",
177 current
->tag
->name
, current
->line
);
182 case LINE_ALTERNATOR
:
183 printf("[ Alternator on line %d with %d sublines \n", current
->line
,
184 current
->children_count
);
185 debug_indent_level
++;
186 for(i
= 0; i
< current
->children_count
; i
++)
188 skin_debug_tree(current
->children
[i
]);
190 debug_indent_level
--;
197 printf("< Conditional tag %%?%s on line %d with %d enumerations \n",
198 current
->tag
->name
, current
->line
, current
->children_count
);
199 debug_indent_level
++;
201 for(i
= 0; i
< current
->children_count
; i
++)
204 printf("[ Enumeration %d\n", i
);
205 debug_indent_level
++;
206 skin_debug_tree(current
->children
[i
]);
207 debug_indent_level
--;
212 debug_indent_level
--;
220 printf("[ Logical line on line %d\n", current
->line
);
222 debug_indent_level
++;
223 if (current
->children
)
224 skin_debug_tree(current
->children
[0]);
225 debug_indent_level
--;
232 current
= current
->next
;
237 void skin_debug_params(int count
, struct skin_tag_parameter params
[])
240 for(i
= 0; i
< count
; i
++)
244 switch(params
[i
].type
)
251 printf("string: \"%s\"", params
[i
].data
.text
);
255 printf("integer: %d", params
[i
].data
.number
);
259 printf("decimal: %d.%d", params
[i
].data
.number
/10,
260 params
[i
].data
.number
%10);
264 printf("Skin Code: \n");
265 debug_indent_level
++;
266 skin_debug_tree(params
[i
].data
.code
);
267 debug_indent_level
--;
277 void skin_debug_indent()
280 for(i
= 0; i
< debug_indent_level
; i
++)
286 #define MIN(a,b) ((a<b)?(a):(b))
287 void skin_error_format_message()
291 if (!error_line_start
)
293 char* line_end
= strchr(error_line_start
, '\n');
294 int len
= MIN(line_end
- error_line_start
, 80);
296 len
= strlen(error_line_start
);
297 printf("Error on line %d.\n", error_line
);
301 strncpy(text
, error_line_start
, len
);
307 /* make it fit nicely.. "<start few chars>...<10 chars><error>" */
308 strncpy(text
, error_line_start
, 6);
313 for (j
=error_col
-10; error_line_start
[j
] && error_line_start
[j
] != '\n'; j
++)
314 text
[i
++] = error_line_start
[j
];
318 printf("%s\n", text
);
319 for (i
=0; i
<error_col
; i
++)
321 snprintf(&text
[i
],64, "^ \'%s\' Here", error_message
);
322 printf("%s\n", text
);