]> err.no Git - mapper/commitdiff
Add some debug output to gpx parser. Begin to handle more gpx tags.
authorKaj-Michael Lang <milang@onion.tal.org>
Mon, 18 Feb 2008 11:43:35 +0000 (13:43 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Mon, 18 Feb 2008 11:43:35 +0000 (13:43 +0200)
src/gpx.c

index 2a9a5f37f339049017af981702604a6fc5832e8c..ad78c188141a63829139479c391a8163edd848b1 100644 (file)
--- a/src/gpx.c
+++ b/src/gpx.c
@@ -82,6 +82,7 @@ typedef enum {
        INSIDE_PATH_POINT_ELE,
        INSIDE_PATH_POINT_TIME,
        INSIDE_PATH_POINT_DESC,
+       INSIDE_PATH_POINT_NAME,
        FINISH,
        UNKNOWN,
        ERROR,
@@ -214,12 +215,12 @@ write_gpx(Path * path, GnomeVFSHandle * handle)
     data->prev_state = data->state; \
     data->state = UNKNOWN; \
     data->unknown_depth = 1; \
-}
+       g_debug("GPX: unknown tag"); }
 
 static void
 gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs)
 {
-
+       g_debug("GPX-START: %s", name);
        switch (data->state) {
        case ERROR:
                break;
@@ -281,7 +282,8 @@ gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs)
                        data->state = INSIDE_PATH_POINT_ELE;
                else if (!strcmp((gchar *) name, "desc"))
                        data->state = INSIDE_PATH_POINT_DESC;
-
+               else if (!strcmp((gchar *) name, "name"))
+                       data->state = INSIDE_PATH_POINT_NAME;
                else
                        MACRO_SET_UNKNOWN();
                break;
@@ -300,25 +302,27 @@ gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs)
 static void 
 gpx_end_element(SaxData * data, const xmlChar * name)
 {
+       g_debug("GPX-END: %s", name);
 
        switch (data->state) {
        case ERROR:
-               break;
+
+       break;
        case START:
                data->state = ERROR;
-               break;
+       break;
        case INSIDE_GPX:
                if (!strcmp((gchar *) name, "gpx"))
                        data->state = FINISH;
                else
                        data->state = ERROR;
-               break;
+       break;
        case INSIDE_PATH:
                if (!strcmp((gchar *) name, "trk"))
                        data->state = INSIDE_GPX;
                else
                        data->state = ERROR;
-               break;
+       break;
        case INSIDE_PATH_SEGMENT:
                if (!strcmp((gchar *) name, "trkseg")) {
                        if (data->at_least_one_trkpt) {
@@ -328,14 +332,14 @@ gpx_end_element(SaxData * data, const xmlChar * name)
                        data->state = INSIDE_PATH;
                } else
                        data->state = ERROR;
-               break;
+       break;
        case INSIDE_PATH_POINT:
                if (!strcmp((gchar *) name, "trkpt")) {
                        data->state = INSIDE_PATH_SEGMENT;
                        data->at_least_one_trkpt = TRUE;
                } else
                        data->state = ERROR;
-               break;
+       break;
        case INSIDE_PATH_POINT_ELE:
                if (!strcmp((gchar *) name, "ele")) {
                        gchar *error_check;
@@ -347,14 +351,13 @@ gpx_end_element(SaxData * data, const xmlChar * name)
                        data->chars = g_string_new("");
                } else
                        data->state = ERROR;
-               break;
+       break;
        case INSIDE_PATH_POINT_TIME:
                if (!strcmp((gchar *) name, "time")) {
                        struct tm time;
                        gchar *ptr;
 
-                       if (NULL == (ptr = strptime(data->chars->str,
-                                                   XML_DATE_FORMAT, &time)))
+                       if (NULL == (ptr = strptime(data->chars->str, XML_DATE_FORMAT, &time)))
                                /* Failed to parse dateTime format. */
                                data->state = ERROR;
                        else {
@@ -368,36 +371,24 @@ gpx_end_element(SaxData * data, const xmlChar * name)
                                data->path.tail->time = (mktime(&time));
 
                                /* Now, skip inconsequential characters */
-                               while (*ptr && *ptr != 'Z' && *ptr != '-'
-                                      && *ptr != '+')
+                               while (*ptr && *ptr != 'Z' && *ptr != '-' && *ptr != '+')
                                        ptr++;
 
                                /* Check if we ran to the end of the string. */
                                if (*ptr) {
                                        /* Next character is either 'Z', '-', or '+' */
                                        if (*ptr == 'Z')
-                                               /* Zulu (UTC) time. Undo the local time zone's
-                                                * offset. */
+                                               /* Zulu (UTC) time. Undo the local time zone's offset. */
                                                data->path.tail->time += time.tm_gmtoff;
                                        else {
                                                /* Not Zulu (UTC). Must parse hours and minutes. */
-                                               gint offhours =
-                                                   strtol(ptr, &error_check,
-                                                          10);
-                                               if (error_check != ptr
-                                                   && *(ptr =
-                                                        error_check) == ':') {
+                                               gint offhours = strtol(ptr, &error_check, 10);
+                                               if (error_check != ptr && *(ptr = error_check) == ':') {
                                                        /* Parse of hours worked. Check minutes. */
-                                                       gint offmins =
-                                                           strtol(ptr + 1,
-                                                                  &error_check,
-                                                                  10);
-                                                       if (error_check !=
-                                                           (ptr + 1)) {
+                                                       gint offmins = strtol(ptr + 1, &error_check, 10);
+                                                       if (error_check != (ptr + 1)) {
                                                                /* Parse of minutes worked. Calculate. */
-                                                               data->path.tail->time +=
-                                                                   (time.tm_gmtoff -
-                                                                    (offhours * 60 * 60 + offmins * 60));
+                                                               data->path.tail->time += (time.tm_gmtoff - (offhours * 60 * 60 + offmins * 60));
                                                        }
                                                }
                                        }
@@ -410,25 +401,27 @@ gpx_end_element(SaxData * data, const xmlChar * name)
                        data->chars = g_string_new("");
                } else
                        data->state = ERROR;
-               break;
+       break;
        case INSIDE_PATH_POINT_DESC:
                /* only parse description for routes */
                if (!strcmp((gchar *) name, "desc")) {
                        MACRO_PATH_INCREMENT_WTAIL(data->path);
                        data->path.wtail->point = data->path.tail;
-                       data->path.wtail->desc
-                           = g_string_free(data->chars, FALSE);
+                       data->path.wtail->desc = g_string_free(data->chars, FALSE);
                        data->chars = g_string_new("");
                        data->state = INSIDE_PATH_POINT;
                } else
                        data->state = ERROR;
-               break;
+       break;
+       case INSIDE_PATH_POINT_NAME:
+
+       break;
        case UNKNOWN:
                if (!--data->unknown_depth)
                        data->state = data->prev_state;
                else
                        data->state = ERROR;
-               break;
+       break;
        default:
                ;
        }
@@ -450,9 +443,10 @@ gpx_chars(SaxData * data, const xmlChar * ch, int len)
        case INSIDE_PATH_POINT_ELE:
        case INSIDE_PATH_POINT_TIME:
        case INSIDE_PATH_POINT_DESC:
+       case INSIDE_PATH_POINT_NAME:
                for (i = 0; i < len; i++)
                        data->chars = g_string_append_c(data->chars, ch[i]);
-               vprintf("%s\n", data->chars->str);
+               g_debug("GPXC: %s", data->chars->str);
                break;
        default:
                break;
@@ -538,18 +532,14 @@ parse_gpx(Path * to_replace, gchar * buffer, gint size, gint policy_old)
                         * plus room for more route data. */
                        path_resize(dest, num_dest_points + num_src_points);
 
-                       memcpy(dest->tail + 1, src_first,
-                              num_src_points * sizeof(Point));
+                       memcpy(dest->tail + 1, src_first, num_src_points * sizeof(Point));
 
                        dest->tail += num_src_points;
 
                        /* Append waypoints from src to dest->. */
-                       path_wresize(dest, (dest->wtail - dest->whead)
-                                    + (src->wtail - src->whead) + 2);
+                       path_wresize(dest, (dest->wtail - dest->whead) + (src->wtail - src->whead) + 2);
                        for (curr = src->whead - 1; curr++ != src->wtail;) {
-                               (++(dest->wtail))->point =
-                                   dest->head + num_dest_points +
-                                   (curr->point - src_first);
+                               (++(dest->wtail))->point = dest->head + num_dest_points + (curr->point - src_first);
                                dest->wtail->desc = curr->desc;
                        }