+
+
+typedef struct {
+ VikWaypoint *wp;
+ const gchar *name;
+} gpx_waypoint_and_name;
+
+typedef struct {
+ gpx_waypoint_and_name *wps;
+ guint i;
+ guint n_wps;
+} gpx_gather_waypoints_passalong_t;
+
+/* Type to hold name of track and timestamp of first trackpoint */
+typedef struct {
+ time_t first_timestamp;
+ const gchar *name;
+} gpx_track_and_timestamp;
+
+typedef struct {
+ gpx_track_and_timestamp *trks;
+ guint i;
+ guint n_trks;
+} gpx_gather_tracks_passalong_t;
+
+static void gpx_collect_waypoint ( const gchar *name, VikWaypoint *wp, gpx_gather_waypoints_passalong_t *passalong )
+{
+ if ( passalong->i < passalong->n_wps ) {
+ passalong->wps[passalong->i].name = name;
+ passalong->wps[passalong->i].wp = wp;
+ passalong->i++;
+ }
+}
+
+/* Function to collect a track and the first timestamp in the list */
+static void gpx_collect_track (const gchar *name, VikTrack *track, gpx_gather_tracks_passalong_t *passalong)
+{
+ if (passalong->i < passalong->n_trks)
+ {
+ passalong->trks[passalong->i].name = name;
+ if (track && track->trackpoints && track->trackpoints->data)
+ {
+ VikTrackpoint *first_point = (VikTrackpoint *)track->trackpoints->data;
+ passalong->trks[passalong->i].first_timestamp = first_point->timestamp;
+ }
+ else
+ {
+ passalong->trks[passalong->i].first_timestamp = 0;
+ }
+ passalong->i++;
+ }
+}
+
+static int gpx_waypoint_and_name_compar(const void *x, const void *y)
+{
+ gpx_waypoint_and_name *a = (gpx_waypoint_and_name *)x;
+ gpx_waypoint_and_name *b = (gpx_waypoint_and_name *)y;
+ return strcmp(a->name,b->name);
+}
+
+/* Function to compare two tracks by their first timestamp */
+static int gpx_track_and_timestamp_compar(const void *x, const void *y)
+{
+ gpx_track_and_timestamp *a = (gpx_track_and_timestamp *)x;
+ gpx_track_and_timestamp *b = (gpx_track_and_timestamp *)y;
+ if (a->first_timestamp < b->first_timestamp)
+ {
+ return -1;
+ }
+ if (a->first_timestamp > b->first_timestamp)
+ {
+ return 1;
+ }
+ return 0;
+}
+