From a05ccf8883d5348621631967515bc99d45bdc150 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Sat, 15 Mar 2008 14:43:33 +0200 Subject: [PATCH] GPX output fixes. Add metadata section, only time for now. Don't waste space with blanks in the xml file. --- src/gpx.c | 71 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/src/gpx.c b/src/gpx.c index 7b782a2..4b17050 100644 --- a/src/gpx.c +++ b/src/gpx.c @@ -100,7 +100,7 @@ struct _SaxData { GString *chars; }; -gchar XML_TZONE[7]; +static gchar XML_TZONE[7]; void gpx_init(void) @@ -113,11 +113,12 @@ g_snprintf(XML_TZONE, sizeof(XML_TZONE), "%+03ld:%02ld", (time2.tm_gmtoff / 60 / } 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;) { @@ -129,24 +130,34 @@ for (curr = path->head - 1, wcurr = path->whead; curr++ != path->tail;) { /* Write the header. */ WRITE_STRING("\n" - "\n" - " \n" " \n"); + "\n"); + +/* Write any metadata */ +WRITE_STRING("\n"); + +WRITE_STRING("\n"); + +WRITE_STRING("\n"); + +/* Write track(s) and waypoint(s) */ +WRITE_STRING("\n\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(" \n" - " \n"); + WRITE_STRING("\n\n"); trkseg_break = FALSE; } unit2latlon(curr->unitx, curr->unity, lat, lon); - WRITE_STRING(" tail;) { WRITE_STRING(">\n"); first_sub = FALSE; } - WRITE_STRING(" "); - { - g_ascii_formatd(buffer, 80, "%.2f", curr->altitude); - WRITE_STRING(buffer); - } + WRITE_STRING(""); + g_ascii_formatd(buffer, sizeof(buffer), "%.2f", curr->altitude); + WRITE_STRING(buffer); WRITE_STRING("\n"); } @@ -174,35 +183,37 @@ for (curr--; curr++ != path->tail;) { WRITE_STRING(">\n"); first_sub = FALSE; } - WRITE_STRING(" \n"); + WRITE_STRING("\n"); } } else trkseg_break = TRUE; } /* Write the footer. */ -WRITE_STRING(" \n" " \n" "\n"); +WRITE_STRING("\n\n\n"); return TRUE; } @@ -217,7 +228,7 @@ 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) { @@ -440,7 +451,7 @@ default: ; * 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; @@ -467,7 +478,7 @@ break; * special here. */ static xmlEntityPtr -gpx_get_entity(SaxData * data, const xmlChar * name) +gpx_get_entity(SaxData *data, const xmlChar *name) { return xmlGetPredefinedEntity(name); } @@ -476,13 +487,19 @@ 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; -- 2.39.5