diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-03-13 03:35:18 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-03-13 03:45:00 -0400 |
commit | 74df3ba2d823fde29b28ae3975e4ddfe09e4d69e (patch) | |
tree | 66b44c01eec50e4688bf24042a9660fff9745e3f /apps | |
parent | a9c62f2c39a74ccfc05fa7160efade49286da77c (diff) | |
download | rockbox-74df3ba2d823fde29b28ae3975e4ddfe09e4d69e.tar.gz rockbox-74df3ba2d823fde29b28ae3975e4ddfe09e4d69e.zip |
add function string_option to misc.c use in skin_parser.c
function string_option allows a string to be found in a
supplied list of options
Change-Id: If9134090406b74ab11f4ef9ed6517a4b99b9d73e
Diffstat (limited to 'apps')
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 90 | ||||
-rw-r--r-- | apps/misc.c | 35 | ||||
-rw-r--r-- | apps/misc.h | 1 |
3 files changed, 97 insertions, 29 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 7da772fab4..75d91e915d 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c | |||
@@ -601,11 +601,16 @@ static int parse_viewporttextstyle(struct skin_element *element, | |||
601 | *line = (struct line_desc)LINE_DESC_DEFINIT; | 601 | *line = (struct line_desc)LINE_DESC_DEFINIT; |
602 | unsigned colour; | 602 | unsigned colour; |
603 | 603 | ||
604 | if (!strcmp(mode, "invert")) | 604 | const char *vp_options[] = { "invert", "color", "colour", |
605 | "clear", "gradient", NULL}; | ||
606 | |||
607 | int vp_op = string_option(mode, vp_options, false); | ||
608 | |||
609 | if (vp_op == 0) /*invert*/ | ||
605 | { | 610 | { |
606 | line->style = STYLE_INVERT; | 611 | line->style = STYLE_INVERT; |
607 | } | 612 | } |
608 | else if (!strcmp(mode, "colour") || !strcmp(mode, "color")) | 613 | else if (vp_op == 1 || vp_op == 2) /*color/colour*/ |
609 | { | 614 | { |
610 | if (element->params_count < 2 || | 615 | if (element->params_count < 2 || |
611 | !parse_color(curr_screen, get_param_text(element, 1), &colour)) | 616 | !parse_color(curr_screen, get_param_text(element, 1), &colour)) |
@@ -614,7 +619,7 @@ static int parse_viewporttextstyle(struct skin_element *element, | |||
614 | line->text_color = colour; | 619 | line->text_color = colour; |
615 | } | 620 | } |
616 | #ifdef HAVE_LCD_COLOR | 621 | #ifdef HAVE_LCD_COLOR |
617 | else if (!strcmp(mode, "gradient")) | 622 | else if (vp_op == 4) /*gradient*/ |
618 | { | 623 | { |
619 | int num_lines; | 624 | int num_lines; |
620 | if (element->params_count < 2) | 625 | if (element->params_count < 2) |
@@ -627,7 +632,7 @@ static int parse_viewporttextstyle(struct skin_element *element, | |||
627 | line->nlines = num_lines; | 632 | line->nlines = num_lines; |
628 | } | 633 | } |
629 | #endif | 634 | #endif |
630 | else if (!strcmp(mode, "clear")) | 635 | else if (vp_op == 3) /*clear*/ |
631 | { | 636 | { |
632 | line->style = STYLE_DEFAULT; | 637 | line->style = STYLE_DEFAULT; |
633 | } | 638 | } |
@@ -1042,20 +1047,38 @@ static int parse_progressbar_tag(struct skin_element* element, | |||
1042 | } | 1047 | } |
1043 | 1048 | ||
1044 | pb->horizontal = pb->width > pb->height; | 1049 | pb->horizontal = pb->width > pb->height; |
1050 | |||
1051 | enum | ||
1052 | { | ||
1053 | eINVERT = 0, eNOFILL, eNOBORDER, eNOBAR, eSLIDER, eIMAGE, | ||
1054 | eBACKDROP, eVERTICAL, eHORIZONTAL, eNOTOUCH, eSETTING | ||
1055 | }; | ||
1056 | |||
1057 | const char *pb_options[] = {"invert", "nofill", "noborder, nobar", "slider", | ||
1058 | "image", "backdrop", "vertical", "horizontal", | ||
1059 | "notouch", "setting", NULL}; | ||
1060 | |||
1061 | int pb_op; | ||
1062 | |||
1063 | |||
1064 | |||
1065 | |||
1045 | while (curr_param < element->params_count) | 1066 | while (curr_param < element->params_count) |
1046 | { | 1067 | { |
1047 | char* text; | 1068 | char* text; |
1048 | param++; | 1069 | param++; |
1049 | text = SKINOFFSETTOPTR(skin_buffer, param->data.text); | 1070 | text = SKINOFFSETTOPTR(skin_buffer, param->data.text); |
1050 | if (!strcmp(text, "invert")) | 1071 | |
1072 | pb_op = string_option(text, pb_options, false); | ||
1073 | if (pb_op == eINVERT) | ||
1051 | pb->invert_fill_direction = true; | 1074 | pb->invert_fill_direction = true; |
1052 | else if (!strcmp(text, "nofill")) | 1075 | else if (pb_op == eNOFILL) |
1053 | pb->nofill = true; | 1076 | pb->nofill = true; |
1054 | else if (!strcmp(text, "noborder")) | 1077 | else if (pb_op == eNOBORDER) |
1055 | pb->noborder = true; | 1078 | pb->noborder = true; |
1056 | else if (!strcmp(text, "nobar")) | 1079 | else if (pb_op == eNOBAR) |
1057 | pb->nobar = true; | 1080 | pb->nobar = true; |
1058 | else if (!strcmp(text, "slider")) | 1081 | else if (pb_op == eSLIDER) |
1059 | { | 1082 | { |
1060 | if (curr_param+1 < element->params_count) | 1083 | if (curr_param+1 < element->params_count) |
1061 | { | 1084 | { |
@@ -1068,7 +1091,7 @@ static int parse_progressbar_tag(struct skin_element* element, | |||
1068 | else /* option needs the next param */ | 1091 | else /* option needs the next param */ |
1069 | return -1; | 1092 | return -1; |
1070 | } | 1093 | } |
1071 | else if (!strcmp(text, "image")) | 1094 | else if (pb_op == eIMAGE) |
1072 | { | 1095 | { |
1073 | if (curr_param+1 < element->params_count) | 1096 | if (curr_param+1 < element->params_count) |
1074 | { | 1097 | { |
@@ -1079,7 +1102,7 @@ static int parse_progressbar_tag(struct skin_element* element, | |||
1079 | else /* option needs the next param */ | 1102 | else /* option needs the next param */ |
1080 | return -1; | 1103 | return -1; |
1081 | } | 1104 | } |
1082 | else if (!strcmp(text, "backdrop")) | 1105 | else if (pb_op == eBACKDROP) |
1083 | { | 1106 | { |
1084 | if (curr_param+1 < element->params_count) | 1107 | if (curr_param+1 < element->params_count) |
1085 | { | 1108 | { |
@@ -1093,31 +1116,31 @@ static int parse_progressbar_tag(struct skin_element* element, | |||
1093 | else /* option needs the next param */ | 1116 | else /* option needs the next param */ |
1094 | return -1; | 1117 | return -1; |
1095 | } | 1118 | } |
1096 | else if (!strcmp(text, "vertical")) | 1119 | else if (pb_op == eVERTICAL) |
1097 | { | 1120 | { |
1098 | pb->horizontal = false; | 1121 | pb->horizontal = false; |
1099 | if (isdefault(get_param(element, 3))) | 1122 | if (isdefault(get_param(element, 3))) |
1100 | pb->height = vp->height - pb->y; | 1123 | pb->height = vp->height - pb->y; |
1101 | } | 1124 | } |
1102 | else if (!strcmp(text, "horizontal")) | 1125 | else if (pb_op == eHORIZONTAL) |
1103 | pb->horizontal = true; | 1126 | pb->horizontal = true; |
1104 | #ifdef HAVE_TOUCHSCREEN | 1127 | #ifdef HAVE_TOUCHSCREEN |
1105 | else if (!strcmp(text, "notouch")) | 1128 | else if (pb_op == eNOTOUCH) |
1106 | suppress_touchregion = true; | 1129 | suppress_touchregion = true; |
1107 | #endif | 1130 | #endif |
1108 | else if (token->type == SKIN_TOKEN_SETTING && !strcmp(text, "setting")) | 1131 | else if (token->type == SKIN_TOKEN_SETTING && pb_op == eSETTING) |
1109 | { | 1132 | { |
1110 | if (curr_param+1 < element->params_count) | 1133 | if (curr_param+1 < element->params_count) |
1111 | { | 1134 | { |
1112 | curr_param++; | 1135 | curr_param++; |
1113 | param++; | 1136 | param++; |
1114 | text = SKINOFFSETTOPTR(skin_buffer, param->data.text); | 1137 | text = SKINOFFSETTOPTR(skin_buffer, param->data.text); |
1115 | #ifndef __PCTOOL__ | 1138 | #ifndef __PCTOOL__ |
1116 | if (find_setting_by_cfgname(text, &pb->setting_id) == NULL) | 1139 | if (find_setting_by_cfgname(text, &pb->setting_id) == NULL) |
1117 | return WPS_ERROR_INVALID_PARAM; | 1140 | return WPS_ERROR_INVALID_PARAM; |
1118 | #endif | 1141 | #endif |
1119 | } | 1142 | } |
1120 | } | 1143 | } |
1121 | else if (curr_param == 4) | 1144 | else if (curr_param == 4) |
1122 | image_filename = text; | 1145 | image_filename = text; |
1123 | 1146 | ||
@@ -1379,28 +1402,32 @@ static int parse_skinvar( struct skin_element *element, | |||
1379 | return 0; | 1402 | return 0; |
1380 | case SKIN_TOKEN_VAR_SET: | 1403 | case SKIN_TOKEN_VAR_SET: |
1381 | { | 1404 | { |
1405 | const char *sv_options[] = {"touch", "set", "inc", "dec", NULL}; | ||
1406 | |||
1382 | struct skin_var_changer *data = skin_buffer_alloc(sizeof(*data)); | 1407 | struct skin_var_changer *data = skin_buffer_alloc(sizeof(*data)); |
1383 | if (!data) | 1408 | if (!data) |
1384 | return WPS_ERROR_INVALID_PARAM; | 1409 | return WPS_ERROR_INVALID_PARAM; |
1385 | data->var = PTRTOSKINOFFSET(skin_buffer, var); | 1410 | data->var = PTRTOSKINOFFSET(skin_buffer, var); |
1386 | char *text_param1 = get_param_text(element, 1); | 1411 | char *text_param1 = get_param_text(element, 1); |
1412 | int sv_op = string_option(text_param1, sv_options, false); | ||
1413 | |||
1387 | if (!isdefault(get_param(element, 2))) | 1414 | if (!isdefault(get_param(element, 2))) |
1388 | data->newval = get_param(element, 2)->data.number; | 1415 | data->newval = get_param(element, 2)->data.number; |
1389 | else if (strcmp(text_param1, "touch")) | 1416 | else if (sv_op == 0) /*touch*/ |
1390 | return WPS_ERROR_INVALID_PARAM; | 1417 | return WPS_ERROR_INVALID_PARAM; |
1391 | data->max = 0; | 1418 | data->max = 0; |
1392 | if (!strcmp(text_param1, "set")) | 1419 | if ((sv_op == 1) /*set*/ |
1393 | data->direct = true; | 1420 | data->direct = true; |
1394 | else if (!strcmp(text_param1, "inc")) | 1421 | else if (sv_op == 2) /*inc*/ |
1395 | { | 1422 | { |
1396 | data->direct = false; | 1423 | data->direct = false; |
1397 | } | 1424 | } |
1398 | else if (!strcmp(text_param1, "dec")) | 1425 | (sv_op == 3) /*dec*/ |
1399 | { | 1426 | { |
1400 | data->direct = false; | 1427 | data->direct = false; |
1401 | data->newval *= -1; | 1428 | data->newval *= -1; |
1402 | } | 1429 | } |
1403 | else if (!strcmp(text_param1, "touch")) | 1430 | else if (sv_op == 0) /*touch*/ |
1404 | { | 1431 | { |
1405 | data->direct = false; | 1432 | data->direct = false; |
1406 | data->newval = 0; | 1433 | data->newval = 0; |
@@ -1679,16 +1706,21 @@ static int parse_touchregion(struct skin_element *element, | |||
1679 | if (region->action == ACTION_NONE) | 1706 | if (region->action == ACTION_NONE) |
1680 | return WPS_ERROR_INVALID_PARAM; | 1707 | return WPS_ERROR_INVALID_PARAM; |
1681 | } | 1708 | } |
1709 | const char *pm_options[] = {"allow_while_locked", "reverse_bar", | ||
1710 | "repeat_press", "long_press", NULL}; | ||
1711 | int pm_op; | ||
1712 | |||
1682 | while (p < element->params_count) | 1713 | while (p < element->params_count) |
1683 | { | 1714 | { |
1684 | char* param = get_param_text(element, p++); | 1715 | char* param = get_param_text(element, p++); |
1685 | if (!strcmp(param, "allow_while_locked")) | 1716 | pm_op = string_option(param, pm_options, false); |
1717 | if (pm_op == 0) | ||
1686 | region->allow_while_locked = true; | 1718 | region->allow_while_locked = true; |
1687 | else if (!strcmp(param, "reverse_bar")) | 1719 | else if (pm_op == 1) |
1688 | region->reverse_bar = true; | 1720 | region->reverse_bar = true; |
1689 | else if (!strcmp(param, "repeat_press")) | 1721 | else if (pm_op == 2) |
1690 | region->press_length = REPEAT; | 1722 | region->press_length = REPEAT; |
1691 | else if (!strcmp(param, "long_press")) | 1723 | else if (pm_op == 3) |
1692 | region->press_length = LONG_PRESS; | 1724 | region->press_length = LONG_PRESS; |
1693 | } | 1725 | } |
1694 | struct skin_token_list *item = new_skin_token_list_item(NULL, region); | 1726 | struct skin_token_list *item = new_skin_token_list_item(NULL, region); |
diff --git a/apps/misc.c b/apps/misc.c index 2668ba714d..350537dc31 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -1384,6 +1384,41 @@ int split_string(char *str, const char split_char, char *vector[], const int vec | |||
1384 | return i; | 1384 | return i; |
1385 | } | 1385 | } |
1386 | 1386 | ||
1387 | /* returns match index from option list | ||
1388 | * returns -1 if option was not found | ||
1389 | * option list is array of char pointers with the final item set to null | ||
1390 | * ex - const char *option[] = { "op_a", "op_b", "op_c", NULL} | ||
1391 | */ | ||
1392 | |||
1393 | int string_option(const char *option, const char *const oplist[], bool ignore_case) | ||
1394 | { | ||
1395 | int i; | ||
1396 | int ifound = -1; | ||
1397 | const char *op; | ||
1398 | if (ignore_case) | ||
1399 | { | ||
1400 | for (i=0; (op=oplist[i]) != NULL; i++) | ||
1401 | { | ||
1402 | if (strcasecmp(op, option) == 0) | ||
1403 | { | ||
1404 | ifound = i; | ||
1405 | break; | ||
1406 | } | ||
1407 | } | ||
1408 | } | ||
1409 | else | ||
1410 | { | ||
1411 | for (i=0; (op=oplist[i]) != NULL; i++) | ||
1412 | { | ||
1413 | if (strcmp(op, option) == 0) | ||
1414 | { | ||
1415 | ifound = i; | ||
1416 | break; | ||
1417 | } | ||
1418 | } | ||
1419 | } | ||
1420 | return ifound; | ||
1421 | } | ||
1387 | 1422 | ||
1388 | /** Open a UTF-8 file and set file descriptor to first byte after BOM. | 1423 | /** Open a UTF-8 file and set file descriptor to first byte after BOM. |
1389 | * If no BOM is present this behaves like open(). | 1424 | * If no BOM is present this behaves like open(). |
diff --git a/apps/misc.h b/apps/misc.h index c4057f4ebc..ed40de3e1f 100644 --- a/apps/misc.h +++ b/apps/misc.h | |||
@@ -123,6 +123,7 @@ extern int show_logo(void); | |||
123 | 123 | ||
124 | int split_string(char *str, const char needle, char *vector[], int vector_length); | 124 | int split_string(char *str, const char needle, char *vector[], int vector_length); |
125 | int open_utf8(const char* pathname, int flags); | 125 | int open_utf8(const char* pathname, int flags); |
126 | int string_option(const char *option, const char *const oplist[], bool ignore_case); | ||
126 | 127 | ||
127 | #ifdef BOOTFILE | 128 | #ifdef BOOTFILE |
128 | #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \ | 129 | #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \ |