summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-04-10 13:37:08 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-04-10 13:37:08 +0000
commit536c5d9e744afe894aa221bb5ce23e175a3f54e5 (patch)
tree76ae73120d14aca8fcf250ae27816a42c61091a9 /apps
parentaf7780e0b3f27a574b007be6ac7a273d14f6b76a (diff)
downloadrockbox-536c5d9e744afe894aa221bb5ce23e175a3f54e5.tar.gz
rockbox-536c5d9e744afe894aa221bb5ce23e175a3f54e5.zip
RTC tags for the WPS: Accept FS#6998 and FS#7001 by Alexander Levin with changes by me. CUSTOM WPS FILES NEED TO BE UPDATED !
The RTC tags are now atomic, i.e. instead of using one tag with the format (e.g. %cd m yc), we use several separate tags, one for each value (e.g. %cd %cm %cy). Also, %cP produces an uppercase AM/PM indicator and %cp a lowercase one, which is the opposite from what they did before. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13093 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/gui/gwps-common.c55
-rw-r--r--apps/gui/gwps.h1
-rw-r--r--apps/gui/wps_debug.c40
-rw-r--r--apps/gui/wps_parser.c76
4 files changed, 83 insertions, 89 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 52ef65c141..4605b3461b 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -762,6 +762,39 @@ static char *get_token_value(struct gui_wps *gwps,
if (!id3)
return NULL;
+#if CONFIG_RTC
+ struct tm* tm = NULL;
+
+ /* if the token is an RTC one, update the time and do the necessary checks */
+
+ if (token->type >= WPS_TOKEN_RTC_DAY_OF_MONTH
+ && token->type <= WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN)
+ {
+ tm = get_time();
+
+ if (tm->tm_mday > 31 || tm->tm_mday < 1)
+ return NULL;
+
+ if (tm->tm_hour > 23)
+ return NULL;
+
+ if (tm->tm_mon > 11 || tm->tm_mon < 0)
+ return NULL;
+
+ if (tm->tm_min > 59 || tm->tm_min < 0)
+ return NULL;
+
+ if (tm->tm_sec > 59 || tm->tm_sec < 0)
+ return NULL;
+
+ if (tm->tm_year > 199 || tm->tm_year < 100)
+ return NULL;
+
+ if (tm->tm_wday > 6 || tm->tm_wday < 0)
+ return NULL;
+ }
+#endif
+
int limit = 1;
if (intval)
{
@@ -769,10 +802,6 @@ static char *get_token_value(struct gui_wps *gwps,
*intval = -1;
}
-#if CONFIG_RTC
- static struct tm* tm;
-#endif
-
switch (token->type)
{
case WPS_TOKEN_CHARACTER:
@@ -1039,63 +1068,50 @@ static char *get_token_value(struct gui_wps *gwps,
return buf;
#if CONFIG_RTC
- case WPS_TOKEN_RTC:
- tm = get_time();
- return NULL;
-
case WPS_TOKEN_RTC_DAY_OF_MONTH:
/* d: day of month (01..31) */
- if (tm->tm_mday > 31 || tm->tm_mday < 1) return NULL;
snprintf(buf, buf_size, "%02d", tm->tm_mday);
return buf;
case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
/* e: day of month, blank padded ( 1..31) */
- if (tm->tm_mday > 31 || tm->tm_mday < 1) return NULL;
snprintf(buf, buf_size, "%2d", tm->tm_mday);
return buf;
case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
/* H: hour (00..23) */
- if (tm->tm_hour > 23) return NULL;
snprintf(buf, buf_size, "%02d", tm->tm_hour);
return buf;
case WPS_TOKEN_RTC_HOUR_24:
/* k: hour ( 0..23) */
- if (tm->tm_hour > 23) return NULL;
snprintf(buf, buf_size, "%2d", tm->tm_hour);
return buf;
case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
/* I: hour (01..12) */
- if (tm->tm_hour > 23) return NULL;
snprintf(buf, buf_size, "%02d",
(tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12);
return buf;
case WPS_TOKEN_RTC_HOUR_12:
/* l: hour ( 1..12) */
- if (tm->tm_hour > 23) return NULL;
snprintf(buf, buf_size, "%2d",
(tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12);
return buf;
case WPS_TOKEN_RTC_MONTH:
/* m: month (01..12) */
- if (tm->tm_mon > 11 || tm->tm_mon < 0) return NULL;
snprintf(buf, buf_size, "%02d", tm->tm_mon + 1);
return buf;
case WPS_TOKEN_RTC_MINUTE:
/* M: minute (00..59) */
- if (tm->tm_min > 59 || tm->tm_min < 0) return NULL;
snprintf(buf, buf_size, "%02d", tm->tm_min);
return buf;
case WPS_TOKEN_RTC_SECOND:
/* S: second (00..59) */
- if (tm->tm_sec > 59 || tm->tm_sec < 0) return NULL;
snprintf(buf, buf_size, "%02d", tm->tm_sec);
return buf;
@@ -1106,7 +1122,6 @@ static char *get_token_value(struct gui_wps *gwps,
case WPS_TOKEN_RTC_YEAR_4_DIGITS:
/* Y: year (1970...) */
- if (tm->tm_year > 199 || tm->tm_year < 100) return NULL;
snprintf(buf, buf_size, "%04d", tm->tm_year + 1900);
return buf;
@@ -1122,25 +1137,21 @@ static char *get_token_value(struct gui_wps *gwps,
case WPS_TOKEN_RTC_WEEKDAY_NAME:
/* a: abbreviated weekday name (Sun..Sat) */
- if (tm->tm_wday > 6 || tm->tm_wday < 0) return NULL;
snprintf(buf, buf_size, "%s",str(dayname[tm->tm_wday]));
return buf;
case WPS_TOKEN_RTC_MONTH_NAME:
/* b: abbreviated month name (Jan..Dec) */
- if (tm->tm_mon > 11 || tm->tm_mon < 0) return NULL;
snprintf(buf, buf_size, "%s",str(monthname[tm->tm_mon]));
return buf;
case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
/* u: day of week (1..7); 1 is Monday */
- if (tm->tm_wday > 6 || tm->tm_wday < 0) return NULL;
snprintf(buf, buf_size, "%1d", tm->tm_wday + 1);
return buf;
case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
/* w: day of week (0..6); 0 is Sunday */
- if (tm->tm_wday > 6 || tm->tm_wday < 0) return NULL;
snprintf(buf, buf_size, "%1d", tm->tm_wday);
return buf;
#endif
diff --git a/apps/gui/gwps.h b/apps/gui/gwps.h
index f012b3b304..e897413037 100644
--- a/apps/gui/gwps.h
+++ b/apps/gui/gwps.h
@@ -129,7 +129,6 @@ enum wps_token_type {
#if CONFIG_RTC
/* Time */
- WPS_TOKEN_RTC,
WPS_TOKEN_RTC_DAY_OF_MONTH,
WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED,
WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED,
diff --git a/apps/gui/wps_debug.c b/apps/gui/wps_debug.c
index 0e2b151551..4a8153d591 100644
--- a/apps/gui/wps_debug.c
+++ b/apps/gui/wps_debug.c
@@ -135,30 +135,56 @@ void dump_wps_tokens(struct wps_data *data)
break;
#if CONFIG_RTC
- case WPS_TOKEN_RTC:
- snprintf(buf, sizeof(buf), "real-time clock",
- token->value.c);
- break;
-
case WPS_TOKEN_RTC_DAY_OF_MONTH:
+ snprintf(buf, sizeof(buf), "rtc: day of month (01..31)");
+ break;
case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
+ snprintf(buf, sizeof(buf), "rtc: day of month, blank padded ( 1..31)");
+ break;
case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
+ snprintf(buf, sizeof(buf), "rtc: hour (00..23)");
+ break;
case WPS_TOKEN_RTC_HOUR_24:
+ snprintf(buf, sizeof(buf), "rtc: hour ( 0..23)");
+ break;
case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
+ snprintf(buf, sizeof(buf), "rtc: hour (01..12)");
+ break;
case WPS_TOKEN_RTC_HOUR_12:
+ snprintf(buf, sizeof(buf), "rtc: hour ( 1..12)");
+ break;
case WPS_TOKEN_RTC_MONTH:
+ snprintf(buf, sizeof(buf), "rtc: month (01..12)");
+ break;
case WPS_TOKEN_RTC_MINUTE:
+ snprintf(buf, sizeof(buf), "rtc: minute (00..59)");
+ break;
case WPS_TOKEN_RTC_SECOND:
+ snprintf(buf, sizeof(buf), "rtc: second (00..59)");
+ break;
case WPS_TOKEN_RTC_YEAR_2_DIGITS:
+ snprintf(buf, sizeof(buf), "rtc: last two digits of year (00..99)");
+ break;
case WPS_TOKEN_RTC_YEAR_4_DIGITS:
+ snprintf(buf, sizeof(buf), "rtc: year (1970...)");
+ break;
case WPS_TOKEN_RTC_AM_PM_UPPER:
+ snprintf(buf, sizeof(buf), "rtc: upper case AM or PM indicator");
+ break;
case WPS_TOKEN_RTC_AM_PM_LOWER:
+ snprintf(buf, sizeof(buf), "rtc: lower case am or pm indicator");
+ break;
case WPS_TOKEN_RTC_WEEKDAY_NAME:
+ snprintf(buf, sizeof(buf), "rtc: abbreviated weekday name (Sun..Sat)");
+ break;
case WPS_TOKEN_RTC_MONTH_NAME:
+ snprintf(buf, sizeof(buf), "rtc: abbreviated month name (Jan..Dec)");
+ break;
case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
+ snprintf(buf, sizeof(buf), "rtc: day of week (1..7); 1 is Monday");
+ break;
case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
- snprintf(buf, sizeof(buf), "real-time clock tag: %c",
- token->value.c);
+ snprintf(buf, sizeof(buf), "rtc: day of week (0..6); 0 is Sunday");
break;
#endif
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index 8d917cdd1d..b25fe24ba2 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -108,33 +108,6 @@ static int parse_image_display(const char *wps_bufptr,
static int parse_image_load(const char *wps_bufptr,
struct wps_token *token, struct wps_data *wps_data);
#endif /*HAVE_LCD_BITMAP */
-#if CONFIG_RTC
-static int parse_rtc_format(const char *wps_bufptr,
- struct wps_token *token, struct wps_data *wps_data);
-
-/* RTC tokens array */
-static const struct wps_tag rtc_tags[] = {
- { WPS_TOKEN_RTC_DAY_OF_MONTH, "d", 0, NULL },
- { WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED, "e", 0, NULL },
- { WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED, "H", 0, NULL },
- { WPS_TOKEN_RTC_HOUR_24, "k", 0, NULL },
- { WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED, "I", 0, NULL },
- { WPS_TOKEN_RTC_HOUR_12, "l", 0, NULL },
- { WPS_TOKEN_RTC_MONTH, "m", 0, NULL },
- { WPS_TOKEN_RTC_MINUTE, "M", 0, NULL },
- { WPS_TOKEN_RTC_SECOND, "S", 0, NULL },
- { WPS_TOKEN_RTC_YEAR_2_DIGITS, "y", 0, NULL },
- { WPS_TOKEN_RTC_YEAR_4_DIGITS, "Y", 0, NULL },
- { WPS_TOKEN_RTC_AM_PM_UPPER, "p", 0, NULL },
- { WPS_TOKEN_RTC_AM_PM_LOWER, "P", 0, NULL },
- { WPS_TOKEN_RTC_WEEKDAY_NAME, "a", 0, NULL },
- { WPS_TOKEN_RTC_MONTH_NAME, "b", 0, NULL },
- { WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON, "u", 0, NULL },
- { WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN, "w", 0, NULL },
- { WPS_TOKEN_CHARACTER, "", 0, NULL }
- /* the array MUST end with an empty string (first char is \0) */
-};
-#endif
/* array of available tags - those with more characters have to go first
(e.g. "xl" and "xd" before "x"). It needs to end with the unknown token. */
@@ -156,7 +129,23 @@ static const struct wps_tag all_tags[] = {
#endif
#if CONFIG_RTC
- { WPS_TOKEN_RTC, "c", WPS_REFRESH_DYNAMIC, parse_rtc_format },
+ { WPS_TOKEN_RTC_DAY_OF_MONTH, "cd", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED, "ce", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED, "cH", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_HOUR_24, "ck", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED, "cI", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_HOUR_12, "cl", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_MONTH, "cm", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_MINUTE, "cM", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_SECOND, "cS", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_YEAR_2_DIGITS, "cy", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_YEAR_4_DIGITS, "cY", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_AM_PM_UPPER, "cP", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_AM_PM_LOWER, "cp", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_WEEKDAY_NAME, "ca", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_MONTH_NAME, "cb", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON, "cu", WPS_REFRESH_DYNAMIC, NULL },
+ { WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN, "cw", WPS_REFRESH_DYNAMIC, NULL },
#endif
/* current file */
@@ -286,37 +275,6 @@ static void wps_start_new_subline(struct wps_data *data) {
data->lines[data->num_lines].num_sublines++;
}
-#if CONFIG_RTC
-static int parse_rtc_format(const char *wps_bufptr,
- struct wps_token *token,
- struct wps_data *wps_data)
-{
- int skip = 0, i;
- (void)token; /* kill the warning */
-
- /* RTC tag format ends with a c or a newline */
- while (wps_bufptr && *wps_bufptr != 'c' && *wps_bufptr != '\n')
- {
- /* find what format char we have */
- i = 0;
- while (*(rtc_tags[i].name) && *wps_bufptr != *(rtc_tags[i].name))
- i++;
-
- wps_data->num_tokens++;
- wps_data->tokens[wps_data->num_tokens].type = rtc_tags[i].type;
- wps_data->tokens[wps_data->num_tokens].value.c = *wps_bufptr;
- skip++;
- wps_bufptr++;
- }
-
- /* eat the unwanted c at the end of the format */
- if (*wps_bufptr == 'c')
- skip++;
-
- return skip;
-}
-#endif
-
#ifdef HAVE_LCD_BITMAP
static int parse_statusbar_enable(const char *wps_bufptr,