From a3e622dcc14fab97218a81444355aea6734b4004 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Dec 2009 11:43:13 +0000 Subject: [PATCH] where-vessels: WIP argument parsing; library load changes --- .gitignore | 2 -- yarrg/dictionary-manager | 2 ++ yarrg/where-vessels | 41 ++++++++++++++++++++++++++++++---------- yarrg/yarrglib.tcl | 8 ++++++++ 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 yarrg/yarrglib.tcl diff --git a/.gitignore b/.gitignore index a580b97..9beb60b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,3 @@ yarrg/_*.* yarrg/OCEAN-*.db yarrg/Writer.lock yarrg/DATA - -yarrg/pkgIndex.tcl diff --git a/yarrg/dictionary-manager b/yarrg/dictionary-manager index 2231266..83c7e54 100755 --- a/yarrg/dictionary-manager +++ b/yarrg/dictionary-manager @@ -31,6 +31,8 @@ # ./dictionary-manager --approve-updates '' . . +source yarrglib.tcl + # invocation: # OUT OF DATE diff --git a/yarrg/where-vessels b/yarrg/where-vessels index f7bbef6..50c38b3 100755 --- a/yarrg/where-vessels +++ b/yarrg/where-vessels @@ -1,19 +1,40 @@ #!/usr/bin/wish -pkg_mkIndex . -set auto_path [concat . $auto_path] +source yarrglib.tcl +source panner.tcl -package require panner +set pirate { } -set us Aristarchus +proc badusage {m} { + puts stderr "where-vessels: bad usage: $m" + exit 1 +} -proc manyset {list args} { - foreach val $list var $args { - upvar 1 $var my - set my $val +set ai 0 +proc nextarg {} { + global ai argv + if {$ai >= [llength $argv]} { + badusage "option [lindex $argv [expr {$ai-1}]] needs a value" } + set v [lindex $argv $ai] + incr ai + return $v } +while {[regexp {^\-} [set arg [lindex $argv $ai]]]} { + incr ai + switch -exact -- $arg { + -- { break } + --pirate { set pirate [string totitle [nextarg]] } + --ocean { set ocean [string totitle [nextarg]] } + --clipboard-file { set clipboard_file [nextarg] } + --notes { set notes_loc [nextarg] } + default { badusage "unknown option $arg" } + } +} +set argv [lrange $argv $ai end] +if {[llength $argv]} { badusage "non-option args not allowed" } + set itemre { (\w+) = ([^=]*) } set manyitemre "^\\\[ $itemre ( (?: ,\\ $itemre)* ) \\]\$" puts $manyitemre @@ -29,7 +50,7 @@ while {[gets $vn l] >= 0} { close $vn proc vessel {vin} { - global us + global pirate upvar #0 $vin vi switch -exact $vi(vesselClass) { smsloop { set sz 00sl } @@ -66,7 +87,7 @@ proc vessel {vin} { upvar #0 notes($nk) note if {[info exists note]} { manyset $note owner xabbrev - if {![string compare $owner $us]} { + if {![string compare $owner $pirate]} { append abbrev = } else { append abbrev - diff --git a/yarrg/yarrglib.tcl b/yarrg/yarrglib.tcl new file mode 100644 index 0000000..e1bf6e8 --- /dev/null +++ b/yarrg/yarrglib.tcl @@ -0,0 +1,8 @@ +package provide yarrglib 0.1; + +proc manyset {list args} { + foreach val $list var $args { + upvar 1 $var my + set my $val + } +} -- 2.30.2