From e96b90a8e48c6e94a075732d7c34e5cd649bf48f Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 10 Mar 2008 13:47:29 +0200 Subject: [PATCH] Formating --- src/gpx.c | 732 +++++++++++++++++++++++++++--------------------------- 1 file changed, 363 insertions(+), 369 deletions(-) diff --git a/src/gpx.c b/src/gpx.c index 405ae26..7b782a2 100644 --- a/src/gpx.c +++ b/src/gpx.c @@ -109,104 +109,102 @@ time_t time1; struct tm time2; time1 = time(NULL); localtime_r(&time1, &time2); -g_snprintf(XML_TZONE, sizeof(XML_TZONE), "%+03ld:%02ld", - (time2.tm_gmtoff / 60 / 60), (time2.tm_gmtoff / 60) % 60); +g_snprintf(XML_TZONE, sizeof(XML_TZONE), "%+03ld:%02ld", (time2.tm_gmtoff / 60 / 60), (time2.tm_gmtoff / 60) % 60); } gboolean write_gpx(Path * path, GnomeVFSHandle * handle) { - Point *curr = NULL; - WayPoint *wcurr = NULL; - gboolean trkseg_break = FALSE; +Point *curr = NULL; +WayPoint *wcurr = NULL; +gboolean trkseg_break = FALSE; - /* Find first non-zero point. */ - for (curr = path->head - 1, wcurr = path->whead; curr++ != path->tail;) { - if (curr->unity) - break; - else if (wcurr && curr == wcurr->point) - wcurr++; - } - - /* Write the header. */ - WRITE_STRING("\n" - "\n" - " \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"); - trkseg_break = FALSE; - } - unit2latlon(curr->unitx, curr->unity, lat, lon); - WRITE_STRING(" head - 1, wcurr = path->whead; curr++ != path->tail;) { + if (curr->unity) + break; + else if (wcurr && curr == wcurr->point) + wcurr++; +} - /* write the elevation */ - if (!isnan(curr->altitude)) { - if (first_sub) { - WRITE_STRING(">\n"); - first_sub = FALSE; - } - WRITE_STRING(" "); - { - g_ascii_formatd(buffer, 80, "%.2f", - curr->altitude); - WRITE_STRING(buffer); - } - WRITE_STRING("\n"); +/* Write the header. */ +WRITE_STRING("\n" + "\n" + " \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"); + trkseg_break = FALSE; + } + unit2latlon(curr->unitx, curr->unity, lat, lon); + WRITE_STRING(" altitude)) { + if (first_sub) { + WRITE_STRING(">\n"); + first_sub = FALSE; } - - /* write the time */ - if (curr->time) { - if (first_sub) { - WRITE_STRING(">\n"); - first_sub = FALSE; - } - WRITE_STRING(" \n"); } + WRITE_STRING("\n"); + } - if (wcurr && curr == wcurr->point) { - if (first_sub) { - WRITE_STRING(">\n"); - first_sub = FALSE; - } - WRITE_STRING(" "); - WRITE_STRING(wcurr->desc); - WRITE_STRING("\n"); - wcurr++; + /* write the time */ + if (curr->time) { + if (first_sub) { + WRITE_STRING(">\n"); + first_sub = FALSE; } + WRITE_STRING(" \n"); + } + + if (wcurr && curr == wcurr->point) { if (first_sub) { - WRITE_STRING("/>\n"); - } else { - WRITE_STRING(" \n"); + WRITE_STRING(">\n"); + first_sub = FALSE; } - } else - trkseg_break = TRUE; - } + WRITE_STRING(" "); + WRITE_STRING(wcurr->desc); + WRITE_STRING("\n"); + wcurr++; + } + if (first_sub) { + WRITE_STRING("/>\n"); + } else { + WRITE_STRING(" \n"); + } + } else + trkseg_break = TRUE; +} - /* Write the footer. */ - WRITE_STRING(" \n" " \n" "\n"); +/* Write the footer. */ +WRITE_STRING(" \n" " \n" "\n"); - return TRUE; +return TRUE; } /** @@ -221,84 +219,82 @@ write_gpx(Path * path, GnomeVFSHandle * handle) static void gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs) { - g_debug("GPX-START: %s (%d)", name, data->state); - switch (data->state) { - case ERROR: - break; - case START: - if (!strcmp((gchar *) name, "gpx")) - data->state = INSIDE_GPX; - else - MACRO_SET_UNKNOWN(); - break; - case INSIDE_GPX: - if (!strcmp((gchar *) name, "trk")) - data->state = INSIDE_PATH; - else if (!strcmp((gchar *) name, "metadata")) - data->state = INSIDE_METADATA; - else - MACRO_SET_UNKNOWN(); - break; - case INSIDE_METADATA: - - break; - case INSIDE_PATH: - if (!strcmp((gchar *) name, "trkseg")) { - data->state = INSIDE_PATH_SEGMENT; - data->at_least_one_trkpt = FALSE; - } else - MACRO_SET_UNKNOWN(); - break; - case INSIDE_PATH_SEGMENT: - if (!strcmp((gchar *) name, "trkpt")) { - const xmlChar **curr_attr; - gchar *error_check; - gdouble lat = 0.f, lon = 0.f; - gboolean has_lat, has_lon; - has_lat = FALSE; - has_lon = FALSE; - for (curr_attr = attrs; *curr_attr != NULL;) { - const gchar *attr_name = *curr_attr++; - const gchar *attr_val = *curr_attr++; - if (!strcmp(attr_name, "lat")) { - lat = g_ascii_strtod(attr_val, &error_check); - if (error_check != attr_val) - has_lat = TRUE; - } else if (!strcmp(attr_name, "lon")) { - lon = g_ascii_strtod(attr_val, &error_check); - if (error_check != attr_val) - has_lon = TRUE; - } +g_debug("GPX-START: %s (%d)", name, data->state); +switch (data->state) { +case ERROR: +break; +case START: + if (!strcmp((gchar *) name, "gpx")) + data->state = INSIDE_GPX; + else + MACRO_SET_UNKNOWN(); +break; +case INSIDE_GPX: + if (!strcmp((gchar *) name, "trk")) + data->state = INSIDE_PATH; + else if (!strcmp((gchar *) name, "metadata")) + data->state = INSIDE_METADATA; + else + MACRO_SET_UNKNOWN(); +break; +case INSIDE_METADATA: +break; +case INSIDE_PATH: + if (!strcmp((gchar *) name, "trkseg")) { + data->state = INSIDE_PATH_SEGMENT; + data->at_least_one_trkpt = FALSE; + } else + MACRO_SET_UNKNOWN(); +break; +case INSIDE_PATH_SEGMENT: + if (!strcmp((gchar *) name, "trkpt")) { + const xmlChar **curr_attr; + gchar *error_check; + gdouble lat = 0.f, lon = 0.f; + gboolean has_lat, has_lon; + has_lat = FALSE; + has_lon = FALSE; + for (curr_attr = attrs; *curr_attr != NULL;) { + const gchar *attr_name = *curr_attr++; + const gchar *attr_val = *curr_attr++; + if (!strcmp(attr_name, "lat")) { + lat = g_ascii_strtod(attr_val, &error_check); + if (error_check != attr_val) + has_lat = TRUE; + } else if (!strcmp(attr_name, "lon")) { + lon = g_ascii_strtod(attr_val, &error_check); + if (error_check != attr_val) + has_lon = TRUE; } - if (has_lat && has_lon) { - MACRO_PATH_INCREMENT_TAIL(data->path); - latlon2unit(lat, lon, data->path.tail->unitx, data->path.tail->unity); - data->path.tail->time = 0; - data->path.tail->altitude = NAN; - data->state = INSIDE_PATH_POINT; - } else - data->state = ERROR; + } + if (has_lat && has_lon) { + MACRO_PATH_INCREMENT_TAIL(data->path); + latlon2unit(lat, lon, data->path.tail->unitx, data->path.tail->unity); + data->path.tail->time = 0; + data->path.tail->altitude = NAN; + data->state = INSIDE_PATH_POINT; } else - MACRO_SET_UNKNOWN(); - break; - case INSIDE_PATH_POINT: - if (!strcmp((gchar *) name, "time")) - data->state = INSIDE_PATH_POINT_TIME; - else if (!strcmp((gchar *) name, "ele")) - 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; - case UNKNOWN: - data->unknown_depth++; - break; - default: - ; - } + data->state = ERROR; + } else + MACRO_SET_UNKNOWN(); +break; +case INSIDE_PATH_POINT: + if (!strcmp((gchar *) name, "time")) + data->state = INSIDE_PATH_POINT_TIME; + else if (!strcmp((gchar *) name, "ele")) + 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; +case UNKNOWN: + data->unknown_depth++; +break; +default: ; +} } @@ -308,136 +304,135 @@ 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); +g_debug("GPX-END: %s", name); - switch (data->state) { - case ERROR: +switch (data->state) { +case ERROR: - break; - case START: +break; +case START: + data->state = ERROR; +break; +case INSIDE_GPX: + if (!strcmp((gchar *) name, "gpx")) + data->state = FINISH; + else data->state = ERROR; - break; - case INSIDE_GPX: - if (!strcmp((gchar *) name, "gpx")) - data->state = FINISH; - else - data->state = ERROR; - break; - case INSIDE_METADATA: - if (!strcmp((gchar *) name, "metadata")) - data->state = INSIDE_GPX; - break; - case INSIDE_PATH: - if (!strcmp((gchar *) name, "trk")) - data->state = INSIDE_GPX; - else - data->state = ERROR; - break; - case INSIDE_PATH_SEGMENT: - if (!strcmp((gchar *) name, "trkseg")) { - if (data->at_least_one_trkpt) { - MACRO_PATH_INCREMENT_TAIL(data->path); - *data->path.tail = _point_null; - } - data->state = INSIDE_PATH; - } else - data->state = ERROR; - break; - case INSIDE_PATH_POINT: - if (!strcmp((gchar *) name, "trkpt")) { - data->state = INSIDE_PATH_SEGMENT; - data->at_least_one_trkpt = TRUE; - } else +break; +case INSIDE_METADATA: + if (!strcmp((gchar *) name, "metadata")) + data->state = INSIDE_GPX; +break; +case INSIDE_PATH: + if (!strcmp((gchar *) name, "trk")) + data->state = INSIDE_GPX; + else + data->state = ERROR; +break; +case INSIDE_PATH_SEGMENT: + if (!strcmp((gchar *) name, "trkseg")) { + if (data->at_least_one_trkpt) { + MACRO_PATH_INCREMENT_TAIL(data->path); + *data->path.tail = _point_null; + } + data->state = INSIDE_PATH; + } else + data->state = ERROR; +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; +case INSIDE_PATH_POINT_ELE: + if (!strcmp((gchar *) name, "ele")) { + gchar *error_check; + data->path.tail->altitude = g_ascii_strtod(data->chars->str, &error_check); + if (error_check == data->chars->str) + data->path.tail->altitude = NAN; + data->state = INSIDE_PATH_POINT; + g_string_free(data->chars, TRUE); + data->chars = g_string_new(""); + } else + data->state = ERROR; +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))) + /* Failed to parse dateTime format. */ data->state = ERROR; - break; - case INSIDE_PATH_POINT_ELE: - if (!strcmp((gchar *) name, "ele")) { + else { + /* Parse was successful. Now we have to parse timezone. + * From here on, if there is an error, I just assume local + * timezone. Yes, this is not proper XML, but I don't + * care. */ gchar *error_check; - data->path.tail->altitude = g_ascii_strtod(data->chars->str, &error_check); - if (error_check == data->chars->str) - data->path.tail->altitude = NAN; - data->state = INSIDE_PATH_POINT; - g_string_free(data->chars, TRUE); - data->chars = g_string_new(""); - } else - data->state = ERROR; - 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))) - /* Failed to parse dateTime format. */ - data->state = ERROR; - else { - /* Parse was successful. Now we have to parse timezone. - * From here on, if there is an error, I just assume local - * timezone. Yes, this is not proper XML, but I don't - * care. */ - gchar *error_check; - - /* First, set time in "local" time zone. */ - data->path.tail->time = (mktime(&time)); - - /* Now, skip inconsequential characters */ - 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. */ - 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) == ':') { - /* Parse of hours worked. Check minutes. */ - 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)); - } + + /* First, set time in "local" time zone. */ + data->path.tail->time = (mktime(&time)); + + /* Now, skip inconsequential characters */ + 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. */ + 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) == ':') { + /* Parse of hours worked. Check minutes. */ + 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)); } } } - /* Successfully parsed dateTime. */ - data->state = INSIDE_PATH_POINT; } - - g_string_free(data->chars, TRUE); - data->chars = g_string_new(""); - } else - data->state = ERROR; - 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->chars = g_string_new(""); + /* Successfully parsed dateTime. */ data->state = INSIDE_PATH_POINT; - } else - data->state = ERROR; - break; - case INSIDE_PATH_POINT_NAME: - /* Just ignore these for now */ - g_string_free(data->chars, FALSE); - data->chars = g_string_new(""); - data->state = INSIDE_PATH_POINT; - break; - case UNKNOWN: - if (!--data->unknown_depth) - data->state = data->prev_state; - else - data->state = ERROR; - break; - default: - ; - } + } + + g_string_free(data->chars, TRUE); + data->chars = g_string_new(""); + } else + data->state = ERROR; +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->chars = g_string_new(""); + data->state = INSIDE_PATH_POINT; + } else + data->state = ERROR; +break; +case INSIDE_PATH_POINT_NAME: + /* Just ignore these for now */ + g_string_free(data->chars, FALSE); + data->chars = g_string_new(""); + data->state = INSIDE_PATH_POINT; +break; +case UNKNOWN: + if (!--data->unknown_depth) + data->state = data->prev_state; + else + data->state = ERROR; +break; +default: ; +} } @@ -447,23 +442,23 @@ gpx_end_element(SaxData * data, const xmlChar * name) static void gpx_chars(SaxData * data, const xmlChar * ch, int len) { - guint i; +guint i; - switch (data->state) { - case ERROR: - case UNKNOWN: - break; - 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]); - g_debug("GPXC: %s", data->chars->str); - break; - default: - break; - } +switch (data->state) { +case ERROR: +case UNKNOWN: + break; +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]); + g_debug("GPXC: %s", data->chars->str); + break; +default: +break; +} } @@ -474,7 +469,7 @@ gpx_chars(SaxData * data, const xmlChar * ch, int len) static xmlEntityPtr gpx_get_entity(SaxData * data, const xmlChar * name) { - return xmlGetPredefinedEntity(name); +return xmlGetPredefinedEntity(name); } /** @@ -483,95 +478,94 @@ gpx_get_entity(SaxData * data, const xmlChar * name) static void gpx_error(SaxData * data, const gchar * msg, ...) { - data->state = ERROR; +data->state = ERROR; } gboolean parse_gpx(Path * to_replace, gchar * buffer, gint size, gint policy_old) { - SaxData data; - xmlSAXHandler sax_handler; - - MACRO_PATH_INIT(data.path); - data.state = START; - data.chars = g_string_new(""); - - memset(&sax_handler, 0, sizeof(sax_handler)); - sax_handler.characters = (charactersSAXFunc) gpx_chars; - sax_handler.startElement = (startElementSAXFunc) gpx_start_element; - sax_handler.endElement = (endElementSAXFunc) gpx_end_element; - sax_handler.entityDecl = (entityDeclSAXFunc) gpx_get_entity; - sax_handler.warning = (warningSAXFunc) gpx_error; - sax_handler.error = (errorSAXFunc) gpx_error; - sax_handler.fatalError = (fatalErrorSAXFunc) gpx_error; - - xmlSAXUserParseMemory(&sax_handler, &data, buffer, size); - g_string_free(data.chars, TRUE); - - if (data.state != FINISH) { - g_debug("GPX: Parser stopped in error state %d", data.state); - return FALSE; - } +SaxData data; +xmlSAXHandler sax_handler; + +MACRO_PATH_INIT(data.path); +data.state = START; +data.chars = g_string_new(""); + +memset(&sax_handler, 0, sizeof(sax_handler)); +sax_handler.characters = (charactersSAXFunc) gpx_chars; +sax_handler.startElement = (startElementSAXFunc) gpx_start_element; +sax_handler.endElement = (endElementSAXFunc) gpx_end_element; +sax_handler.entityDecl = (entityDeclSAXFunc) gpx_get_entity; +sax_handler.warning = (warningSAXFunc) gpx_error; +sax_handler.error = (errorSAXFunc) gpx_error; +sax_handler.fatalError = (fatalErrorSAXFunc) gpx_error; + +xmlSAXUserParseMemory(&sax_handler, &data, buffer, size); +g_string_free(data.chars, TRUE); + +if (data.state != FINISH) { + g_debug("GPX: Parser stopped in error state %d", data.state); + return FALSE; +} - if (policy_old && to_replace->head != to_replace->tail) { - Point *src_first; - Path *src, *dest; +if (policy_old && to_replace->head != to_replace->tail) { + Point *src_first; + Path *src, *dest; - if (policy_old > 0) { - /* Append to current path. Make sure last path point is zero. */ - if (to_replace->tail->unity != 0) { - MACRO_PATH_INCREMENT_TAIL((*to_replace)); - *to_replace->tail = _point_null; - } - src = &data.path; - dest = to_replace; - } else { - /* Prepend to current route. */ - src = to_replace; - dest = &data.path; + if (policy_old > 0) { + /* Append to current path. Make sure last path point is zero. */ + if (to_replace->tail->unity != 0) { + MACRO_PATH_INCREMENT_TAIL((*to_replace)); + *to_replace->tail = _point_null; } + src = &data.path; + dest = to_replace; + } else { + /* Prepend to current route. */ + src = to_replace; + dest = &data.path; + } - /* Find src_first non-zero point. */ - for (src_first = src->head - 1; src_first++ != src->tail;) - if (src_first->unity) - break; - - /* Append route points from src to dest. */ - if (src->tail >= src_first) { - WayPoint *curr; - guint num_dest_points = dest->tail - dest->head + 1; - guint num_src_points = src->tail - src_first + 1; + /* Find src_first non-zero point. */ + for (src_first = src->head - 1; src_first++ != src->tail;) + if (src_first->unity) + break; - /* Adjust dest->tail to be able to fit src route data - * plus room for more route data. */ - path_resize(dest, num_dest_points + num_src_points); + /* Append route points from src to dest. */ + if (src->tail >= src_first) { + WayPoint *curr; + guint num_dest_points = dest->tail - dest->head + 1; + guint num_src_points = src->tail - src_first + 1; - memcpy(dest->tail + 1, src_first, num_src_points * sizeof(Point)); + /* Adjust dest->tail to be able to fit src route data + * plus room for more route data. */ + path_resize(dest, num_dest_points + num_src_points); - dest->tail += num_src_points; + memcpy(dest->tail + 1, src_first, num_src_points * sizeof(Point)); - /* Append waypoints from src to dest->. */ - 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->desc = curr->desc; - } + dest->tail += num_src_points; + /* Append waypoints from src to dest->. */ + 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->desc = curr->desc; } - - /* Kill old route - don't use MACRO_PATH_FREE(), because that - * would free the string desc's that we just moved to data.route. */ - g_free(src->head); - g_free(src->whead); - if (policy_old < 0) - (*to_replace) = *dest; - } else { - MACRO_PATH_FREE((*to_replace)); - /* Overwrite with data.route. */ - (*to_replace) = data.path; - path_resize(to_replace, to_replace->tail - to_replace->head + 1); - path_wresize(to_replace, to_replace->wtail - to_replace->whead + 1); } - return TRUE; + /* Kill old route - don't use MACRO_PATH_FREE(), because that + * would free the string desc's that we just moved to data.route. */ + g_free(src->head); + g_free(src->whead); + if (policy_old < 0) + (*to_replace) = *dest; +} else { + MACRO_PATH_FREE((*to_replace)); + /* Overwrite with data.route. */ + (*to_replace) = data.path; + path_resize(to_replace, to_replace->tail - to_replace->head + 1); + path_wresize(to_replace, to_replace->wtail - to_replace->whead + 1); +} + +return TRUE; } -- 2.39.5