summaryrefslogtreecommitdiff
path: root/utils/themeeditor/skin_parser.c
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-10 21:02:44 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-10 21:02:44 +0000
commit64321adf4331a97201321f5a37d17aa90fa5d5db (patch)
tree4ab86b70f8b4059432e713a1ef7c03613fa9ad0e /utils/themeeditor/skin_parser.c
parent6c522624b364b3d85ac7f95d55061d4677246dad (diff)
downloadrockbox-64321adf4331a97201321f5a37d17aa90fa5d5db.tar.gz
rockbox-64321adf4331a97201321f5a37d17aa90fa5d5db.zip
Theme Editor: Applied FS#11389, switched conditional elements to use tag fields along with children, instead of holding the tag as the first child
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26751 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/skin_parser.c')
-rw-r--r--utils/themeeditor/skin_parser.c184
1 files changed, 78 insertions, 106 deletions
diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c
index 401181cc3d..0eda9daa09 100644
--- a/utils/themeeditor/skin_parser.c
+++ b/utils/themeeditor/skin_parser.c
@@ -30,27 +30,32 @@
30#include "symbols.h" 30#include "symbols.h"
31#include "skin_scan.h" 31#include "skin_scan.h"
32 32
33#ifdef ROCKBOX
33/* Declaration of parse tree buffer */ 34/* Declaration of parse tree buffer */
34char skin_parse_tree[SKIN_MAX_MEMORY]; 35#define SKIN_MAX_MEMORY (30*1024)
35int skin_current_block = 0; 36static char skin_parse_tree[SKIN_MAX_MEMORY];
37static char *skin_buffer;
38#endif
36 39
37/* Global variables for the parser */ 40/* Global variables for the parser */
38int skin_line = 0; 41int skin_line = 0;
39 42
40/* Auxiliary parsing functions (not visible at global scope) */ 43/* Auxiliary parsing functions (not visible at global scope) */
41struct skin_element* skin_parse_viewport(char** document); 44static struct skin_element* skin_parse_viewport(char** document);
42struct skin_element* skin_parse_line(char** document); 45static struct skin_element* skin_parse_line(char** document);
43struct skin_element* skin_parse_line_optional(char** document, int conditional); 46static struct skin_element* skin_parse_line_optional(char** document,
44struct skin_element* skin_parse_sublines(char** document); 47 int conditional);
45struct skin_element* skin_parse_sublines_optional(char** document, 48static struct skin_element* skin_parse_sublines(char** document);
46 int conditional); 49static struct skin_element* skin_parse_sublines_optional(char** document,
47 50 int conditional);
48int skin_parse_tag(struct skin_element* element, char** document); 51
49int skin_parse_text(struct skin_element* element, char** document, 52static int skin_parse_tag(struct skin_element* element, char** document);
50 int conditional); 53static int skin_parse_text(struct skin_element* element, char** document,
51int skin_parse_conditional(struct skin_element* element, char** document); 54 int conditional);
52int skin_parse_comment(struct skin_element* element, char** document); 55static int skin_parse_conditional(struct skin_element* element,
53struct skin_element* skin_parse_code_as_arg(char** document); 56 char** document);
57static int skin_parse_comment(struct skin_element* element, char** document);
58static struct skin_element* skin_parse_code_as_arg(char** document);
54 59
55struct skin_element* skin_parse(const char* document) 60struct skin_element* skin_parse(const char* document)
56{ 61{
@@ -61,6 +66,10 @@ struct skin_element* skin_parse(const char* document)
61 struct skin_element** to_write = 0; 66 struct skin_element** to_write = 0;
62 67
63 char* cursor = (char*)document; /*Keeps track of location in the document*/ 68 char* cursor = (char*)document; /*Keeps track of location in the document*/
69#ifdef ROCKBOX
70 /* FIXME */
71 skin_buffer = &skin_parse_tree[0];
72#endif
64 73
65 skin_line = 1; 74 skin_line = 1;
66 75
@@ -93,7 +102,7 @@ struct skin_element* skin_parse(const char* document)
93 102
94} 103}
95 104
96struct skin_element* skin_parse_viewport(char** document) 105static struct skin_element* skin_parse_viewport(char** document)
97{ 106{
98 107
99 struct skin_element* root = NULL; 108 struct skin_element* root = NULL;
@@ -218,7 +227,7 @@ struct skin_element* skin_parse_viewport(char** document)
218 227
219/* Auxiliary Parsing Functions */ 228/* Auxiliary Parsing Functions */
220 229
221struct skin_element* skin_parse_line(char**document) 230static struct skin_element* skin_parse_line(char**document)
222{ 231{
223 232
224 return skin_parse_line_optional(document, 0); 233 return skin_parse_line_optional(document, 0);
@@ -231,7 +240,8 @@ struct skin_element* skin_parse_line(char**document)
231 * SEPERATESYM. This should only be used when parsing a line inside a 240 * SEPERATESYM. This should only be used when parsing a line inside a
232 * conditional, otherwise just use the wrapper function skin_parse_line() 241 * conditional, otherwise just use the wrapper function skin_parse_line()
233 */ 242 */
234struct skin_element* skin_parse_line_optional(char** document, int conditional) 243static struct skin_element* skin_parse_line_optional(char** document,
244 int conditional)
235{ 245{
236 char* cursor = *document; 246 char* cursor = *document;
237 247
@@ -296,12 +306,12 @@ struct skin_element* skin_parse_line_optional(char** document, int conditional)
296 return retval; 306 return retval;
297} 307}
298 308
299struct skin_element* skin_parse_sublines(char** document) 309static struct skin_element* skin_parse_sublines(char** document)
300{ 310{
301 return skin_parse_sublines_optional(document, 0); 311 return skin_parse_sublines_optional(document, 0);
302} 312}
303 313
304struct skin_element* skin_parse_sublines_optional(char** document, 314static struct skin_element* skin_parse_sublines_optional(char** document,
305 int conditional) 315 int conditional)
306{ 316{
307 struct skin_element* retval; 317 struct skin_element* retval;
@@ -379,7 +389,7 @@ struct skin_element* skin_parse_sublines_optional(char** document,
379 return retval; 389 return retval;
380} 390}
381 391
382int skin_parse_tag(struct skin_element* element, char** document) 392static int skin_parse_tag(struct skin_element* element, char** document)
383{ 393{
384 394
385 char* cursor = *document + 1; 395 char* cursor = *document + 1;
@@ -422,7 +432,8 @@ int skin_parse_tag(struct skin_element* element, char** document)
422 } 432 }
423 433
424 /* Copying basic tag info */ 434 /* Copying basic tag info */
425 element->type = TAG; 435 if(element->type != CONDITIONAL)
436 element->type = TAG;
426 element->tag = tag; 437 element->tag = tag;
427 tag_args = tag->params; 438 tag_args = tag->params;
428 element->line = skin_line; 439 element->line = skin_line;
@@ -606,14 +617,13 @@ int skin_parse_tag(struct skin_element* element, char** document)
606 * If the conditional flag is set true, then parsing text will stop at an 617 * If the conditional flag is set true, then parsing text will stop at an
607 * ARGLISTSEPERATESYM. Only set that flag when parsing within a conditional 618 * ARGLISTSEPERATESYM. Only set that flag when parsing within a conditional
608 */ 619 */
609int skin_parse_text(struct skin_element* element, char** document, 620static int skin_parse_text(struct skin_element* element, char** document,
610 int conditional) 621 int conditional)
611{ 622{
612 char* cursor = *document; 623 char* cursor = *document;
613
614 int length = 0; 624 int length = 0;
615
616 int dest; 625 int dest;
626 char *text = NULL;
617 627
618 /* First figure out how much text we're copying */ 628 /* First figure out how much text we're copying */
619 while(*cursor != '\0' && *cursor != '\n' && *cursor != MULTILINESYM 629 while(*cursor != '\0' && *cursor != '\n' && *cursor != MULTILINESYM
@@ -643,7 +653,7 @@ int skin_parse_text(struct skin_element* element, char** document,
643 element->type = TEXT; 653 element->type = TEXT;
644 element->line = skin_line; 654 element->line = skin_line;
645 element->next = NULL; 655 element->next = NULL;
646 element->text = skin_alloc_string(length); 656 element->data = text = skin_alloc_string(length);
647 657
648 for(dest = 0; dest < length; dest++) 658 for(dest = 0; dest < length; dest++)
649 { 659 {
@@ -651,22 +661,21 @@ int skin_parse_text(struct skin_element* element, char** document,
651 if(*cursor == TAGSYM) 661 if(*cursor == TAGSYM)
652 cursor++; 662 cursor++;
653 663
654 element->text[dest] = *cursor; 664 text[dest] = *cursor;
655 cursor++; 665 cursor++;
656 } 666 }
657 element->text[length] = '\0'; 667 text[length] = '\0';
658 668
659 *document = cursor; 669 *document = cursor;
660 670
661 return 1; 671 return 1;
662} 672}
663 673
664int skin_parse_conditional(struct skin_element* element, char** document) 674static int skin_parse_conditional(struct skin_element* element, char** document)
665{ 675{
666 676
667 char* cursor = *document + 1; /* Starting past the "%" */ 677 char* cursor = *document + 1; /* Starting past the "%" */
668 char* bookmark; 678 char* bookmark;
669 struct skin_element* tag = skin_alloc_element(); /* The tag to evaluate */
670 int children = 1; 679 int children = 1;
671 int i; 680 int i;
672 681
@@ -674,7 +683,7 @@ int skin_parse_conditional(struct skin_element* element, char** document)
674 element->line = skin_line; 683 element->line = skin_line;
675 684
676 /* Parsing the tag first */ 685 /* Parsing the tag first */
677 if(!skin_parse_tag(tag, &cursor)) 686 if(!skin_parse_tag(element, &cursor))
678 return 0; 687 return 0;
679 688
680 /* Counting the children */ 689 /* Counting the children */
@@ -714,21 +723,20 @@ int skin_parse_conditional(struct skin_element* element, char** document)
714 cursor = bookmark; 723 cursor = bookmark;
715 724
716 /* Parsing the children */ 725 /* Parsing the children */
717 element->children_count = children + 1; /* Make sure to include the tag */ 726 element->children = skin_alloc_children(children);
718 element->children = skin_alloc_children(children + 1); 727 element->children_count = children;
719 element->children[0] = tag;
720 728
721 for(i = 1; i < children + 1; i++) 729 for(i = 0; i < children; i++)
722 { 730 {
723 element->children[i] = skin_parse_code_as_arg(&cursor); 731 element->children[i] = skin_parse_code_as_arg(&cursor);
724 skip_whitespace(&cursor); 732 skip_whitespace(&cursor);
725 733
726 if(i < children && *cursor != ENUMLISTSEPERATESYM) 734 if(i < children - 1 && *cursor != ENUMLISTSEPERATESYM)
727 { 735 {
728 skin_error(SEPERATOR_EXPECTED); 736 skin_error(SEPERATOR_EXPECTED);
729 return 0; 737 return 0;
730 } 738 }
731 else if(i == children && *cursor != ENUMLISTCLOSESYM) 739 else if(i == children - 1 && *cursor != ENUMLISTCLOSESYM)
732 { 740 {
733 skin_error(CLOSE_EXPECTED); 741 skin_error(CLOSE_EXPECTED);
734 return 0; 742 return 0;
@@ -744,9 +752,10 @@ int skin_parse_conditional(struct skin_element* element, char** document)
744 return 1; 752 return 1;
745} 753}
746 754
747int skin_parse_comment(struct skin_element* element, char** document) 755static int skin_parse_comment(struct skin_element* element, char** document)
748{ 756{
749 char* cursor = *document; 757 char* cursor = *document;
758 char* text = NULL;
750 759
751 int length; 760 int length;
752 /* 761 /*
@@ -758,12 +767,15 @@ int skin_parse_comment(struct skin_element* element, char** document)
758 767
759 element->type = COMMENT; 768 element->type = COMMENT;
760 element->line = skin_line; 769 element->line = skin_line;
761 element->text = skin_alloc_string(length); 770#ifdef ROCKBOX
771 element->data = NULL;
772#else
773 element->data = text = skin_alloc_string(length);
762 /* We copy from one char past cursor to leave out the # */ 774 /* We copy from one char past cursor to leave out the # */
763 memcpy((void*)(element->text), (void*)(cursor + 1), 775 memcpy((void*)text, (void*)(cursor + 1),
764 sizeof(char) * (length-1)); 776 sizeof(char) * (length-1));
765 element->text[length - 1] = '\0'; 777 text[length - 1] = '\0';
766 778#endif
767 if(cursor[length] == '\n') 779 if(cursor[length] == '\n')
768 skin_line++; 780 skin_line++;
769 781
@@ -774,7 +786,7 @@ int skin_parse_comment(struct skin_element* element, char** document)
774 return 1; 786 return 1;
775} 787}
776 788
777struct skin_element* skin_parse_code_as_arg(char** document) 789static struct skin_element* skin_parse_code_as_arg(char** document)
778{ 790{
779 791
780 int sublines = 0; 792 int sublines = 0;
@@ -813,29 +825,21 @@ struct skin_element* skin_parse_code_as_arg(char** document)
813 825
814 826
815/* Memory management */ 827/* Memory management */
816struct skin_element* skin_alloc_element() 828char* skin_alloc(size_t size)
817{ 829{
818 830#ifdef ROCKBOX
819#if 0 831 char *retval = skin_buffer;
820 832 skin_buffer = (void *)(((unsigned long)skin_buffer + 3) & ~3);
821 char* retval = &skin_parse_tree[skin_current_block * 4]; 833 return retval;
822 834#else
823 int delta = sizeof(struct skin_element) / (sizeof(char) * 4); 835 return malloc(size);
824
825 /* If one block is partially filled, make sure to advance to the
826 * next one for the next allocation
827 */
828 if(sizeof(struct skin_element) % (sizeof(char) * 4) != 0)
829 delta++;
830
831 skin_current_block += delta;
832
833 return (struct skin_element*)retval;
834
835#endif 836#endif
837}
836 838
839struct skin_element* skin_alloc_element()
840{
837 struct skin_element* retval = (struct skin_element*) 841 struct skin_element* retval = (struct skin_element*)
838 malloc(sizeof(struct skin_element)); 842 skin_alloc(sizeof(struct skin_element));
839 retval->next = NULL; 843 retval->next = NULL;
840 retval->params_count = 0; 844 retval->params_count = 0;
841 retval->children_count = 0; 845 retval->children_count = 0;
@@ -846,60 +850,25 @@ struct skin_element* skin_alloc_element()
846 850
847struct skin_tag_parameter* skin_alloc_params(int count) 851struct skin_tag_parameter* skin_alloc_params(int count)
848{ 852{
849#if 0 853 size_t size = sizeof(struct skin_tag_parameter) * count;
850 854 return (struct skin_tag_parameter*)skin_alloc(size);
851 char* retval = &skin_parse_tree[skin_current_block * 4];
852
853 int delta = sizeof(struct skin_tag_parameter) / (sizeof(char) * 4);
854 delta *= count;
855
856 /* Correcting uneven alignment */
857 if(count * sizeof(struct skin_tag_parameter) % (sizeof(char) * 4) != 0)
858 delta++;
859
860 skin_current_block += delta;
861
862 return (struct skin_tag_parameter*) retval;
863
864#endif
865
866 return (struct skin_tag_parameter*)malloc(sizeof(struct skin_tag_parameter)
867 * count);
868 855
869} 856}
870 857
871char* skin_alloc_string(int length) 858char* skin_alloc_string(int length)
872{ 859{
873 860 return (char*)skin_alloc(sizeof(char) * (length + 1));
874#if 0
875 char* retval = &skin_parse_tree[skin_current_block * 4];
876
877 /* Checking alignment */
878 length++; /* Accounting for the null terminator */
879 int delta = length / 4;
880 if(length % 4 != 0)
881 delta++;
882
883 skin_current_block += delta;
884
885 if(skin_current_block >= SKIN_MAX_MEMORY / 4)
886 skin_error(MEMORY_LIMIT_EXCEEDED);
887
888 return retval;
889
890#endif
891
892 return (char*)malloc(sizeof(char) * (length + 1));
893
894} 861}
895 862
896struct skin_element** skin_alloc_children(int count) 863struct skin_element** skin_alloc_children(int count)
897{ 864{
898 return (struct skin_element**) malloc(sizeof(struct skin_element*) * count); 865 return (struct skin_element**)
866 skin_alloc(sizeof(struct skin_element*) * count);
899} 867}
900 868
901void skin_free_tree(struct skin_element* root) 869void skin_free_tree(struct skin_element* root)
902{ 870{
871#ifndef ROCKBOX
903 int i; 872 int i;
904 873
905 /* First make the recursive call */ 874 /* First make the recursive call */
@@ -908,8 +877,8 @@ void skin_free_tree(struct skin_element* root)
908 skin_free_tree(root->next); 877 skin_free_tree(root->next);
909 878
910 /* Free any text */ 879 /* Free any text */
911 if(root->type == TEXT) 880 if(root->type == TEXT || root->type == COMMENT)
912 free(root->text); 881 free(root->data);
913 882
914 /* Then recursively free any children, before freeing their pointers */ 883 /* Then recursively free any children, before freeing their pointers */
915 for(i = 0; i < root->children_count; i++) 884 for(i = 0; i < root->children_count; i++)
@@ -926,4 +895,7 @@ void skin_free_tree(struct skin_element* root)
926 895
927 /* Finally, delete root's memory */ 896 /* Finally, delete root's memory */
928 free(root); 897 free(root);
898#else
899 (void)root;
900#endif
929} 901}