Mercurial > hg > egg-tcls
comparison weather.tcl @ 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 |
comparison
equal
deleted
inserted
replaced
453:c69368f97c10 | 454:112f8afa2f04 |
---|---|
312 set res [join $result " ; "] | 312 set res [join $result " ; "] |
313 weather_msg $upublic $unick $uchan $weather_msg_stations [list $res] | 313 weather_msg $upublic $unick $uchan $weather_msg_stations [list $res] |
314 return 0 | 314 return 0 |
315 } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} { | 315 } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} { |
316 # List stations nearest to given coordinates | 316 # List stations nearest to given coordinates |
317 set qlist [::textutil::split::splitx [join [lrange $rarglist 1 end] " "] {\s*,\s*}] | 317 set qargs [join [lrange $rarglist 1 end] ""] |
318 set nlist [lsearch -all -inline -not -exact $qlist ""] | 318 if {![regexp {^\s*@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} { |
319 if {[llength $nlist] < 2} { | |
320 weather_usage $upublic $unick $uchan $weather_msg_usage_nearest | 319 weather_usage $upublic $unick $uchan $weather_msg_usage_nearest |
321 return 0 | 320 return 0 |
322 } | 321 } |
323 | 322 |
324 # Check argument types | 323 # Check argument types |
325 set d_lat [lindex $nlist 0] | |
326 set d_lng [lindex $nlist 1] | |
327 if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} { | 324 if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} { |
328 weather_msg $upublic $unick $uchan $weather_msg_usage_nearest_invalid | 325 weather_msg $upublic $unick $uchan $weather_msg_usage_nearest_invalid |
329 return 0 | 326 return 0 |
330 } | 327 } |
331 | 328 |