Skip to content

Commit

Permalink
Merge pull request GPSBabel#35 from tsteven4/master
Browse files Browse the repository at this point in the history
eliminate some thrashing between QStrings and char strings in trackfi…
  • Loading branch information
tsteven4 committed Feb 20, 2016
2 parents 7e34c09 + 19d998c commit df669ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions testo.d/track.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ rm -f ${TMPDIR}/trackfilter*
gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,split,title="LOG-%Y%m%d" -o gpx -F ${TMPDIR}/trackfilter.gpx
compare ${REFERENCE}/track/trackfilter.gpx ${TMPDIR}/trackfilter.gpx

gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,split,title="LOG" -o gpx -F ${TMPDIR}/trackfilter1.gpx
compare ${REFERENCE}/track/trackfilter.gpx ${TMPDIR}/trackfilter1.gpx

gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,split,sdistance=0.1k -o gpx -F ${TMPDIR}/trackfilter2.gpx
compare ${REFERENCE}/track/trackfilter-sdistance.gpx ${TMPDIR}/trackfilter2.gpx

Expand Down
32 changes: 17 additions & 15 deletions trackfilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,30 +371,32 @@ trackfilter_fill_track_list_cb(const route_head* track) /* callback for track_d
static void
trackfilter_split_init_rte_name(route_head* track, const QDateTime dt)
{
char tbuff[128];
struct tm tm;
QString datetimestring;

time_t time = dt.toUTC().toTime_t();
tm = *gmtime(&time);

(opt_interval != 0) ?
strftime(tbuff, sizeof(tbuff), "%Y%m%d%H%M%S", &tm) :
strftime(tbuff, sizeof(tbuff), "%Y%m%d", &tm);
if (opt_interval != 0) {
datetimestring = dt.toUTC().toString("yyyyMMddhhmmss");
} else {
datetimestring = dt.toUTC().toString("yyyyMMdd");
}

// TODO: this should be q QString.
char buff[128];
if ((opt_title != NULL) && (strlen(opt_title) > 0)) {
if (strchr(opt_title, '%') != NULL) {
// Uggh. strftime format exposed to user.
char buff[128];

time_t time = dt.toUTC().toTime_t();
struct tm tm = *gmtime(&time);

strftime(buff, sizeof(buff), opt_title, &tm);
track->rte_name = buff;
} else {
snprintf(buff, sizeof(buff), "%s-%s", opt_title, tbuff);
track->rte_name = QString("%1-%2").arg(opt_title).arg(datetimestring);
}
} else if (!track->rte_name.isEmpty()) {
snprintf(buff, sizeof(buff) - 1, "%s-%s", CSTRc(track->rte_name), tbuff);
track->rte_name = QString("%1-%2").arg(track->rte_name).arg(datetimestring);
} else {
strncpy(buff, tbuff, sizeof(buff));
track->rte_name = datetimestring;
}
track->rte_name = buff;
}

static void
Expand Down Expand Up @@ -954,7 +956,7 @@ trackfilter_seg2trk(void)
dest->rte_num = src->rte_num;
/* name in the form TRACKNAME #n */
if (!src->rte_name.isEmpty()) {
dest->rte_name = QString().sprintf("%s #%d", CSTRc(src->rte_name), ++trk_seg_num);
dest->rte_name = QString("%1 #%2").arg(src->rte_name).arg(++trk_seg_num);
}

/* Insert after original track or after last newly
Expand Down

0 comments on commit df669ed

Please sign in to comment.