Commit FS#11709 by me. Introduces ARMv5E optimized iQMF for atrac3 based on packed...
[kugel-rb.git] / lib / skin_parser / skin_debug.c
bloba09cd673c7a4d484599e6f1992e58863ecd53a29
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
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;
32 extern int skin_line;
33 extern char* skin_start;
35 /* Global error variables */
36 int error_line;
37 int error_col;
38 const char *error_line_start;
39 char* error_message;
41 /* Debugging functions */
42 void skin_error(enum skin_errorcode error, const char* cursor)
45 error_col = 0;
47 while(cursor > skin_start && *cursor != '\n')
49 cursor--;
50 error_col++;
52 error_line_start = cursor+1;
54 error_line = skin_line;
56 switch(error)
58 case MEMORY_LIMIT_EXCEEDED:
59 error_message = "Memory limit exceeded";
60 break;
61 case NEWLINE_EXPECTED:
62 error_message = "Newline expected";
63 break;
64 case ILLEGAL_TAG:
65 error_message = "Illegal tag";
66 break;
67 case ARGLIST_EXPECTED:
68 error_message = "Argument list expected";
69 break;
70 case TOO_MANY_ARGS:
71 error_message = "Too many arguments given";
72 break;
73 case DEFAULT_NOT_ALLOWED:
74 error_message = "Argument can not be set to default";
75 break;
76 case UNEXPECTED_NEWLINE:
77 error_message = "Unexpected newline";
78 break;
79 case INSUFFICIENT_ARGS:
80 error_message = "Not enough arguments";
81 break;
82 case INT_EXPECTED:
83 error_message = "Expected integer";
84 break;
85 case DECIMAL_EXPECTED:
86 error_message = "Expected decimal";
87 break;
88 case SEPARATOR_EXPECTED:
89 error_message = "Expected argument separator";
90 break;
91 case CLOSE_EXPECTED:
92 error_message = "Expected list close";
93 break;
94 case MULTILINE_EXPECTED:
95 error_message = "Expected subline separator";
96 break;
101 int skin_error_line()
103 return error_line;
106 int skin_error_col()
108 return error_col;
111 char* skin_error_message()
113 return error_message;
116 void skin_clear_errors()
118 error_line = 0;
119 error_col = 0;
120 error_message = NULL;
123 #if !defined(ROCKBOX) || defined(__PCTOOL__)
124 void skin_debug_tree(struct skin_element* root)
126 int i;
127 char *text;
129 struct skin_element* current = root;
131 while(current)
133 skin_debug_indent();
135 switch(current->type)
137 case UNKNOWN:
138 printf("[ Unknown element.. error\n]");
139 break;
141 case VIEWPORT:
142 printf("[ Viewport \n");
144 debug_indent_level++;
145 skin_debug_tree(current->children[0]);
146 debug_indent_level--;
148 printf("]");
149 break;
151 case TEXT:
152 text = current->data;
153 printf("[ Plain text on line %d : %s ]\n", current->line, text);
154 break;
156 case COMMENT:
157 text = current->data;
158 printf("[ Comment on line %d: ", current->line);
159 for(i = 0; i < (int)strlen(text); i++)
161 if(text[i] == '\n')
162 printf("\\n");
163 else
164 printf("%c", text[i]);
166 printf(" ]\n");
167 break;
169 case TAG:
170 printf("[ %s tag on line %d with %d arguments\n",
171 current->tag->name,
172 current->line, current->params_count);
173 debug_indent_level++;
174 skin_debug_params(current->params_count, current->params);
175 debug_indent_level--;
176 skin_debug_indent();
177 printf("]\n");
179 break;
181 case LINE_ALTERNATOR:
182 printf("[ Alternator on line %d with %d sublines \n", current->line,
183 current->children_count);
184 debug_indent_level++;
185 for(i = 0; i < current->children_count; i++)
187 skin_debug_tree(current->children[i]);
189 debug_indent_level--;
191 skin_debug_indent();
192 printf("]\n");
193 break;
195 case CONDITIONAL:
196 printf("[ Conditional tag on line %d with %d enumerations \n",
197 current->line, current->children_count - 1);
198 debug_indent_level++;
200 skin_debug_indent();
201 printf("[ Condition tag \n");
202 debug_indent_level++;
203 skin_debug_tree(current->children[0]);
204 debug_indent_level--;
205 skin_debug_indent();
206 printf("]\n");
208 for(i = 1; i < current->children_count; i++)
210 skin_debug_indent();
211 printf("[ Enumeration %d\n", i - 1);
212 debug_indent_level++;
213 skin_debug_tree(current->children[i]);
214 debug_indent_level--;
215 skin_debug_indent();
216 printf("]\n");
219 debug_indent_level--;
220 skin_debug_indent();
221 printf("]\n");
224 break;
226 case LINE:
227 printf("[ Logical line on line %d\n", current->line);
229 debug_indent_level++;
230 if (current->children)
231 skin_debug_tree(current->children[0]);
232 debug_indent_level--;
234 skin_debug_indent();
235 printf("]\n");
236 break;
239 current = current->next;
244 void skin_debug_params(int count, struct skin_tag_parameter params[])
246 int i;
247 for(i = 0; i < count; i++)
250 skin_debug_indent();
251 switch(params[i].type)
253 case DEFAULT:
254 printf("[-]");
255 break;
257 case STRING:
258 printf("[%s]", params[i].data.text);
259 break;
261 case INTEGER:
262 printf("[%d]", params[i].data.number);
263 break;
265 case DECIMAL:
266 printf("[%d.%d]", params[i].data.number/10,
267 params[i].data.number%10);
268 break;
270 case CODE:
271 printf("[ WPS Code: \n");
272 debug_indent_level++;
273 skin_debug_tree(params[i].data.code);
274 debug_indent_level--;
275 skin_debug_indent();
276 printf("]");
277 break;
280 printf("\n");
285 void skin_debug_indent()
287 int i;
288 for(i = 0; i < debug_indent_level; i++)
289 printf(" ");
292 #endif
294 #define MIN(a,b) ((a<b)?(a):(b))
295 void skin_error_format_message()
297 int i;
298 char text[128];
299 char* line_end = strchr(error_line_start, '\n');
300 int len = MIN(line_end - error_line_start, 80);
301 if (!line_end)
302 len = strlen(error_line_start);
303 printf("Error on line %d.\n", error_line);
304 error_col--;
305 if (error_col <= 10)
307 strncpy(text, error_line_start, len);
308 text[len] = '\0';
310 else
312 int j;
313 /* make it fit nicely.. "<start few chars>...<10 chars><error>" */
314 strncpy(text, error_line_start, 6);
315 i = 5;
316 text[i++] = '.';
317 text[i++] = '.';
318 text[i++] = '.';
319 for (j=error_col-10; error_line_start[j] && error_line_start[j] != '\n'; j++)
320 text[i++] = error_line_start[j];
321 text[i] = '\0';
322 error_col = 18;
324 printf("%s\n", text);
325 for (i=0; i<error_col; i++)
326 text[i] = ' ';
327 snprintf(&text[i],64, "^ \'%s\' Here", error_message);
328 printf("%s\n", text);