pfile = gnome_vfs_uri_make_full_from_relative(config_dir, file);
if (GNOME_VFS_OK == gnome_vfs_read_entire_file(pfile, &size, &bytes))
- gpx_parse(path, bytes, size, 0); /* 0 to replace track. */
+ gpx_parse(path, bytes, size, GPX_PATH_NEW);
g_free(pfile);
}
data->state = ERROR;
}
+/**
+ * Parse a buffer of GPX data.
+ *
+ * XXX: Add support for parsing directly from file if the file is local.
+ *
+ */
gboolean
-gpx_parse(Path *to_replace, gchar *buffer, gint size, gint policy_old)
+gpx_parse(Path *path, gchar *buffer, gint size, gpx_path_policy policy)
{
SaxData data;
xmlSAXHandler sax_handler;
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);
+ g_warning("GPX: Parser stopped in error state %d", data.state);
return FALSE;
}
-if (policy_old && to_replace->head != to_replace->tail) {
+switch (policy) {
+case GPX_PATH_APPEND:
+case GPX_PATH_PREPEND:
+ {
Point *src_first;
Path *src, *dest;
- if (policy_old > 0) {
+ if (policy==GPX_PATH_APPEND) {
/* 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;
+ if (path->tail->unity != 0) {
+ MACRO_PATH_INCREMENT_TAIL((*path));
+ *path->tail = _point_null;
}
src = &data.path;
- dest = to_replace;
+ dest = path;
} else {
/* Prepend to current route. */
- src = to_replace;
+ src = path;
dest = &data.path;
}
* 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));
+ if (policy==GPX_PATH_PREPEND)
+ (*path) = *dest;
+ }
+break;
+case GPX_PATH_NEW:
/* 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);
+ MACRO_PATH_FREE((*path));
+ (*path) = data.path;
+ path_resize(path, path->tail - path->head + 1);
+ path_wresize(path, path->wtail - path->whead + 1);
+break;
+default:
+ g_assert_not_reached();
+break;
}
return TRUE;
#include <libgnomevfs/gnome-vfs.h>
#include "path.h"
+typedef enum {
+ GPX_PATH_PREPEND=-1,
+ GPX_PATH_NEW=0,
+ GPX_PATH_APPEND=1,
+} gpx_path_policy;
+
void gpx_init(void);
gboolean gpx_write(Path *path, GnomeVFSHandle *handle);
-gboolean gpx_parse(Path *to_replace, gchar *buffer, gint size, gint policy_old);
+gboolean gpx_parse(Path *to_replace, gchar *buffer, gint size, gpx_path_policy policy);
#endif
if (file_open_get_contents(_route_dir_uri, &buffer, &size)) {
/* If auto is enabled, append the route, otherwise replace it. */
- if (gpx_parse(_route, buffer, size, _autoroute_data.enabled ? 0 : 1)) {
+ if (gpx_parse(_route, buffer, size, _autoroute_data.enabled ? GPX_PATH_APPEND : GPX_PATH_NEW)) {
route_cancel_autoroute(FALSE);
MACRO_BANNER_SHOW_INFO(_window, _("Route Opened"));
if (strncmp(rdl_data.bytes, "<?xml", strlen("<?xml"))) {
/* Not an XML document - must be bad locations. */
- popup_error(dialog,
- _("Could not generate directions. Make sure your "
- "source and destination are valid."));
+ popup_error(dialog, _("Could not generate directions. Make sure your source and destination are valid."));
g_free(rdl_data.bytes);
/* Let them try again. */
}
/* Else, if GPS is enabled, replace the route, otherwise append it. */
else if (gpx_parse(_route, rdl_data.bytes, rdl_data.bytes_read,
- (gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON(oti.rad_use_gps)) ? 0 : 1))) {
+ (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oti.rad_use_gps)) ? GPX_PATH_NEW : GPX_PATH_APPEND))) {
GtkTreeIter iter;
/* Find the nearest route point, if we're connected. */
map_force_redraw();
- if (gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON(oti.chk_auto))) {
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oti.chk_auto))) {
/* Kick off a timeout to start the first update. */
_autoroute_data.dest = gnome_vfs_escape_string(to);
_autoroute_data.enabled = TRUE;
gboolean r = FALSE;
if (file_open_get_contents(&_track_file_uri, &buffer, &size)) {
- if (gpx_parse(_track, buffer, size, -1)) {
+ if (gpx_parse(_track, buffer, size, GPX_PATH_NEW)) {
map_force_redraw();
MACRO_BANNER_SHOW_INFO(_window, _("Track Opened"));
r = TRUE;