summaryrefslogtreecommitdiff
path: root/apps/misc.c
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2010-07-29 12:37:48 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2010-07-29 12:37:48 +0000
commit2d31d77a8ba231cb03ec35863c4c4ce2024f6509 (patch)
treeb85ca1bede3e83695619064ee9a323f0a8da1865 /apps/misc.c
parente436483b66a931fef6436e9cd3e69eb2b3ff1f7b (diff)
downloadrockbox-2d31d77a8ba231cb03ec35863c4c4ce2024f6509.tar.gz
rockbox-2d31d77a8ba231cb03ec35863c4c4ce2024f6509.zip
FS#11470 - new skin code, finally svn uses the new parser from the theme editor. This means that a skin that passes the editor WILL pass svn and checkwps (unless the target runs out of skin buffer or something.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27613 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/misc.c')
-rw-r--r--apps/misc.c135
1 files changed, 8 insertions, 127 deletions
diff --git a/apps/misc.c b/apps/misc.c
index bae8dfbd07..c378133ab2 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -937,142 +937,23 @@ int hex_to_rgb(const char* hex, int* color)
937#endif /* HAVE_LCD_COLOR */ 937#endif /* HAVE_LCD_COLOR */
938 938
939#ifdef HAVE_LCD_BITMAP 939#ifdef HAVE_LCD_BITMAP
940/* A simplified scanf - used (at time of writing) by wps parsing functions.
941
942 fmt - char array specifying the format of each list option. Valid values
943 are: d - int
944 s - string (sets pointer to string, without copying)
945 c - hex colour (RGB888 - e.g. ff00ff)
946 g - greyscale "colour" (0-3)
947 set_vals - if not NULL 1 is set in the bitplace if the item was read OK
948 0 if not read.
949 first item is LSB, (max 32 items! )
950 Stops parseing if an item is invalid unless the item == '-'
951 sep - list separator (e.g. ',' or '|')
952 str - string to parse, must be terminated by 0 or sep
953 ... - pointers to store the parsed values
954
955 return value - pointer to char after parsed data, 0 if there was an error.
956
957*/
958
959/* '0'-'3' are ASCII 0x30 to 0x33 */ 940/* '0'-'3' are ASCII 0x30 to 0x33 */
960#define is0123(x) (((x) & 0xfc) == 0x30) 941#define is0123(x) (((x) & 0xfc) == 0x30)
961 942
962const char* parse_list(const char *fmt, uint32_t *set_vals, 943bool parse_color(char *text, int *value)
963 const char sep, const char* str, ...)
964{ 944{
965 va_list ap; 945 (void)text; (void)value; /* silence warnings on mono bitmap */
966 const char* p = str, *f = fmt;
967 const char** s;
968 int* d;
969 bool set, is_negative;
970 int i=0;
971
972 va_start(ap, str);
973 if (set_vals)
974 *set_vals = 0;
975 while (*fmt)
976 {
977 /* Check for separator, if we're not at the start */
978 if (f != fmt)
979 {
980 if (*p != sep)
981 goto err;
982 p++;
983 }
984 set = false;
985 switch (*fmt++)
986 {
987 case 's': /* string - return a pointer to it (not a copy) */
988 s = va_arg(ap, const char **);
989
990 *s = p;
991 while (*p && *p != sep && *p != ')')
992 p++;
993 set = (s[0][0]!='-') && (s[0][1]!=sep && s[0][1]!=')') ;
994 break;
995
996 case 'd': /* int */
997 is_negative = false;
998 d = va_arg(ap, int*);
999
1000 if (*p == '-' && isdigit(*(p+1)))
1001 {
1002 is_negative = true;
1003 p++;
1004 }
1005 if (!isdigit(*p))
1006 {
1007 if (!set_vals || *p != '-')
1008 goto err;
1009 p++;
1010 }
1011 else
1012 {
1013 *d = *p++ - '0';
1014 while (isdigit(*p))
1015 *d = (*d * 10) + (*p++ - '0');
1016 set = true;
1017 if (is_negative)
1018 *d *= -1;
1019 }
1020
1021 break;
1022
1023#ifdef HAVE_LCD_COLOR 946#ifdef HAVE_LCD_COLOR
1024 case 'c': /* colour (rrggbb - e.g. f3c1a8) */ 947 if (hex_to_rgb(text, value) < 0)
1025 d = va_arg(ap, int*); 948 return false;
1026
1027 if (hex_to_rgb(p, d) < 0)
1028 {
1029 if (!set_vals || *p != '-')
1030 goto err;
1031 p++;
1032 }
1033 else
1034 {
1035 p += 6;
1036 set = true;
1037 }
1038
1039 break;
1040#endif 949#endif
1041 950
1042#if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2) 951#if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1043 case 'g': /* greyscale colour (0-3) */ 952 if (!is0123(*text))
1044 d = va_arg(ap, int*); 953 return false;
1045 954 *value = *text - '0';
1046 if (!is0123(*p))
1047 {
1048 if (!set_vals || *p != '-')
1049 goto err;
1050 p++;
1051 }
1052 else
1053 {
1054 *d = *p++ - '0';
1055 set = true;
1056 }
1057
1058 break;
1059#endif 955#endif
1060 956 return true;
1061 default: /* Unknown format type */
1062 goto err;
1063 break;
1064 }
1065 if (set_vals && set)
1066 *set_vals |= BIT_N(i);
1067 i++;
1068 }
1069
1070 va_end(ap);
1071 return p;
1072
1073err:
1074 va_end(ap);
1075 return NULL;
1076} 957}
1077 958
1078/* only used in USB HID and set_time screen */ 959/* only used in USB HID and set_time screen */