diff options
Diffstat (limited to 'lib/skin_parser/skin_debug.c')
-rw-r--r-- | lib/skin_parser/skin_debug.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/skin_parser/skin_debug.c b/lib/skin_parser/skin_debug.c index c03b32e910..88ad209cce 100644 --- a/lib/skin_parser/skin_debug.c +++ b/lib/skin_parser/skin_debug.c | |||
@@ -35,6 +35,7 @@ extern char* skin_start; | |||
35 | /* Global error variables */ | 35 | /* Global error variables */ |
36 | int error_line; | 36 | int error_line; |
37 | int error_col; | 37 | int error_col; |
38 | char *error_line_start; | ||
38 | char* error_message; | 39 | char* error_message; |
39 | 40 | ||
40 | /* Debugging functions */ | 41 | /* Debugging functions */ |
@@ -48,6 +49,7 @@ void skin_error(enum skin_errorcode error, char* cursor) | |||
48 | cursor--; | 49 | cursor--; |
49 | error_col++; | 50 | error_col++; |
50 | } | 51 | } |
52 | error_line_start = cursor+1; | ||
51 | 53 | ||
52 | error_line = skin_line; | 54 | error_line = skin_line; |
53 | 55 | ||
@@ -285,4 +287,42 @@ void skin_debug_indent() | |||
285 | for(i = 0; i < debug_indent_level; i++) | 287 | for(i = 0; i < debug_indent_level; i++) |
286 | printf(" "); | 288 | printf(" "); |
287 | } | 289 | } |
290 | |||
288 | #endif | 291 | #endif |
292 | |||
293 | #define MIN(a,b) ((a<b)?(a):(b)) | ||
294 | void skin_error_format_message() | ||
295 | { | ||
296 | int i; | ||
297 | char text[128]; | ||
298 | char* line_end = strchr(error_line_start, '\n'); | ||
299 | int len = MIN(line_end - error_line_start, 80); | ||
300 | if (!line_end) | ||
301 | len = strlen(error_line_start); | ||
302 | printf("Error on line %d.\n", error_line); | ||
303 | error_col--; | ||
304 | if (error_col <= 10) | ||
305 | { | ||
306 | strncpy(text, error_line_start, len); | ||
307 | text[len] = '\0'; | ||
308 | } | ||
309 | else | ||
310 | { | ||
311 | int j; | ||
312 | /* make it fit nicely.. "<start few chars>...<10 chars><error>" */ | ||
313 | strncpy(text, error_line_start, 6); | ||
314 | i = 5; | ||
315 | text[i++] = '.'; | ||
316 | text[i++] = '.'; | ||
317 | text[i++] = '.'; | ||
318 | for (j=error_col-10; error_line_start[j] && error_line_start[j] != '\n'; j++) | ||
319 | text[i++] = error_line_start[j]; | ||
320 | text[i] = '\0'; | ||
321 | error_col = 18; | ||
322 | } | ||
323 | printf("%s\n", text); | ||
324 | for (i=0; i<error_col; i++) | ||
325 | text[i] = ' '; | ||
326 | snprintf(&text[i],64, "^ \'%s\' Here", error_message); | ||
327 | printf("%s\n", text); | ||
328 | } | ||