Skip to content

Commit

Permalink
Sets valid content for the name and desc fields
Browse files Browse the repository at this point in the history
Affects GPX output. Replaces placeholder values. The basename of
the input file is used for the name field, such that:

    /path/to/foo.bar.baz.gps

becomes:

    foo.bar.baz
  • Loading branch information
asnodgrass committed May 15, 2017
1 parent 95967dc commit 2e6fec6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cmd/gpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"os"
"fmt"
"log"
"path"
"strings"
"time"
"io"
"io/ioutil"
Expand Down Expand Up @@ -69,7 +71,8 @@ var gpxCmd = &cobra.Command{
trkpts = append(trkpts, recordToTrackPoint(rec))
}

gpxData := generateGPX(trkpts)
name := filenamePrefix(inFile)
gpxData := generateGPX(trkpts, name)
if outFile != "" {
ioutil.WriteFile(outFile, gpxData, 0644)
} else {
Expand Down Expand Up @@ -154,14 +157,14 @@ func recordToTrackPoint(rec v1000.Record) (trackPoint) {
return tp
}

func generateGPX(trkpts []trackPoint) []byte {
func generateGPX(trkpts []trackPoint, name string) []byte {
trksegs := make([]trackSegment, 1)
trksegs[0].TrackPoints = trkpts

trk := track{
TrackSegments: trksegs,
Name: "please fix me",
Description: "and this too",
Name: name,
Description: "V1000 gps tracklog data",
}

bounds := gpxBounds{
Expand Down Expand Up @@ -244,3 +247,13 @@ func maximumLongitude(trkpts []trackPoint) latLong {
}
return high
}

func filenamePrefix(filename string) string {
f := path.Base(filename)
pos := strings.LastIndex(f, ".")
if pos == -1 {
return f
} else {
return f[:pos]
}
}

0 comments on commit 2e6fec6

Please sign in to comment.