diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2012-02-02 22:26:16 +1100 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2012-02-07 21:41:18 +1100 |
commit | 40ecdf6811d9a717ef67ff1833a67dbb521f91be (patch) | |
tree | ddde16bbb941fb70515a6127339b0a2f176e224f /lib/skin_parser/skin_parser.c | |
parent | f1eedb80a2efbf60cfc25182b72e3da07e0f1250 (diff) | |
download | rockbox-40ecdf6811d9a717ef67ff1833a67dbb521f91be.tar.gz rockbox-40ecdf6811d9a717ef67ff1833a67dbb521f91be.zip |
skin engine: New logical 'and' and 'or' tags to evaluate multiple tags in a single conditional.
Use these tags to stop having multiple conditionals.. e.g:
OLD: %?C<%?Ia<something>>
NEW: %?and(%C, %Ia)<something>
Change-Id: Ia3bbe4611cf808e87dcd1b1147181461fa08294a
Diffstat (limited to 'lib/skin_parser/skin_parser.c')
-rw-r--r-- | lib/skin_parser/skin_parser.c | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/lib/skin_parser/skin_parser.c b/lib/skin_parser/skin_parser.c index 24f64fd788..a81bcded34 100644 --- a/lib/skin_parser/skin_parser.c +++ b/lib/skin_parser/skin_parser.c | |||
@@ -513,35 +513,31 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
513 | { | 513 | { |
514 | const char* cursor = *document + 1; | 514 | const char* cursor = *document + 1; |
515 | const char* bookmark; | 515 | const char* bookmark; |
516 | char *open_square_bracket = NULL; | ||
516 | 517 | ||
517 | char tag_name[3]; | 518 | char tag_name[MAX_TAG_LENGTH]; |
518 | char* tag_args; | 519 | char* tag_args; |
519 | const struct tag_info *tag; | 520 | const struct tag_info *tag; |
520 | struct skin_tag_parameter* params = NULL; | 521 | struct skin_tag_parameter* params = NULL; |
521 | 522 | ||
522 | int num_args = 1; | 523 | int num_args = 1; |
523 | int i; | 524 | int i; |
524 | int star = 0; /* Flag for the all-or-none option */ | 525 | int qmark = 0; /* Flag for the all-or-none option */ |
525 | 526 | ||
526 | int optional = 0; | 527 | int optional = 0; |
527 | 528 | ||
528 | /* Checking the tag name */ | 529 | /* Checking the tag name */ |
529 | tag_name[0] = cursor[0]; | 530 | for (i=0; cursor[i] && i<MAX_TAG_LENGTH; i++) |
530 | tag_name[1] = cursor[1]; | 531 | tag_name[i] = cursor[i]; |
531 | tag_name[2] = '\0'; | ||
532 | 532 | ||
533 | /* First we check the two characters after the '%', then a single char */ | 533 | /* First we check the two characters after the '%', then a single char */ |
534 | tag = find_tag(tag_name); | 534 | tag = NULL; |
535 | 535 | i = MAX_TAG_LENGTH; | |
536 | if(!tag) | 536 | while (!tag && i > 1) |
537 | { | 537 | { |
538 | tag_name[1] = '\0'; | 538 | tag_name[i-1] = '\0'; |
539 | tag = find_tag(tag_name); | 539 | tag = find_tag(tag_name); |
540 | cursor++; | 540 | i--; |
541 | } | ||
542 | else | ||
543 | { | ||
544 | cursor += 2; | ||
545 | } | 541 | } |
546 | 542 | ||
547 | if(!tag) | 543 | if(!tag) |
@@ -549,6 +545,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
549 | skin_error(ILLEGAL_TAG, cursor); | 545 | skin_error(ILLEGAL_TAG, cursor); |
550 | return 0; | 546 | return 0; |
551 | } | 547 | } |
548 | cursor += i; | ||
552 | 549 | ||
553 | /* Copying basic tag info */ | 550 | /* Copying basic tag info */ |
554 | if(element->type != CONDITIONAL && element->type != VIEWPORT) | 551 | if(element->type != CONDITIONAL && element->type != VIEWPORT) |
@@ -558,16 +555,16 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
558 | element->line = skin_line; | 555 | element->line = skin_line; |
559 | 556 | ||
560 | /* Checking for the * flag */ | 557 | /* Checking for the * flag */ |
561 | if(tag_args[0] == '*') | 558 | if(tag_args[0] == '?') |
562 | { | 559 | { |
563 | star = 1; | 560 | qmark = 1; |
564 | tag_args++; | 561 | tag_args++; |
565 | } | 562 | } |
566 | 563 | ||
567 | /* If this tag has no arguments, we can bail out now */ | 564 | /* If this tag has no arguments, we can bail out now */ |
568 | if(strlen(tag_args) == 0 | 565 | if(strlen(tag_args) == 0 |
569 | || (tag_args[0] == '|' && *cursor != ARGLISTOPENSYM) | 566 | || (tag_args[0] == '|' && *cursor != ARGLISTOPENSYM) |
570 | || (star && *cursor != ARGLISTOPENSYM)) | 567 | || (qmark && *cursor != ARGLISTOPENSYM)) |
571 | { | 568 | { |
572 | 569 | ||
573 | #ifdef ROCKBOX | 570 | #ifdef ROCKBOX |
@@ -663,6 +660,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
663 | bool canbedefault = false; | 660 | bool canbedefault = false; |
664 | bool haspercent = false, number = true, hasdecimal = false; | 661 | bool haspercent = false, number = true, hasdecimal = false; |
665 | char temp_params[8]; | 662 | char temp_params[8]; |
663 | open_square_bracket = tag_args; | ||
666 | tag_args++; | 664 | tag_args++; |
667 | while (*tag_args != ']') | 665 | while (*tag_args != ']') |
668 | { | 666 | { |
@@ -681,7 +679,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
681 | (cursor[j] == '-')); | 679 | (cursor[j] == '-')); |
682 | j++; | 680 | j++; |
683 | } | 681 | } |
684 | type_code = '*'; | 682 | type_code = '?'; |
685 | if (canbedefault && *cursor == DEFAULTSYM && !isdigit(cursor[1])) | 683 | if (canbedefault && *cursor == DEFAULTSYM && !isdigit(cursor[1])) |
686 | { | 684 | { |
687 | type_code = 'i'; | 685 | type_code = 'i'; |
@@ -704,7 +702,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
704 | { | 702 | { |
705 | type_code = 's'; | 703 | type_code = 's'; |
706 | } | 704 | } |
707 | if (type_code == '*') | 705 | if (type_code == '?') |
708 | { | 706 | { |
709 | skin_error(INSUFFICIENT_ARGS, cursor); | 707 | skin_error(INSUFFICIENT_ARGS, cursor); |
710 | return 0; | 708 | return 0; |
@@ -768,8 +766,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
768 | params[i].type = DECIMAL; | 766 | params[i].type = DECIMAL; |
769 | params[i].data.number = val; | 767 | params[i].data.number = val; |
770 | } | 768 | } |
771 | else if(tolower(type_code) == 'n' || | 769 | else if(tolower(type_code) == 's' || tolower(type_code) == 'f') |
772 | tolower(type_code) == 's' || tolower(type_code) == 'f') | ||
773 | { | 770 | { |
774 | /* Scanning a string argument */ | 771 | /* Scanning a string argument */ |
775 | params[i].type = STRING; | 772 | params[i].type = STRING; |
@@ -813,7 +810,17 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
813 | cursor++; | 810 | cursor++; |
814 | } | 811 | } |
815 | 812 | ||
816 | if (*tag_args != 'N') | 813 | if (*(tag_args + 1) == '*') |
814 | { | ||
815 | if (i+1 == num_args) | ||
816 | tag_args += 2; | ||
817 | else if (open_square_bracket) | ||
818 | { | ||
819 | tag_args = open_square_bracket; | ||
820 | open_square_bracket = NULL; | ||
821 | } | ||
822 | } | ||
823 | else | ||
817 | tag_args++; | 824 | tag_args++; |
818 | 825 | ||
819 | /* Checking for the optional bar */ | 826 | /* Checking for the optional bar */ |