GString *chars;
};
-gchar XML_TZONE[7];
+static gchar XML_TZONE[7];
void
gpx_init(void)
}
gboolean
-write_gpx(Path * path, GnomeVFSHandle * handle)
+write_gpx(Path *path, GnomeVFSHandle *handle)
{
Point *curr = NULL;
WayPoint *wcurr = NULL;
gboolean trkseg_break = FALSE;
+gchar buffer[80];
/* Find first non-zero point. */
for (curr = path->head - 1, wcurr = path->whead; curr++ != path->tail;) {
/* Write the header. */
WRITE_STRING("<?xml version=\"1.0\"?>\n"
- "<gpx version=\"1.0\" creator=\"mapper\" "
- "xmlns=\"http://www.topografix.com/GPX/1/0\">\n"
- " <trk>\n" " <trkseg>\n");
+ "<gpx version=\"1.0\" creator=\"mapper\" xmlns=\"http://www.topografix.com/GPX/1/0\">\n");
+
+/* Write any metadata */
+WRITE_STRING("<metadata>\n");
+
+WRITE_STRING("<time>");
+strftime(buffer, sizeof(buffer), XML_DATE_FORMAT, localtime(time(NULL)));
+WRITE_STRING(buffer);
+WRITE_STRING(XML_TZONE);
+WRITE_STRING("</time>\n");
+
+WRITE_STRING("</metadata>\n");
+
+/* Write track(s) and waypoint(s) */
+WRITE_STRING("<trk>\n<trkseg>\n");
/* Curr points to first non-zero point. */
for (curr--; curr++ != path->tail;) {
gdouble lat, lon;
if (curr->unity) {
- gchar buffer[80];
gboolean first_sub = TRUE;
if (trkseg_break) {
/* First trkpt of the segment - write trkseg header. */
- WRITE_STRING(" </trkseg>\n"
- " <trkseg>\n");
+ WRITE_STRING("</trkseg>\n<trkseg>\n");
trkseg_break = FALSE;
}
unit2latlon(curr->unitx, curr->unity, lat, lon);
- WRITE_STRING(" <trkpt lat=\"");
+ WRITE_STRING("<trkpt lat=\"");
g_ascii_formatd(buffer, sizeof(buffer), "%.06f", lat);
WRITE_STRING(buffer);
WRITE_STRING("\" lon=\"");
WRITE_STRING(">\n");
first_sub = FALSE;
}
- WRITE_STRING(" <ele>");
- {
- g_ascii_formatd(buffer, 80, "%.2f", curr->altitude);
- WRITE_STRING(buffer);
- }
+ WRITE_STRING("<ele>");
+ g_ascii_formatd(buffer, sizeof(buffer), "%.2f", curr->altitude);
+ WRITE_STRING(buffer);
WRITE_STRING("</ele>\n");
}
WRITE_STRING(">\n");
first_sub = FALSE;
}
- WRITE_STRING(" <time>");
- strftime(buffer, 80, XML_DATE_FORMAT,
- localtime(&curr->time));
+ WRITE_STRING("<time>");
+ strftime(buffer, sizeof(buffer), XML_DATE_FORMAT, localtime(&curr->time));
WRITE_STRING(buffer);
WRITE_STRING(XML_TZONE);
WRITE_STRING("</time>\n");
}
if (wcurr && curr == wcurr->point) {
+ gchar *desc;
if (first_sub) {
WRITE_STRING(">\n");
first_sub = FALSE;
}
- WRITE_STRING(" <desc>");
- WRITE_STRING(wcurr->desc);
- WRITE_STRING("</desc>\n");
+ if (wcurr->desc) {
+ desc=g_markup_printf_escaped("<desc>%s</desc>\n", wcurr->desc);
+ WRITE_STRING(desc);
+ g_free(desc);
+ }
wcurr++;
}
if (first_sub) {
WRITE_STRING("/>\n");
} else {
- WRITE_STRING(" </trkpt>\n");
+ WRITE_STRING("</trkpt>\n");
}
} else
trkseg_break = TRUE;
}
/* Write the footer. */
-WRITE_STRING(" </trkseg>\n" " </trk>\n" "</gpx>\n");
+WRITE_STRING("</trkseg>\n</trk>\n</gpx>\n");
return TRUE;
}
g_debug("GPX: unknown tag"); }
static void
-gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs)
+gpx_start_element(SaxData *data, const xmlChar *name, const xmlChar **attrs)
{
g_debug("GPX-START: %s (%d)", name, data->state);
switch (data->state) {
* Handle char data in the parsing of a GPX file.
*/
static void
-gpx_chars(SaxData * data, const xmlChar * ch, int len)
+gpx_chars(SaxData *data, const xmlChar *ch, int len)
{
guint i;
* special here.
*/
static xmlEntityPtr
-gpx_get_entity(SaxData * data, const xmlChar * name)
+gpx_get_entity(SaxData *data, const xmlChar *name)
{
return xmlGetPredefinedEntity(name);
}
* Handle an error in the parsing of a GPX file.
*/
static void
-gpx_error(SaxData * data, const gchar * msg, ...)
+gpx_error(SaxData *data, const gchar *msg, ...)
{
+va_list args;
+
+va_start(args, msg);
+g_logv("GPX", G_LOG_LEVEL_WARNING, msg, args);
+va_end(args);
+
data->state = ERROR;
}
gboolean
-parse_gpx(Path * to_replace, gchar * buffer, gint size, gint policy_old)
+parse_gpx(Path *to_replace, gchar *buffer, gint size, gint policy_old)
{
SaxData data;
xmlSAXHandler sax_handler;