summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-18 00:59:02 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-18 00:59:02 +0000
commit3c4fb8abe4e28091cb857705af2d762cd00b985a (patch)
tree804090633b693cbb185d801a75683404d345e2fc
parenteb52a45a0c1f42386dbc0e148e81972ae3878b71 (diff)
downloadrockbox-3c4fb8abe4e28091cb857705af2d762cd00b985a.tar.gz
rockbox-3c4fb8abe4e28091cb857705af2d762cd00b985a.zip
Theme Editor: Added column number to parser error messages
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27477 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--lib/skin_parser/skin_debug.c18
-rw-r--r--lib/skin_parser/skin_debug.h3
-rw-r--r--lib/skin_parser/skin_parser.c26
-rw-r--r--utils/themeeditor/gui/skindocument.cpp4
-rw-r--r--utils/themeeditor/models/parsetreemodel.cpp1
5 files changed, 37 insertions, 15 deletions
diff --git a/lib/skin_parser/skin_debug.c b/lib/skin_parser/skin_debug.c
index 4abe6252f0..c03b32e910 100644
--- a/lib/skin_parser/skin_debug.c
+++ b/lib/skin_parser/skin_debug.c
@@ -30,15 +30,25 @@
30/* Global variables for debug output */ 30/* Global variables for debug output */
31int debug_indent_level = 0; 31int debug_indent_level = 0;
32extern int skin_line; 32extern int skin_line;
33extern char* skin_start;
33 34
34/* Global error variables */ 35/* Global error variables */
35int error_line; 36int error_line;
37int error_col;
36char* error_message; 38char* error_message;
37 39
38/* Debugging functions */ 40/* Debugging functions */
39void skin_error(enum skin_errorcode error) 41void skin_error(enum skin_errorcode error, char* cursor)
40{ 42{
41 43
44 error_col = 0;
45
46 while(cursor > skin_start && *cursor != '\n')
47 {
48 cursor--;
49 error_col++;
50 }
51
42 error_line = skin_line; 52 error_line = skin_line;
43 53
44 switch(error) 54 switch(error)
@@ -91,6 +101,11 @@ int skin_error_line()
91 return error_line; 101 return error_line;
92} 102}
93 103
104int skin_error_col()
105{
106 return error_col;
107}
108
94char* skin_error_message() 109char* skin_error_message()
95{ 110{
96 return error_message; 111 return error_message;
@@ -99,6 +114,7 @@ char* skin_error_message()
99void skin_clear_errors() 114void skin_clear_errors()
100{ 115{
101 error_line = 0; 116 error_line = 0;
117 error_col = 0;
102 error_message = NULL; 118 error_message = NULL;
103} 119}
104 120
diff --git a/lib/skin_parser/skin_debug.h b/lib/skin_parser/skin_debug.h
index 8fc061a9f9..fbff5cbb4c 100644
--- a/lib/skin_parser/skin_debug.h
+++ b/lib/skin_parser/skin_debug.h
@@ -31,8 +31,9 @@ extern "C"
31#include "skin_parser.h" 31#include "skin_parser.h"
32#ifndef ROCKBOX 32#ifndef ROCKBOX
33/* Debugging functions */ 33/* Debugging functions */
34void skin_error(enum skin_errorcode error); 34void skin_error(enum skin_errorcode error, char* cursor);
35int skin_error_line(void); 35int skin_error_line(void);
36int skin_error_col(void);
36char* skin_error_message(void); 37char* skin_error_message(void);
37void skin_clear_errors(void); 38void skin_clear_errors(void);
38void skin_debug_tree(struct skin_element* root); 39void skin_debug_tree(struct skin_element* root);
diff --git a/lib/skin_parser/skin_parser.c b/lib/skin_parser/skin_parser.c
index 5bc5984fb7..3e23067258 100644
--- a/lib/skin_parser/skin_parser.c
+++ b/lib/skin_parser/skin_parser.c
@@ -34,6 +34,7 @@
34 34
35/* Global variables for the parser */ 35/* Global variables for the parser */
36int skin_line = 0; 36int skin_line = 0;
37char* skin_start = 0;
37int viewport_line = 0; 38int viewport_line = 0;
38 39
39/* Auxiliary parsing functions (not visible at global scope) */ 40/* Auxiliary parsing functions (not visible at global scope) */
@@ -66,6 +67,7 @@ struct skin_element* skin_parse(const char* document)
66 char* cursor = (char*)document; /*Keeps track of location in the document*/ 67 char* cursor = (char*)document; /*Keeps track of location in the document*/
67 68
68 skin_line = 1; 69 skin_line = 1;
70 skin_start = (char*)document;
69 viewport_line = 0; 71 viewport_line = 0;
70 72
71 skin_clear_errors(); 73 skin_clear_errors();
@@ -381,7 +383,7 @@ static struct skin_element* skin_parse_sublines_optional(char** document,
381 383
382 if(*cursor != MULTILINESYM && i != sublines - 1) 384 if(*cursor != MULTILINESYM && i != sublines - 1)
383 { 385 {
384 skin_error(MULTILINE_EXPECTED); 386 skin_error(MULTILINE_EXPECTED, cursor);
385 return NULL; 387 return NULL;
386 } 388 }
387 else if(i != sublines - 1) 389 else if(i != sublines - 1)
@@ -433,7 +435,7 @@ static int skin_parse_tag(struct skin_element* element, char** document)
433 435
434 if(!tag) 436 if(!tag)
435 { 437 {
436 skin_error(ILLEGAL_TAG); 438 skin_error(ILLEGAL_TAG, cursor);
437 return 0; 439 return 0;
438 } 440 }
439 441
@@ -464,7 +466,7 @@ static int skin_parse_tag(struct skin_element* element, char** document)
464 /* Checking the number of arguments and allocating args */ 466 /* Checking the number of arguments and allocating args */
465 if(*cursor != ARGLISTOPENSYM && tag_args[0] != '|') 467 if(*cursor != ARGLISTOPENSYM && tag_args[0] != '|')
466 { 468 {
467 skin_error(ARGLIST_EXPECTED); 469 skin_error(ARGLIST_EXPECTED, cursor);
468 return 0; 470 return 0;
469 } 471 }
470 else 472 else
@@ -512,7 +514,7 @@ static int skin_parse_tag(struct skin_element* element, char** document)
512 /* Making sure we haven't run out of arguments */ 514 /* Making sure we haven't run out of arguments */
513 if(*tag_args == '\0') 515 if(*tag_args == '\0')
514 { 516 {
515 skin_error(TOO_MANY_ARGS); 517 skin_error(TOO_MANY_ARGS, cursor);
516 return 0; 518 return 0;
517 } 519 }
518 520
@@ -545,7 +547,7 @@ static int skin_parse_tag(struct skin_element* element, char** document)
545 } 547 }
546 else 548 else
547 { 549 {
548 skin_error(DEFAULT_NOT_ALLOWED); 550 skin_error(DEFAULT_NOT_ALLOWED, cursor);
549 return 0; 551 return 0;
550 } 552 }
551 } 553 }
@@ -554,7 +556,7 @@ static int skin_parse_tag(struct skin_element* element, char** document)
554 /* Scanning an int argument */ 556 /* Scanning an int argument */
555 if(!isdigit(*cursor) && *cursor != '-') 557 if(!isdigit(*cursor) && *cursor != '-')
556 { 558 {
557 skin_error(INT_EXPECTED); 559 skin_error(INT_EXPECTED, cursor);
558 return 0; 560 return 0;
559 } 561 }
560 562
@@ -610,12 +612,12 @@ static int skin_parse_tag(struct skin_element* element, char** document)
610 612
611 if(*cursor != ARGLISTSEPERATESYM && i < num_args - 1) 613 if(*cursor != ARGLISTSEPERATESYM && i < num_args - 1)
612 { 614 {
613 skin_error(SEPERATOR_EXPECTED); 615 skin_error(SEPERATOR_EXPECTED, cursor);
614 return 0; 616 return 0;
615 } 617 }
616 else if(*cursor != ARGLISTCLOSESYM && i == num_args - 1) 618 else if(*cursor != ARGLISTCLOSESYM && i == num_args - 1)
617 { 619 {
618 skin_error(CLOSE_EXPECTED); 620 skin_error(CLOSE_EXPECTED, cursor);
619 return 0; 621 return 0;
620 } 622 }
621 else 623 else
@@ -639,7 +641,7 @@ static int skin_parse_tag(struct skin_element* element, char** document)
639 /* Checking for a premature end */ 641 /* Checking for a premature end */
640 if(*tag_args != '\0' && !optional) 642 if(*tag_args != '\0' && !optional)
641 { 643 {
642 skin_error(INSUFFICIENT_ARGS); 644 skin_error(INSUFFICIENT_ARGS, cursor);
643 return 0; 645 return 0;
644 } 646 }
645 647
@@ -724,7 +726,7 @@ static int skin_parse_conditional(struct skin_element* element, char** document)
724 /* Counting the children */ 726 /* Counting the children */
725 if(*(cursor++) != ENUMLISTOPENSYM) 727 if(*(cursor++) != ENUMLISTOPENSYM)
726 { 728 {
727 skin_error(ARGLIST_EXPECTED); 729 skin_error(ARGLIST_EXPECTED, cursor);
728 return 0; 730 return 0;
729 } 731 }
730 bookmark = cursor; 732 bookmark = cursor;
@@ -768,12 +770,12 @@ static int skin_parse_conditional(struct skin_element* element, char** document)
768 770
769 if(i < children - 1 && *cursor != ENUMLISTSEPERATESYM) 771 if(i < children - 1 && *cursor != ENUMLISTSEPERATESYM)
770 { 772 {
771 skin_error(SEPERATOR_EXPECTED); 773 skin_error(SEPERATOR_EXPECTED, cursor);
772 return 0; 774 return 0;
773 } 775 }
774 else if(i == children - 1 && *cursor != ENUMLISTCLOSESYM) 776 else if(i == children - 1 && *cursor != ENUMLISTCLOSESYM)
775 { 777 {
776 skin_error(CLOSE_EXPECTED); 778 skin_error(CLOSE_EXPECTED, cursor);
777 return 0; 779 return 0;
778 } 780 }
779 else 781 else
diff --git a/utils/themeeditor/gui/skindocument.cpp b/utils/themeeditor/gui/skindocument.cpp
index f04c12d213..18877d14ee 100644
--- a/utils/themeeditor/gui/skindocument.cpp
+++ b/utils/themeeditor/gui/skindocument.cpp
@@ -211,7 +211,9 @@ void SkinDocument::cursorChanged()
211 skin_parse(line.selectedText().toAscii()); 211 skin_parse(line.selectedText().toAscii());
212 if(skin_error_line() > 0) 212 if(skin_error_line() > 0)
213 parseStatus = tr("Error on line ") + 213 parseStatus = tr("Error on line ") +
214 QString::number(line.blockNumber() + 1) + tr(": ") + 214 QString::number(line.blockNumber() + 1)
215 + tr(", column ") + QString::number(skin_error_col())
216 + tr(": ") +
215 skin_error_message(); 217 skin_error_message();
216 statusLabel->setText(parseStatus); 218 statusLabel->setText(parseStatus);
217 } 219 }
diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp
index 66c96213ab..8e49118e2e 100644
--- a/utils/themeeditor/models/parsetreemodel.cpp
+++ b/utils/themeeditor/models/parsetreemodel.cpp
@@ -72,6 +72,7 @@ QString ParseTreeModel::changeTree(const char *document)
72 { 72 {
73 QString error = tr("Error on line ") + 73 QString error = tr("Error on line ") +
74 QString::number(skin_error_line()) 74 QString::number(skin_error_line())
75 + tr(", column ") + QString::number(skin_error_col())
75 + tr(": ") + QString(skin_error_message()); 76 + tr(": ") + QString(skin_error_message());
76 return error; 77 return error;
77 } 78 }