summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-09-01 07:36:21 +0000
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-09-01 07:36:21 +0000
commit443af83790d9778d8286a2436699edb11d546c98 (patch)
treecf3e7096f6e0931b3cc671a62c088dc17bb47e8d
parenta98f3ea3ff49f186db4e9f2ac51a89338a37b843 (diff)
downloadnavit-443af83790d9778d8286a2436699edb11d546c98.tar.gz
Add:osd/core:Added OSD time string in nicer formatting from ticket #612
| Thanks mvglasow git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3543 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/osd/core/osd_core.c73
-rw-r--r--navit/util.c30
2 files changed, 92 insertions, 11 deletions
diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c
index 1f1bf278b..979f4a534 100644
--- a/navit/osd/core/osd_core.c
+++ b/navit/osd/core/osd_core.c
@@ -761,6 +761,15 @@ struct osd_text {
};
+/**
+ * @brief Format a text attribute
+ *
+ * Returns the formatted current value of an attribute as a string
+ *
+ * @param attr Pointer to an attr structure specifying the attribute to be formatted
+ * @param format Pointer to a string specifying how to format the attribute. Allowed format strings depend on the attribute; this member can be NULL.
+ * @returns Pointer to a string containing the formatted value
+ */
static char *
osd_text_format_attr(struct attr *attr, char *format)
{
@@ -868,6 +877,43 @@ osd_text_format_attr(struct attr *attr, char *format)
g_free(tmp);
return ret;
}
+ case attr_position_time_iso8601:
+ if ((!format) || (!strcmp(format,"iso8601")))
+ {
+ break;
+ }
+ else
+ {
+ if (strstr(format, "local;") == format)
+ {
+ textt = iso8601_to_secs(attr->u.str);
+ memcpy ((void *) &tm, (void *) localtime(&textt), sizeof(tm));
+ strftime(buffer, sizeof(buffer), (char *)(format + 6), &tm);
+ }
+ else if ((sscanf(format, "%*c%2d:%2d;", &(text_tm.tm_hour), &(text_tm.tm_min)) == 2) && (strchr("+-", format[0])))
+ {
+ if (strchr("-", format[0]))
+ {
+ textt = iso8601_to_secs(attr->u.str) - text_tm.tm_hour * 3600 - text_tm.tm_min * 60;
+ }
+ else
+ {
+ textt = iso8601_to_secs(attr->u.str) + text_tm.tm_hour * 3600 + text_tm.tm_min * 60;
+ }
+ memcpy ((void *) &tm, (void *) gmtime(&textt), sizeof(tm));
+ strftime(buffer, sizeof(buffer), &format[strcspn(format, ";") + 1], &tm);
+ }
+ else
+ {
+ sscanf(attr->u.str, "%4d-%2d-%2dT%2d:%2d:%2d", &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday), &(tm.tm_hour), &(tm.tm_min), &(tm.tm_sec));
+ // the tm structure definition is kinda weird and needs some extra voodoo
+ tm.tm_year-=1900; tm.tm_mon--;
+ // get weekday and day of the year
+ mktime(&tm);
+ strftime(buffer, sizeof(buffer), format, &tm);
+ }
+ return g_strdup(buffer);
+ }
default:
break;
}
@@ -875,12 +921,12 @@ osd_text_format_attr(struct attr *attr, char *format)
}
/**
- * * Parse a string of the form key.subkey or key[index].subkey into its components, where subkey can itself have its own index and further subkeys
- * *
- * * @param in string to parse (will be modified by the function); upon returning this pointer will point to a string containing key
- * * @param index pointer to an address that will receive a pointer to a string containing index or a null pointer if key does not have an index
- * * @returns a pointer to a string containing subkey, i.e. everything following the first period; if no subkey was found, the return value is a pointer to an empty string; if errors are encountered (index with missing closed bracket or passing a null pointer as index argument when an index was encountered), the return value is NULL
- * */
+ * Parse a string of the form key.subkey or key[index].subkey into its components, where subkey can itself have its own index and further subkeys
+ *
+ * @param in String to parse (the part before subkey will be modified by the function); upon returning this pointer will point to a string containing key
+ * @param index Pointer to an address that will receive a pointer to a string containing index or a null pointer if key does not have an index
+ * @returns If the function succeeds, a pointer to a string containing subkey, i.e. everything following the first period, or a pointer to an empty string if there is nothing left to parse. If the function fails(index with missing closed bracket or passing a null pointer as index argument when an index was encountered), the return value is NULL
+ */
static char *
osd_text_split(char *in, char **index)
{
@@ -1139,6 +1185,12 @@ osd_text_draw(struct osd_text *this, struct navit *navit, struct vehicle *v)
}
+/**
+ * @brief Create a new osd_text_item and insert it into a linked list
+ *
+ * @param parent Pointer to the preceding osd_text_item structure in the list. If NULL, the new osd_text_item becomes the root element of a new list.
+ * @returns A pointer to the new osd_text_item element.
+ */
struct osd_text_item *
oti_new(struct osd_text_item * parent)
{
@@ -1156,6 +1208,15 @@ oti_new(struct osd_text_item * parent)
return this;
}
+/**
+ * @brief Prepare a text type OSD element
+ *
+ * Parses the label string (as specified in the XML file) for a text type OSD element into attributes and static text.
+ *
+ * @param this Pointer to an osd_text structure representing the OSD element. The items member of this structure will receive a pointer to a list of osd_text_item structures.
+ * @param nav Pointer to a navit structure
+ * @returns nothing
+ */
static void
osd_text_prepare(struct osd_text *this, struct navit *nav)
{
diff --git a/navit/util.c b/navit/util.c
index da9c4e036..87bb515fa 100644
--- a/navit/util.c
+++ b/navit/util.c
@@ -155,12 +155,20 @@ char *stristr(const char *String, const char *Pattern)
# define EOVERFLOW E2BIG
#endif
-/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
- NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
- NULL), pointing to *N characters of space. It is realloc'ed as
- necessary. Returns the number of characters read (not including
- the null terminator), or -1 on error or EOF. */
+/**
+ * Read the part of a file up to a delimiter to a string.
+ * <p>
+ * Read up to (and including) a DELIMITER from FP into *LINEPTR (and
+ NUL-terminate it).
+ * @param lineptr Pointer to a pointer returned from malloc (or
+ NULL), pointing to a buffer. It is realloc'ed as
+ necessary and will receive the data read.
+ * @param n Size of the buffer.
+ *
+ * @return Number of characters read (not including
+ the null terminator), or -1 on error or EOF.
+*/
int
getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
{
@@ -260,6 +268,13 @@ char * newSysString(const char *toconvert)
#endif
#endif
+/**
+ * Convert an ISO 8601-style time string into epoch time.
+ *
+ * @param iso8601 Pointer to a string containing the time in ISO 8601 format.
+ *
+ * @return An unsigned integer representing the number of seconds elapsed since January 1, 1970, 00:00:00 UTC.
+ */
unsigned int
iso8601_to_secs(char *iso8601)
{
@@ -287,6 +302,11 @@ iso8601_to_secs(char *iso8601)
return ((d*24+val[3])*60+val[4])*60+val[5];
}
+/**
+ * Output local system time in ISO 8601 format.
+ *
+ * @return Pointer to a string containing the time in ISO 8601 format
+ */
char *
current_to_iso8601(void)
{