changeset 454:112f8afa2f04

weather: Improve "nearest" sub-command argument parsing.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 10 Oct 2017 01:32:58 +0300
parents c69368f97c10
children 511f1b28c8d1
files weather.tcl
diffstat 1 files changed, 2 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/weather.tcl	Tue Oct 10 01:32:25 2017 +0300
+++ b/weather.tcl	Tue Oct 10 01:32:58 2017 +0300
@@ -314,16 +314,13 @@
     return 0
   } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} {
     # List stations nearest to given coordinates
-    set qlist [::textutil::split::splitx [join [lrange $rarglist 1 end] " "] {\s*,\s*}]
-    set nlist [lsearch -all -inline -not -exact $qlist ""]
-    if {[llength $nlist] < 2} {
+    set qargs [join [lrange $rarglist 1 end] ""]
+    if {![regexp {^\s*@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} {
       weather_usage $upublic $unick $uchan $weather_msg_usage_nearest
       return 0
     }
 
     # Check argument types
-    set d_lat [lindex $nlist 0]
-    set d_lng [lindex $nlist 1]
     if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} {
       weather_msg $upublic $unick $uchan $weather_msg_usage_nearest_invalid
       return 0