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_message
= "Memory limit exceeded";
61 case NEWLINE_EXPECTED
:
62 error_message
= "Newline expected";
65 error_message
= "Illegal tag";
67 case ARGLIST_EXPECTED
:
68 error_message
= "Argument list expected";
71 error_message
= "Too many arguments given";
73 case DEFAULT_NOT_ALLOWED
:
74 error_message
= "Argument can not be set to default";
76 case UNEXPECTED_NEWLINE
:
77 error_message
= "Unexpected newline";
79 case INSUFFICIENT_ARGS
:
80 error_message
= "Not enough arguments";
83 error_message
= "Expected integer";
85 case DECIMAL_EXPECTED
:
86 error_message
= "Expected decimal";
88 case SEPARATOR_EXPECTED
:
89 error_message
= "Expected argument separator";
92 error_message
= "Expected list close";
94 case MULTILINE_EXPECTED
:
95 error_message
= "Expected subline separator";
101 int skin_error_line()
111 char* skin_error_message()
113 return error_message
;
116 void skin_clear_errors()
120 error_message
= NULL
;
123 #if !defined(ROCKBOX) || defined(__PCTOOL__)
124 void skin_debug_tree(struct skin_element
* root
)
129 struct skin_element
* current
= root
;
135 switch(current
->type
)
138 printf("[ Unknown element.. error\n]");
142 printf("[ Viewport \n");
144 debug_indent_level
++;
145 skin_debug_tree(current
->children
[0]);
146 debug_indent_level
--;
152 text
= current
->data
;
153 printf("[ Plain text on line %d : %s ]\n", current
->line
, text
);
157 text
= current
->data
;
158 printf("[ Comment on line %d: ", current
->line
);
159 for(i
= 0; i
< (int)strlen(text
); i
++)
164 printf("%c", text
[i
]);
170 printf("[ %s tag on line %d with %d arguments\n",
172 current
->line
, current
->params_count
);
173 debug_indent_level
++;
174 skin_debug_params(current
->params_count
, current
->params
);
175 debug_indent_level
--;
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
--;
196 printf("[ Conditional tag on line %d with %d enumerations \n",
197 current
->line
, current
->children_count
- 1);
198 debug_indent_level
++;
201 printf("[ Condition tag \n");
202 debug_indent_level
++;
203 skin_debug_tree(current
->children
[0]);
204 debug_indent_level
--;
208 for(i
= 1; i
< current
->children_count
; i
++)
211 printf("[ Enumeration %d\n", i
- 1);
212 debug_indent_level
++;
213 skin_debug_tree(current
->children
[i
]);
214 debug_indent_level
--;
219 debug_indent_level
--;
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
--;
239 current
= current
->next
;
244 void skin_debug_params(int count
, struct skin_tag_parameter params
[])
247 for(i
= 0; i
< count
; i
++)
251 switch(params
[i
].type
)
258 printf("[%s]", params
[i
].data
.text
);
262 printf("[%d]", params
[i
].data
.number
);
266 printf("[%d.%d]", params
[i
].data
.number
/10,
267 params
[i
].data
.number
%10);
271 printf("[ WPS Code: \n");
272 debug_indent_level
++;
273 skin_debug_tree(params
[i
].data
.code
);
274 debug_indent_level
--;
285 void skin_debug_indent()
288 for(i
= 0; i
< debug_indent_level
; i
++)
294 #define MIN(a,b) ((a<b)?(a):(b))
295 void skin_error_format_message()
299 char* line_end
= strchr(error_line_start
, '\n');
300 int len
= MIN(line_end
- error_line_start
, 80);
302 len
= strlen(error_line_start
);
303 printf("Error on line %d.\n", error_line
);
307 strncpy(text
, error_line_start
, len
);
313 /* make it fit nicely.. "<start few chars>...<10 chars><error>" */
314 strncpy(text
, error_line_start
, 6);
319 for (j
=error_col
-10; error_line_start
[j
] && error_line_start
[j
] != '\n'; j
++)
320 text
[i
++] = error_line_start
[j
];
324 printf("%s\n", text
);
325 for (i
=0; i
<error_col
; i
++)
327 snprintf(&text
[i
],64, "^ \'%s\' Here", error_message
);
328 printf("%s\n", text
);