chiark / gitweb /
where-vessels: WIP argument parsing; library load changes
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 12 Dec 2009 11:43:13 +0000 (11:43 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 12 Dec 2009 13:14:53 +0000 (13:14 +0000)
.gitignore
yarrg/dictionary-manager
yarrg/where-vessels
yarrg/yarrglib.tcl [new file with mode: 0644]

index a580b970b1b2d1a3a00ed34384cd3fca62d670a2..9beb60b750d2464935fe401f3c4f57834f606650 100644 (file)
@@ -15,5 +15,3 @@ yarrg/_*.*
 yarrg/OCEAN-*.db
 yarrg/Writer.lock
 yarrg/DATA
-
-yarrg/pkgIndex.tcl
index 2231266edc8f0e0ef441067a7e5ffd276ba52ba6..83c7e548c29ff3873a9b4e0057ded05f1fdeb1f7 100755 (executable)
@@ -31,6 +31,8 @@
 
 # ./dictionary-manager --approve-updates '' . .
 
+source yarrglib.tcl
+
 
 # invocation:
 # OUT OF DATE
index f7bbef6b728234ffdd5ed70699215ba2041f9a42..50c38b3595e0f399ba4f8e61590bb06136bba099 100755 (executable)
@@ -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 (file)
index 0000000..e1bf6e8
--- /dev/null
@@ -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
+    }
+}