comparison MakeWaypoints.kt @ 4:45be2d1d3213

Remove trailing whitespace, add warp notes.
author David Barts <n5jrn@me.com>
date Wed, 25 Aug 2021 06:33:31 -0700
parents ab4d4434c37f
children a725bd48bc0b
comparison
equal deleted inserted replaced
3:ab4d4434c37f 4:45be2d1d3213
1 /* 1 /*
2 * Make waypoints. In Kotlin, because the JVM has a uniquely non-sucky 2 * Make waypoints. In Kotlin, because the JVM has a uniquely non-sucky
3 * way to write XML. 3 * way to write XML.
4 */ 4 */
5 5
6 import javax.xml.stream.* 6 import javax.xml.stream.*
7 import java.io.FileOutputStream 7 import java.io.FileOutputStream
8 8
9 private const val MYNAME = "MakeWaypoints" 9 private const val MYNAME = "MakeWaypoints"
10 private const val CHARSET = "UTF-8" 10 private const val CHARSET = "UTF-8"
12 fun main(args: Array<String>): Unit { 12 fun main(args: Array<String>): Unit {
13 if (args.size != 1) { 13 if (args.size != 1) {
14 System.err.println("${MYNAME}: expecting a single file name") 14 System.err.println("${MYNAME}: expecting a single file name")
15 System.exit(2) 15 System.exit(2)
16 } 16 }
17 17
18 println("Enter waypoints below, end with empty line.") 18 println("Enter waypoints below, end with empty line.")
19 println() 19 println()
20 20
21 val outName = args[0] 21 val outName = args[0]
22 val invalid = "${MYNAME}: invalid entry, please try again" 22 val invalid = "${MYNAME}: invalid entry, please try again"
23 FileOutputStream(outName).use stream@{ 23 FileOutputStream(outName).use stream@{
24 XMLOutputFactory.newInstance().createXMLStreamWriter(it, CHARSET).run { 24 XMLOutputFactory.newInstance().createXMLStreamWriter(it, CHARSET).run {
25 writeStartDocument(CHARSET, "1.0") 25 writeStartDocument(CHARSET, "1.0")
26 writeStartElement("gpx") 26 writeStartElement("gpx")
27 writeAttribute("creator", "MakeWaypoints") 27 writeAttribute("creator", "MakeWaypoints")
28 writeAttribute("version", "1.1") 28 writeAttribute("version", "1.1")
29 writeDefaultNamespace("http://www.topografix.com/GPX/1/1") 29 writeDefaultNamespace("http://www.topografix.com/GPX/1/1")
30 30
31 while (true) { 31 while (true) {
32 print("Longitude, latitude: ") 32 print("Longitude, latitude: ")
33 val longLat = readLine() 33 val longLat = readLine()
34 if (longLat.isNullOrEmpty()) { 34 if (longLat.isNullOrEmpty()) {
35 writeEndDocument() 35 writeEndDocument()
62 writeEndElement() 62 writeEndElement()
63 } 63 }
64 } 64 }
65 } 65 }
66 } 66 }
67
68