chiark / gitweb /
where-vessels: more fine-grained scale-selection
[ypp-sc-tools.main.git] / yarrg / where-vessels
1 #!/usr/bin/wish
2 # show your vessels on a map
3
4 # This is part of ypp-sc-tools, a set of third-party tools for assisting
5 # players of Yohoho Puzzle Pirates.
6 #
7 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
23 # are used without permission.  This program is not endorsed or
24 # sponsored by Three Rings.
25
26
27
28 source yarrglib.tcl
29 source panner.tcl
30 package require http
31
32 #---------- general utilities ----------
33
34 set debug 0
35 proc debug {m} {
36     global debug
37     if {$debug} { puts "DEBUG $m" }
38 }
39
40 proc badusage {m} {
41     puts stderr "where-vessels: bad usage: $m"
42     exit 1
43 }
44
45 proc glset {n val} {
46     upvar #0 $n var
47     set var $val
48 }
49
50 #---------- expecting certain errors ----------
51
52 proc errexpect-setline {lno line} {
53     glset errexpect_lno $lno
54     glset errexpect_line $line
55 }
56
57 proc errexpect-error {m} {
58     global errexpect_line errexpect_lno
59     error $m "$errexpect_line\n" [list YARRG-ERREXPECT $errexpect_lno]
60 }
61
62 proc errexpect-arrayget {arrayvar key} {
63     upvar 1 $arrayvar av
64     upvar 1 ${arrayvar}($key) v
65     if {[info exists v]} { return $v }
66     errexpect-error "undefined $key"
67 }
68
69 proc errexpect-arrayget-boolean {arrayvar key} {
70     switch -exact [uplevel 1 [list errexpect-arrayget $arrayvar $key]] {
71         true    { return 1 }
72         false   { return 0 }
73         default { errexpect-error "unexpected $key" }
74     }
75 }
76
77 proc errexpect-catch {code} {
78     global errorInfo errorCode
79     set rc [catch {
80         uplevel 1 $code
81     } rv]
82     debug "ERREXPECT CATCH |$rc|$rv|$errorCode|$errorInfo|"
83     if {$rc==1 && ![string compare YARRG-ERREXPECT [lindex $errorCode 0]]} {
84         return [list 1 $rv [lindex $errorCode 1] $errorInfo]
85     } elseif {$rc==0} {
86         return [list 0 $rv]
87     } else {
88         return -code $rc -errorinfo $errorInfo -errorcode $errorCode $rv
89     }
90 }
91
92 #---------- argument parsing ----------
93
94 proc nextarg {} {
95     global ai argv
96     if {$ai >= [llength $argv]} {
97         badusage "option [lindex $argv [expr {$ai-1}]] needs a value"
98     }
99     set v [lindex $argv $ai]
100     incr ai
101     return $v
102 }
103
104 set notes_loc vessel-notes
105 set scraper {./yppedia-ocean-scraper --chart}
106 set info_cache _vessel-info-cache
107 set info_source rsync.yarrg.chiark.net::yarrg/vessel-info
108
109 proc parseargs {} {
110     global ai argv
111     global debug scraper
112     set ai 0
113
114     while {[regexp {^\-} [set arg [lindex $argv $ai]]]} {
115         incr ai
116         switch -exact -- $arg {
117             -- { break }
118             --pirate { glset pirate [string totitle [nextarg]] }
119             --ocean { glset ocean [string totitle [nextarg]] }
120             --clipboard-file { load-clipboard-file [nextarg] }
121             --local-html-dir { lappend scraper --local-html-dir=[nextarg] }
122             --notes { glset notes_loc [nextarg] }
123             --vessel-info-source { glset info_source [nextarg] }
124             --debug { incr debug }
125             default { badusage "unknown option $arg" }
126         }
127     }
128     set argv [lrange $argv $ai end]
129     if {[llength $argv]} { badusage "non-option args not allowed" }
130 }
131
132 proc argdefaults {} {
133     global ocean notes_loc pirate scraper
134     if {![info exists ocean] || ![info exists pirate]} {
135         set cmd {./yarrg --find-window-only --quiet}
136         if {[info exists ocean]} { lappend cmd --ocean $ocean }
137         if {[info exists pirate]} { lappend cmd --pirate $pirate }
138         manyset [split [eval exec $cmd] " "] ocean pirate
139         if {![llength $ocean] || ![llength $pirate]} {
140             error "$ocean $pirate ?"
141         }
142     }
143     lappend scraper $ocean
144 }
145
146
147 #---------- loading and parsing the vessel notes ----------
148
149 proc load-notes {} {
150     global notes_loc notes_data
151     if {[regexp {^\w+\:} $notes_loc]} {
152         update
153         debug "FETCHING NOTES $notes_loc"
154         set req [::http::geturl $notes_loc]
155         switch -glob [::http::status $req].[::http::ncode $req] {
156             ok.200 { }
157             ok.* { error "retrieving vessel-notes: [::http::code $req]" }
158             * { error "Retrieving vessel-notes: [::http::error $req]" }
159         }
160         set newdata [::http::data $req]
161         ::http::cleanup $req
162     } else {
163         debug "READING NOTES $notes_loc"
164         set vn [open $notes_loc]
165         set newdata [read $vn]
166         close $vn
167     }
168     set notes_data $newdata
169 }
170
171 proc parse-notes {} {
172     global notes_data notes
173     catch { unset notes }
174
175     set lno 0
176     foreach l [split $notes_data "\n"] {
177         incr lno
178         errexpect-setline $lno $l
179         set l [string trim $l]
180         if {![string length $l]} continue
181         if {[regexp {^\#} $l]} continue
182         if {![regexp -expanded \
183                   {^ (\d+) (?: \s+([^=]*?) )? \s* =
184                       (?: \s* (\S+)
185                        (?: \s+ (\S+) )?)? $} \
186                   $l dummy vid vname owner note]} {
187               errexpect-error "badly formatted"
188         }
189         set vname [string trim $vname]
190         if {[info exists notes($vid)]} {
191             errexpect-error "duplicate vesselid $vid"
192         }
193         set notes($vid) [list $lno $vname $owner $note]
194     }
195 }
196
197 proc note-info {lno vid name island description} {
198     global note_infos
199     lappend note_infos [list $lno $vid $name $island $description]
200 }
201
202 proc display-note-infos {} {
203     global note_infos note_missings notes
204
205     set nmissing [llength $note_missings]
206     debug "display-note-infos $nmissing [array size notes]"
207
208     if {[llength $note_infos]} {
209         set tiny "[llength $note_infos] warning(s)"
210     } elseif {$nmissing && [array size notes]} {
211         set tiny "$nmissing missing"
212     } else {
213         return
214     }
215
216     set infodata {}
217
218     foreach info $note_infos {
219         manyset $info lno vid name island description
220         append infodata "vessel"
221         append infodata " $vid"
222         if {[string length $name]} { append infodata " $name" }
223         if {[string length $island]} { append infodata " ($island)" }
224         append infodata ": " $description "\n"
225     }
226
227     if {$nmissing} {
228         if {[string length $infodata]} { append infodata "\n" }
229         append infodata "$nmissing vessel(s) not mentioned in notes:\n"
230         set last_island {}
231         foreach info [lsort $note_missings] {
232             manyset $info island name vid
233             if {[string compare $island $last_island]} {
234                 append infodata "# $island:\n"
235                 set last_island $island
236             }
237             append infodata [format "%-9d %-29s =\n" $vid $name]
238         }
239     }
240
241     parser-control-failed-core .cp.ctrl.notes notes \
242         white blue 0 \
243         $tiny \
244         "[llength $note_infos] warning(s);\
245          $nmissing vessel(s) missing" \
246         "Full description of warnings and missing vessels:" \
247         $infodata
248 }
249
250 #---------- vessel properties ----------
251
252 proc info-cache-update {} {
253     global info_source info_cache
254     file mkdir $info_cache
255     exec sh -c "cp -u icons/* $info_cache/."
256
257     if {[string length $info_source]} {
258         set cmdl [list \
259                   rsync -udLKtOzm \
260                   --exclude=*~ --exclude=*.bak --exclude=.* --exclude=*.tmp \
261                   $info_source/ $info_cache 2>@ stderr]
262         debug "INFO-CACHE $cmdl"
263         eval exec $cmdl
264     }
265
266     set f [open $info_cache/vessel-info]
267     glset vessel_size_data [read $f]
268     close $f
269 }
270
271 proc vesselinfo-init {} {
272     global vc_game2code vc_code2abbrev vc_code2full vc_codes
273
274     global vessel_size_data
275     manyset $vessel_size_data sizeinfos subclassinfos
276
277     set vc_codes {}
278     foreach {game code abbrev full} $sizeinfos {
279         if {![regexp {^[a-z][a-z]$} $code code]} { error "bad code" }
280         if {![regexp {^[a-z][a-z]$} $abbrev abbrev]} { error "bad abbrev" }
281         lappend vc_codes $code
282         set vc_game2code($game) $code
283         set vc_code2abbrev($code) $abbrev
284         set vc_code2full($code) $full
285         load-icon $abbrev
286     }
287
288     global vsc_code2report
289     global vsc_game2code
290     set vsc_game2code(null) {}
291     set vsc_code2report() Ordinary
292     set vsc_code2report(!) "(Special/L.E.)"
293     foreach {game code full} $subclassinfos {
294         if {![regexp {^[A-Z]$} $code code]} { error "bad code" }
295         set vsc_game2code($game) $code
296         set vsc_code2report($code) $full
297     }
298
299     load-icon atsea
300     set owners {ours dot query}
301     foreach b $owners { load-icon $b }
302     foreach a {battle borrow dot} {
303         load-icon $a
304         foreach b $owners { load-icon-combine $a $b }
305     }
306 }
307
308 proc load-icon {icon} {
309     global info_cache
310     image create bitmap icon/$icon -file $info_cache/$icon.xbm
311 }
312
313 proc load-icon-combine {args} {
314     global info_cache
315     set cmd {}
316     set delim "pnmcat -lr "
317     foreach icon $args {
318         append cmd $delim " <(xbmtopbm $info_cache/$icon.xbm)"
319         set delim " <(pbmmake -white 1 1)"
320     }
321     append cmd " | pbmtoxbm"
322     debug "load-icon-combine $cmd"
323     image create bitmap icon/[join $args +] -data [exec bash -c $cmd]
324 }
325
326 proc code-lockown2icon {lockown} {
327     manyset [split $lockown ""] lock notown
328     set l "
329          [lindex {battle borrow dot} $lock]
330          [lindex {ours dot query {} {} dot} $notown]
331     "
332     if {[llength $l]} { return icon/[join $l +] } { return {} }
333 }
334
335 proc canvas-horiz-stack {xvar xoff y bind type args} {
336     upvar 1 $xvar x
337     upvar 1 canvas canvas
338     set id [eval $canvas create $type [expr {$x+$xoff}] $y $args]
339     set bbox [$canvas bbox $id]
340 #   debug "CANVAS-HORIZ-STACK $type $x $xoff $id $bbox [list $args]"
341     set x [lindex $bbox 2]
342     $canvas bind $id <ButtonPress> $bind
343     return $id
344 }
345
346 proc code2canvas {code canvas x yvar qty qtylen bind} {
347     global vc_code2abbrev
348     upvar 1 $yvar y
349
350     manyset [split $code _] inport size subclass lockown xabbrev
351
352     set stackx $x
353     incr stackx 2
354     set imy [expr {$y+2}]
355
356     if {!$inport} { incr qtylen -1 }
357     if {$qtylen<=0} { set qtylen {} }
358     set qty [format "%${qtylen}s" $qty]
359
360     set qtyid [canvas-horiz-stack stackx 0 $y $bind \
361                    text -anchor nw -font fixed -text $qty]
362
363     if {!$inport} {
364         canvas-horiz-stack stackx 0 $imy $bind \
365             image -anchor nw -image icon/atsea
366         incr stackx
367     }
368     
369     upvar #0 vc_code2abbrev($size) vcabb
370     if {![info exists vcabb]} {
371         set vcabb vc-$size
372         image create bitmap icon/$vcabb -data \
373             [exec pbmtext -builtin fixed $size | pnminvert | pnmcrop >t.pnm]
374     }
375     canvas-horiz-stack stackx -1 $imy $bind \
376             image -anchor nw -image icon/$vcabb
377
378     if {[string length $subclass]} {
379         canvas-horiz-stack stackx 0 $y $bind \
380             text -anchor nw -font fixed -text \
381             $subclass
382     }
383
384     incr stackx
385     set lockownicon [code-lockown2icon $lockown]
386     if {[string length $lockownicon]} {
387         canvas-horiz-stack stackx 0 $imy $bind \
388             image -anchor nw -image $lockownicon
389         incr stackx
390     }
391     
392     if {[string length $xabbrev]} {
393         canvas-horiz-stack stackx 0 $y $bind \
394             text -anchor nw -font fixed -text \
395             $xabbrev
396     }
397     
398     set bbox [$canvas bbox $qtyid]
399     set ny [lindex $bbox 3]
400     set bid [$canvas create rectangle \
401                  $x $y $stackx $ny \
402                  -fill white]
403
404     set y $ny
405     $canvas lower $bid $qtyid
406
407     $canvas bind $bid <ButtonPress> $bind
408 }
409
410 proc show-report-decode {code} {
411     global vc_code2full
412
413     smash-prepare
414
415     manyset [split $code _] inport sizecode subclass lockown xabbrev
416     manyset [split $lockown ""] lock notown
417     
418     report-set inport [lindex {{At Sea} {In port}} $inport]
419
420     upvar #0 vc_code2full($sizecode) sizefull
421     upvar #0 smash_sizeinexact($sizecode) sizeinexact
422     set size_report $sizefull
423     if {[info exists sizeinexact]} { set size_report "($sizefull+)" }
424     report-set size $size_report
425
426     global smash_subclass
427     if {$smash_subclass >= 2} {
428         report-set subclass "(Any class)"
429     } elseif {[
430                upvar #0 vsc_code2report($subclass) subclass_report
431                info exists subclass_report
432               ]} {
433         report-set subclass $subclass_report
434     } else {
435         report-set subclass "Class \"$subclass\""
436     }
437
438     report-set lock [lindex {
439         {Battle ready} {Unlocked} {Locked}
440         {(All lock states)} {(Not battle ready)}
441     } $lock]
442
443     switch -exact $notown {
444         0 { report-set own "Yours" }
445         1 { report-set own "Other pirate's" }
446         2 { report-set own "Owner unknown" }
447         3 { report-set own "(All ownerships)" }
448         4 - 5 { report-set own "(Yours/unknown)" }
449         default { report-set own "?? $notown" }
450     }
451
452     global smash_xabbrev_map
453     if {[llength $smash_xabbrev_map]} {
454         if {[string length $xabbrev]} {
455             report-set xabbrev "(Flags: $xabbrev)"
456         } else {
457             report-set xabbrev "(No flags)"
458         }
459     } else {
460         if {[string length $xabbrev]} {
461             report-set xabbrev "Notes flags: $xabbrev"
462         } else {
463             report-set xabbrev "No flags in notes"
464         }
465     }
466 }
467
468 #---------- common to smashing and filtering ----------
469
470 proc make-control {parent ctrl label ekind} {
471     debug "MAKE-CONTROL [list $parent $ctrl $label $ekind]"
472     label $parent.lab_$ctrl -text $label -justify left
473     $ekind $parent.$ctrl
474     manyset [grid size $parent] dummy row
475     incr row
476     grid configure $parent.lab_$ctrl -row $row -column 0 -sticky nw -pady 4
477     grid configure $parent.$ctrl -row $row -column 1 -sticky w -pady 3
478     return $parent.$ctrl
479 }
480
481 proc begin-control-grid {cw count rows inrow} {
482     if {!$inrow} { set inrow [expr {($count + $rows) / $rows}] }
483     upvar #0 control_grid_properties($cw) props
484     set props [list $rows $inrow]
485     return $cw
486 }
487
488 proc make-control-grid-elem {cw kind ix ekind args} {
489     upvar #0 control_grid_properties($cw) props
490     manyset $props rows inrow
491
492     set ew $cw.$ix
493
494     debug "MAKE-CONTROL-GRID-ELEM $cw $kind $ix $ekind $rows $inrow $ew"
495
496     eval [list $ekind $ew] $args
497
498     switch -exact $kind {
499         ix {
500             grid configure $ew -sticky sw \
501                 -row [expr {$ix / $inrow}] \
502                 -column [expr {$ix % $inrow}]
503         }
504         final {
505             grid configure $ew -sticky se \
506                 -row [expr {$rows-1}] \
507                 -column [expr {$inrow-1}]
508         }
509         default {
510             error "$kind ?"
511         }
512     }
513     return $ew
514 }
515
516 proc control-tickbox-flip {varsvn values} {
517     upvar #0 $varsvn vars
518     foreach val $values {
519         set vars($val) [expr {!$vars($val)}]
520     }
521     redraw-needed c.-tickbox-flip $varsvn $values
522 }
523
524 proc populate-control-grid-tickboxes {cw rows inrow varsvn values flipvalues
525                                     label_kind valvn default_get label_get} {
526     debug "POPULATE-CONTROL-GRID-TICKBOXES $cw $rows $inrow $varsvn\
527              [list $values] $label_kind $valvn"
528
529     upvar #0 $varsvn vars
530     upvar 1 $valvn val
531     set count [llength $values]
532
533     begin-control-grid $cw $count $rows $inrow
534
535     for {set ix 0} {$ix < $count} {incr ix} {
536         set val [lindex $values $ix]
537         set vars($val) [uplevel 1 $default_get]
538         set ew [make-control-grid-elem $cw ix $ix checkbutton \
539                     -variable ${varsvn}($val) \
540                     -font fixed \
541                     -command [list redraw-needed c.-g.-tickbox $cw $val]]
542         $ew configure -$label_kind [uplevel 1 $label_get]
543         switch -exact $label_kind {
544             image { $ew configure -height 16 }
545         }
546     }
547     [make-control-grid-elem $cw final invert button] \
548         configure \
549         -text flip -command [list control-tickbox-flip $varsvn $flipvalues] \
550         -padx 0 -pady 0
551 }
552
553 #---------- smashing ----------
554
555 set smash_subclass 0
556 set smash_owner 0
557
558 proc smash-code {code} {
559     manyset [split $code _] inport size subclass lockown xabbrev
560
561     upvar #0 smash_sizemap($size) smsize
562
563     global smash_subclass
564     if {$smash_subclass > 1} {
565         set subclass {}
566     } elseif {$smash_subclass && [string length $subclass]} {
567         set subclass !
568     }
569
570     global smash_owner
571     switch $smash_owner {
572         0 { }
573         1 { regsub {[12]$} $lockown 5 lockown }
574         2 {
575             if {[regexp {^0.} $lockown]} {
576                 # battle ready / all lock states
577                 set lockown 03
578             } elseif {[regexp {^.0} $lockown]} {
579                 # not battle ready / yours
580                 set lockown 40
581             } else {
582                 # state (not battle ready) / not known to be yours
583                 regsub {.$} $lockown 4 lockown
584             }
585         }
586         3 { regsub {.$} $lockown {3} lockown }
587         4 { set lockown 33 }
588     }
589
590     global smash_xabbrev_map
591     set xabbrev [string map $smash_xabbrev_map $xabbrev]
592
593     return [join [list $inport $smsize $subclass $lockown $xabbrev] _]
594 }
595
596 proc smash-prepare {} {
597     global vc_codes smash_sizemap smash_size smash_sizeinexact
598     set mapto {}
599     catch { unset smash_sizeplus }
600     foreach size $vc_codes {
601         if {!$smash_size($size)} {
602             set mapto $size
603         } else {
604             set smash_sizeinexact($mapto) 1
605         }
606         set smash_sizemap($size) $mapto
607     }
608
609     global smash_xabbrev_a smash_xabbrev_b smash_xabbrev_map
610     set smash_xabbrev_map {}
611     foreach a [split $smash_xabbrev_a ""] b [split $smash_xabbrev_b ""] {
612         if {![string length $a]} continue
613         lappend smash_xabbrev_map $a $b
614     }
615     debug "SMASH-PREPAE xabbrev_map=[list $smash_xabbrev_map]"
616 }
617
618 proc make-smasher {sma label ekind} {
619     return [make-control .smash $sma $label $ekind]
620 }
621
622 proc make-radio-smasher {sma label variable descs rows inrow} {
623     set w [make-smasher $sma $label frame]
624     begin-control-grid $w [llength $descs] $rows $inrow
625     for {set i 0} {$i < [llength $descs]} {incr i} {
626         make-control-grid-elem $w ix $i \
627             radiobutton \
628             -variable $variable -value $i -command redraw-needed \
629             -text [lindex $descs $i]
630     }
631 }
632
633 proc make-smashers {} {
634     global vc_codes vc_code2abbrev
635     set cw [make-smasher size "Size\n round\n down" frame]
636     populate-control-grid-tickboxes $cw 2 0 smash_size \
637         $vc_codes [lrange $vc_codes 1 end] \
638         image val { expr 0 } { expr {"icon/$vc_code2abbrev($val)"} }
639     $cw.0 configure -state disabled
640
641     make-radio-smasher subclass Class smash_subclass \
642         {Show Normal/LE Hide} 1 0
643
644     make-radio-smasher owner Owner smash_owner \
645         {Show Yours? {For you} Lock Hide} 2 3
646
647     set cw [make-smasher xabbrev "Flags" frame]
648     foreach ix {1 3} ab {a b} width {14 12} {
649         set vn smash_xabbrev_$ab
650         global $vn
651         set $vn {}
652         entry $cw.$ix -textvariable $vn -width $width
653         trace add variable $vn write [list redraw-needed $vn]
654     }
655     set ix 0
656     foreach str {y/ / /d} { label $cw.$ix -text $str; incr ix 2 }
657     eval pack [lsort [winfo children $cw]] -side left
658 }
659
660 #---------- filtering ----------
661
662 set filters {}
663
664 proc filter-values/size {} { global vc_codes; return $vc_codes }
665 proc filter-icon/size {code} {
666     upvar #0 vc_code2abbrev($code) abb
667     return icon/$abb
668 }
669 proc filter-default/size {code} { return 1 }
670 proc filter-says-yes/size {codel} {
671     set sizecode [lindex $codel 1]
672     upvar #0 filter_size($sizecode) yes
673     return $yes
674 }
675
676 proc filter-values/lockown {} {
677     foreach lv {0 1 2} {
678         foreach ov {0 1 2} {
679             lappend vals "$lv$ov"
680         }
681     }
682     return $vals
683 }
684 proc filter-icon/lockown {lockown} { return [code-lockown2icon $lockown] }
685 proc filter-default/lockown {lockown} {
686     return [regexp {^[01]|^2[^1]} $lockown]
687 }
688 proc filter-says-yes/lockown {codel} {
689     set lockown [lindex $codel 3]
690     upvar #0 filter_lockown($lockown) yes
691     debug "FILTER-SAYS-YES/LOCKOWN $codel $lockown $yes"
692     return $yes
693 }
694
695 proc filter-validate/xabbre {re} {
696     if {[catch {
697         regexp -- $re {}
698     } emsg]} {
699         regsub {^.*:\s*} $emsg {} emsg
700         regsub {^.*(.{30})$} $emsg {\1} emsg
701         return $emsg
702     }
703     return {}
704 }
705 proc filter-says-yes/xabbre {codel} {
706     global filter_xabbre
707     set xabbrev [lindex $codel 4]
708     return [regexp -- $filter_xabbre $xabbrev]
709 }
710
711 proc make-tickbox-filter {fil label rows inrow} {
712     set values [filter-values/$fil]
713
714     if {![catch { info args filter-icon/$fil }]} {
715         set label_get { filter-icon/$fil $val }
716         set label_kind image
717     } else {
718         set label_get { filter-map/$fil $val }
719         set label_kind text
720     }
721
722     set fw [make-filter $fil $label frame]
723
724     populate-control-grid-tickboxes $fw $rows $inrow filter_$fil \
725         $values $values \
726         $label_kind val { filter-default/$fil $val } $label_get
727 }
728
729 proc entry-filter-changed {fw fil n1 n2 op} {
730     global errorInfo
731     upvar #0 filter_$fil realvar
732     upvar #0 filterentered_$fil entryvar
733     global def_background
734     debug "entry-filter-changed $fw $fil $entryvar"
735     if {[catch {
736         set error [filter-validate/$fil $entryvar]
737         if {[string length $error]} {
738             $fw.error configure -text $error -foreground white -background red
739         } else {
740             $fw.error configure -text { } -background $def_background
741             set realvar $entryvar
742             redraw-needed
743         }
744     } emsg]} {
745         puts stderr "FILTER CHECK ERROR $emsg $errorInfo"
746     }
747 }
748
749 proc make-entry-filter {fil label def} {
750     global filterentered_$fil
751     upvar #0 filter_$fil realvar
752     set realvar $def
753     set fw [make-filter $fil $label frame]
754     entry $fw.entry -textvariable filterentered_$fil
755     label $fw.error
756     glset def_background [$fw.error cget -background]
757     trace add variable filterentered_$fil write \
758         [list entry-filter-changed $fw $fil]
759     pack $fw.entry $fw.error -side top -anchor w
760 }
761
762 proc make-filter {fil label ekind} {
763     global filters
764     lappend filters $fil
765     return [make-control .filter $fil $label $ekind]
766 }
767
768 proc make-filters {} {
769     make-tickbox-filter size Size 2 0
770     make-tickbox-filter lockown "Lock/\nowner" 2 6
771     make-entry-filter xabbre "Flags\n regexp" {}
772 }
773
774 proc filterstyle-changed {n1 n2 op} {
775     global filterstyle
776     debug "filterstyle-changed $filterstyle"
777     redraw-needed
778 }
779
780 proc filters-say-yes {code} {
781     global filters filterstyle
782     set codel [split $code _]
783     set lockown [lindex $codel 3]
784     switch -exact $filterstyle {
785         0 { return 1 }
786         1 { return [filter-default/lockown $lockown] }
787         2 { return [regexp {^.0} $lockown] }
788         3 { }
789         default { error $filterstyle }
790     }
791     
792     foreach fil $filters {
793         if {![filter-says-yes/$fil $codel]} {
794             debug "FILTERS-SAY-YES $code NO $fil"
795             return 0
796         }
797     }
798     debug "FILTERS-SAY-YES $code YES $filters"
799     return 1
800 }
801     
802 #---------- loading and parsing the clipboard (vessel locations) ----------
803
804 proc vessel {vin} {
805     global pirate notes_used note_missings newnotes
806     upvar 1 $vin vi
807
808     set codel {}
809     lappend codel [errexpect-arrayget-boolean vi inPort]
810
811     set gamesize [errexpect-arrayget vi vesselClass]
812     upvar #0 vc_game2code($gamesize) size
813     if {![info exists size]} {
814         set size "($gamesize)"
815         upvar #0 vc_code2abbrev($size) vcabb
816         set vcabb vc-$size
817         set data [exec pbmtext -builtin fixed " $gamesize " \
818                  | pnminvert | pnmcrop | pbmtoxbm]
819         debug "INVENTED ICON $vcabb $data"
820         image create bitmap icon/$vcabb -data $data
821             
822         global vc_code2full
823         set vc_code2full($size) "Type \"$gamesize\""
824     }
825     lappend codel $size
826
827     set gamesubclass [errexpect-arrayget vi vesselSubclass]
828     upvar #0 vsc_game2code($gamesubclass) subclass
829     if {[info exists subclass]} {
830         lappend codel $subclass
831     } else {
832         lappend codel ($gamesubclass)
833     }
834
835     switch -exact [errexpect-arrayget vi isLocked]/[ \
836                    errexpect-arrayget vi isBattleReady] {
837         true/false      { set lock 2 }
838         false/false     { set lock 1 }
839         false/true      { set lock 0 }
840         default         { errexpect-error "unexpected isLocked/isBattleReady" }
841     }
842
843     set vid [errexpect-arrayget vi vesselId]
844     upvar #0 notes($vid) note
845     set realname [errexpect-arrayget vi vesselName]
846     set island [errexpect-arrayget vi islandName]
847
848     set owner {}
849     set xabbrev {}
850     if {[info exists note]} {
851         manyset $note lno notename owner xabbrev
852         if {[string compare -nocase $realname $notename]} {
853             note-info $lno $vid $realname $island \
854                 "notes say name is $notename"
855         }
856         if {[string length $owner]} {
857             if {![string compare $owner $pirate]} {
858                 set notown 0
859             } else {
860                 set notown 1
861             }
862         } else {
863             set notown 2
864         }
865         append abbrev $xabbrev
866         set notes_used($vid) 1
867
868     } else {
869         set notown 2
870         lappend note_missings [list $island $realname $vid]
871     }
872
873     lappend codel "$lock$notown" $xabbrev
874     lappend newnotes [list $vid $realname $owner $xabbrev]
875     set kk "$island [join $codel _]"
876     upvar #0 found($kk) k
877     lappend k [list $vid $realname $owner]
878  
879     debug "CODED $kk $vid $realname"
880 }
881
882 set clipboard {}
883 proc parse-clipboard {} {
884     global clipboard found notes notes_used newnotes
885
886     catch { unset found }
887     catch { unset notes_used }
888     glset note_infos {}
889     glset note_missings {}
890
891     set newnotes {}
892     
893     set itemre { (\w+) = ([^=]*) }
894     set manyitemre "^\\\[ $itemre ( (?: ,\\ $itemre)* ) \\]\$"
895     debug $manyitemre
896
897     set lno 0
898     foreach l [split $clipboard "\n"] {
899         incr lno
900         errexpect-setline $lno $l
901         if {![string length $l]} continue
902         catch { unset vi }
903         while 1 {
904                 if {![regexp -expanded $manyitemre $l dummy \
905                         thiskey thisval rhs]} {
906                     errexpect-error "badly formatted"
907                 }
908                 set vi($thiskey) $thisval
909                 if {![string length $rhs]} break
910                 regsub {^, } $rhs {} rhs
911                 set l "\[$rhs\]"
912         }
913         vessel vi
914     }
915
916     if {[llength $newnotes]} {
917         foreach vid [lsort [array names notes]] {
918             if {![info exists notes_used($vid)]} {
919                 manyset $notes($vid) lno notename
920                 note-info $lno $vid $notename {} \
921                     "vessel in notes no longer found"
922             }
923         }
924     }
925 }
926
927 proc load-clipboard-file {fn} {
928     set f [open $fn]
929     glset clipboard [read $f]
930     close $f
931 }
932
933
934 #---------- loading and parsing the chart ----------
935
936 proc load-chart {} {
937     global chart scraper
938     debug "FETCHING CHART"
939     set chart [eval exec $scraper [list | perl -we {
940         use strict;
941         use CommodsScrape;
942         use IO::File;
943         use IO::Handle;
944         yppedia_chart_parse(\*STDIN, (new IO::File ">/dev/null"),
945                 sub { sprintf "%d %d", @_; },
946                 sub { printf "archlabel %d %d %s\n", @_; },
947                 sub { printf "island %s {%s} %s\n", @_; },
948                 sub { printf "league %s %s %s.\n", @_; },
949                 sub { printf STDERR "warning: %s: incomprehensible: %s", @_; }
950                         );
951         STDOUT->error and die $!;
952     }]]
953 }
954
955 proc init-scales {} {
956     global scales scaleix scale
957     set defscale 16
958     set scales {1 2 3 4 5 6 8}
959     set e12 {10 12 15 18 22 27 33 39 47 56 68 82}
960     foreach t $e12 {
961         if {$t < $defscale} { set scaleix [llength $scales] }
962         lappend scales $t
963     }
964     foreach t [lrange $e12 0 6] { lappend scales [expr {$t * 10}] }
965     set scale [lindex $scales $scaleix]
966 }
967
968 proc coord {c} {
969         global scale
970         return [expr {$c * $scale}]
971 }
972
973 proc chart-got/archlabel {args} { }
974 proc chart-got/island {x y isle sizecol} {
975         debug "ISLE $x $y $isle $sizecol"
976         global canvas isleloc
977         set isleloc($isle) [list $x $y]
978         set sz 5
979 #       $canvas create oval \
980 #               [expr {[coord $x] - $sz}] [expr {[coord $y] - $sz}] \
981 #               [expr {[coord $x] + $sz}] [expr {[coord $y] + $sz}] \
982 #               -fill blue
983         set colour "#888"
984         if {[string match *_col $sizecol]} { set colour black }
985         $canvas create text [coord $x] [coord $y] \
986                 -text $isle -anchor s -fill $colour
987 }
988 proc chart-got/league {x1 y1 x2 y2 kind} {
989 #       debug "LEAGUE $x1 $y1 $x2 $y2 $kind"
990         global canvas
991         set l [$canvas create line \
992                 [coord $x1] [coord $y1] \
993                 [coord $x2] [coord $y2]]
994         if {![string compare $kind .]} {
995                 $canvas itemconfigure $l -dash .
996         }
997 }
998
999 proc debug-filter-array {array} {
1000     upvar #0 $array a
1001     set m " FILTER $array"
1002     foreach k [lsort [array names a]] {
1003         append m " $k=$a($k)"
1004     }
1005     debug $m
1006 }
1007
1008 proc redraw-needed {args} {
1009     global redraw_after
1010     debug "REDRAW NEEDED $args"
1011     if {[info exists redraw_after]} return
1012
1013     global filterstyle
1014     debug " FILTER style $filterstyle"
1015     debug-filter-array filter_size
1016     debug-filter-array filter_lockown
1017     global filter_xabbre
1018     debug " FILTER xabbre $filter_xabbre"
1019
1020     set redraw_after [after 250 draw]
1021 }
1022
1023 proc draw {} {
1024     global chart found isleloc canvas redraw_after islandnames smfound
1025
1026     catch { after cancel $redraw_after }
1027     catch { unset redraw_after }
1028     
1029     $canvas delete all
1030
1031     foreach l [split $chart "\n"] {
1032 #       debug "CHART-GOT $l"
1033         set proc [lindex $l 0]
1034         eval chart-got/$proc [lrange $l 1 end]
1035     }
1036
1037     smash-prepare
1038
1039     catch { unset smfound }
1040     foreach key [lsort [array names found]] {
1041         regexp {^(.*) (\S+)$} $key dummy islandname code
1042
1043         if {![filters-say-yes $code]} continue
1044
1045         set smcode [smash-code $code]
1046         debug "smashed $code => $smcode"
1047         set smkey "$islandname $smcode"
1048         foreach vessel $found($key) { lappend smfound($smkey) $vessel }
1049     }
1050
1051     set islandnames {}
1052     set lastislandname {}
1053     foreach smkey [lsort [array names smfound]] {
1054         set c [llength $smfound($smkey)]
1055         regexp {^(.*) (\S+)$} $smkey dummy islandname code
1056         debug "SHOWING [list $smkey $c $islandname $code l=$lastislandname]"
1057
1058         if {[string compare $lastislandname $islandname]} {
1059                 manyset $isleloc($islandname) x y
1060                 set x [coord $x]
1061                 set y [coord $y]
1062                 set lastislandname $islandname
1063                 lappend islandnames $islandname
1064 #               debug "START Y $y"
1065         }
1066
1067         if {$c > 1} { set qty [format %d $c] } else { set qty {} }
1068         code2canvas $code $canvas $x y $qty 2 \
1069             [list show-report $islandname $code]
1070 #       debug "NEW Y $y"
1071     }
1072
1073     panner::updatecanvas-bbox .cp.ctrl.pan
1074
1075     islandnames-update
1076 }
1077
1078
1079 #---------- parser error reporting ----------
1080
1081 proc parser-control-create {w base invokebuttontext etl_title} {
1082     frame $w
1083     button $w.do -text $invokebuttontext -command invoke_$base -pady 3
1084
1085     frame $w.resframe -width 120 -height 32
1086     button $w.resframe.res -text {} -anchor nw \
1087         -padx 1 -pady 1 -borderwidth 0 -justify left
1088     glset deffont_$base [$w.resframe.res cget -font]
1089     place $w.resframe.res -relx 0.5 -y 0 -anchor n
1090
1091     pack $w.do -side top
1092     pack $w.resframe -side top -expand y -fill both
1093
1094     set eb .err_$base
1095     toplevel $eb
1096     wm withdraw $eb
1097     wm title $eb "where-vessels - $etl_title"
1098     wm protocol $eb WM_DELETE_WINDOW [list wm withdraw $eb]
1099
1100     label $eb.title -text $etl_title
1101     pack $eb.title -side top
1102
1103     button $eb.close -text Close -command [list wm withdraw $eb]
1104     pack $eb.close -side bottom
1105
1106     frame $eb.emsg -bd 2 -relief groove
1107     label $eb.emsg.lab -anchor nw -text "Error:"
1108     text $eb.emsg.text -height 1
1109     pack $eb.emsg.text -side bottom -fill x
1110     pack $eb.emsg.lab -side left
1111
1112     pack $eb.emsg -side top -pady 2 -fill x
1113
1114     frame $eb.text -bd 2 -relief groove
1115     pack $eb.text -side bottom -pady 2 -fill both -expand y
1116     
1117     label $eb.text.lab -anchor nw
1118
1119     text $eb.text.text -width 85 \
1120         -xscrollcommand [list $eb.text.xscroll set] \
1121         -yscrollcommand [list $eb.text.yscroll set]
1122     $eb.text.text tag configure error \
1123         -background red -foreground white
1124
1125     scrollbar $eb.text.xscroll -orient horizontal \
1126         -command [list $eb.text.text xview]
1127     scrollbar $eb.text.yscroll -orient vertical \
1128         -command [list $eb.text.text yview]
1129
1130     grid configure $eb.text.lab -row 0 -column 0 -sticky w -columnspan 2
1131     grid configure $eb.text.text -row 1 -column 0 -sticky news
1132     grid configure $eb.text.yscroll -sticky ns -row 1 -column 1
1133     grid configure $eb.text.xscroll -sticky ew -row 2 -column 0
1134     grid rowconfigure $eb.text 0 -weight 0
1135     grid rowconfigure $eb.text 1 -weight 1
1136     grid rowconfigure $eb.text 2 -weight 0
1137     grid columnconfigure $eb.text 0 -weight 1
1138     grid columnconfigure $eb.text 1 -weight 0
1139 }
1140
1141 proc parser-control-ok-core {w base background show} {
1142     debug "parser-control-ok-core $w $base $background $show"
1143     upvar #0 deffont_$base deffont
1144     $w.resframe.res configure \
1145         -background $background -disabledforeground black -font $deffont \
1146         -state disabled -command {} \
1147         -text $show
1148 }    
1149 proc parser-control-ok {w base show} {
1150     parser-control-ok-core $w $base green $show
1151 }
1152 proc parser-control-none {w base show} {
1153     parser-control-ok-core $w $base blue $show
1154 }
1155 proc parser-control-failed-core {w base foreground background smallfont
1156                                  tiny summary fulldesc fulldata} {
1157     debug "parser-control-failed-core $w $base $summary $fulldesc"
1158     upvar #0 deffont_$base deffont
1159     set eb .err_$base
1160
1161     $eb.emsg.text delete 0.0 end
1162     $eb.emsg.text insert end $summary
1163
1164     $eb.text.lab configure -text $fulldesc
1165     $eb.text.text delete 0.0 end
1166     $eb.text.text insert end $fulldata
1167
1168     regsub -all {.{18}} $tiny "&\n" ewrap
1169
1170     if {$smallfont} {
1171         set font fixed
1172     } else {
1173         set font $deffont
1174     }
1175
1176     $w.resframe.res configure \
1177         -background $background -foreground $foreground -font $font \
1178         -state normal -command [list wm deiconify $eb] \
1179         -text $ewrap
1180 }
1181     
1182 proc parser-control-failed-expected {w base emsg lno ei fulldesc newdata} {
1183     set eb .err_$base
1184
1185     set line [lindex [split $ei "\n"] 0]
1186     debug "parser-control-failed-expected: $w $base: $lno: $emsg\n $line"
1187
1188     parser-control-failed-core $w $base \
1189         white red 1 \
1190         "err: [string trim $emsg]: \"$line\"" \
1191         "at line $lno: $emsg" \
1192         $fulldesc $newdata
1193
1194     $eb.text.text tag add error $lno.0 $lno.end
1195     $eb.text.text see $lno.0    
1196 }
1197 proc parser-control-failed-unexpected {w base emsg ei} {
1198     global errorInfo
1199     parser-control-failed-core $w $base \
1200         black yellow 1 \
1201         $emsg $emsg "Details and stack trace:" $ei
1202 }
1203
1204 proc reparse {base varname old fulldesc okshow noneshow parse ok} {
1205     upvar #0 $varname var
1206     manyset [errexpect-catch {
1207         uplevel 1 $parse
1208         if {[string length [string trim $var]]} {
1209             parser-control-ok .cp.ctrl.$base $base $okshow
1210         } else {
1211             parser-control-none .cp.ctrl.$base $base $noneshow
1212         }
1213     }] failed emsg lno ei
1214     if {$failed} {
1215         parser-control-failed-expected .cp.ctrl.$base $base \
1216             $emsg $lno $ei $fulldesc $var
1217         set var $old
1218         uplevel 1 $parse
1219     } else {
1220         uplevel 1 $ok
1221     }
1222 }
1223
1224 #---------- island names selection etc. ----------
1225
1226 proc islandnames-update {} {
1227     global islandnames
1228     .islands.count configure -text [format "ships at %d island(s)" \
1229                                         [llength $islandnames]]
1230 }
1231
1232 proc islandnames-select {} {
1233     .islands.clip configure -relief sunken -state disabled
1234     selection own -command islandnames-deselect .islands.clip
1235 }
1236 proc islandnames-deselect {} {
1237     .islands.clip configure -relief raised -state normal
1238 }
1239
1240 proc islandnames-handler {offset maxchars} {
1241     global islandnames
1242     return [string range [join $islandnames ", "] \
1243                 $offset [expr {$offset+$maxchars-1}]]
1244 }
1245
1246 #---------- main user interface ----------
1247
1248 proc widgets-setup {} {
1249     global canvas debug pirate ocean filterstyle
1250
1251     wm geometry . 1200x800
1252     wm title . "where-vessels - $pirate on the $ocean ocean"
1253
1254     #----- map -----
1255
1256     frame .f -border 1 -relief groove
1257     set canvas .f.c
1258     canvas $canvas
1259     pack $canvas -expand 1 -fill both
1260     pack .f -expand 1 -fill both -side left
1261
1262     #----- control panels and filter -----
1263
1264     frame .cp
1265     frame .smash -relief groove -bd 2 -padx 1
1266     frame .filter -relief groove -bd 2 -padx 1
1267     frame .islands -pady 2
1268     pack .cp .filter .islands .smash -side top
1269
1270     label .smash.title -text {Display/combine details}
1271     grid .smash.title -row 0 -column 0 -columnspan 2
1272
1273     set filterstyle 1
1274     trace add variable filterstyle write filterstyle-changed
1275
1276     frame .filter.title
1277     label .filter.title.title -text Show
1278     pack .filter.title.title -side left
1279     for {set fing 0} {$fing < 4} {incr fing} {
1280         radiobutton .filter.title.f$fing \
1281             -variable filterstyle -value $fing \
1282             -text [lindex {All Useable Mine These:} $fing]
1283         pack .filter.title.f$fing -side left
1284     }
1285
1286     grid configure .filter.title -row 0 -column 0 -columnspan 2
1287
1288     #----- control panel -----
1289
1290     frame .cp.ctrl
1291     pack .cp.ctrl -side left -anchor n
1292
1293     debug "BBOX [$canvas bbox all]"
1294
1295     panner::canvas-scroll-bbox .f.c
1296     panner::create .cp.ctrl.pan .f.c 120 120 $debug
1297
1298     pack .cp.ctrl.pan -side top -pady 0 -padx 5
1299     frame .cp.ctrl.zoom
1300     pack .cp.ctrl.zoom -side top
1301
1302     foreach inout {out in} minplus {- +} {
1303         button .cp.ctrl.zoom.$inout -text $minplus -font {Courier 16} \
1304             -command "zoom ${minplus}1" -pady 0
1305         pack .cp.ctrl.zoom.$inout -side left
1306     }
1307
1308     parser-control-create .cp.ctrl.acquire \
1309         acquire Acquire \
1310         "Clipboard parsing error" \
1311         
1312     pack .cp.ctrl.acquire -side top -pady 2
1313
1314     parser-control-create .cp.ctrl.notes \
1315         notes "Reload notes" \
1316         "Vessel notes loading report" \
1317         
1318     pack .cp.ctrl.notes -side top -pady 2
1319
1320     #----- island name count and copy -----
1321
1322     label .islands.count
1323     button .islands.clip -text "copy island names" -pady 2 -padx 2 \
1324          -command islandnames-select
1325     selection handle .islands.clip islandnames-handler
1326     pack .islands.count .islands.clip -side left
1327
1328     #----- decoding etc. report -----
1329
1330     frame .cp.report
1331     pack .cp.report -side left -anchor n
1332
1333     label .cp.report.island -text { }
1334
1335     canvas .cp.report.abbrev -width 1 -height 15
1336
1337     frame .cp.report.code
1338     label .cp.report.code.lab -text Code:
1339     glset report_code { }
1340     entry .cp.report.code.code -state readonly \
1341         -textvariable report_code -width 15
1342     pack .cp.report.code.lab .cp.report.code.code -side left
1343     frame .cp.report.details -bd 2 -relief groove -padx 2 -pady 2
1344
1345     listbox .cp.report.list -height 5
1346
1347     pack .cp.report.island .cp.report.abbrev .cp.report.details \
1348         .cp.report.list -side top
1349     #pack .cp.report.code -side top
1350     pack configure .cp.report.details -fill x
1351
1352     foreach sw {inport size subclass lock own xabbrev} {
1353         label .cp.report.details.$sw -text { }
1354         pack .cp.report.details.$sw -side top -anchor w
1355     }
1356 }
1357
1358 proc report-set {sw val} { .cp.report.details.$sw configure -text $val }
1359
1360 proc show-report {islandname code} {
1361     .cp.report.island configure -text $islandname
1362
1363     .cp.report.abbrev delete all
1364     set y 2
1365     code2canvas $code .cp.report.abbrev 5 y {} 0 {}
1366     manyset [.cp.report.abbrev bbox all] minx dummy maxx dummy
1367     .cp.report.abbrev configure -width [expr {$maxx-$minx+4}]
1368
1369     glset report_code $code
1370     show-report-decode $code
1371
1372     set kk "$islandname $code"
1373     upvar #0 smfound($kk) k
1374
1375     .cp.report.list delete 0 end
1376
1377     foreach elem $k {
1378         manyset $elem vid name owner
1379         lappend owned($owner) $name
1380     }
1381
1382     foreach owner [lsort [array names owned]] {
1383         if {[string length $owner]} {
1384             set owndesc "$owner's"
1385         } else {
1386             set owndesc "Owner unknown"
1387         }
1388         .cp.report.list insert end "$owndesc:"
1389         foreach name $owned($owner) {
1390             .cp.report.list insert end " $name"
1391         }
1392     }
1393 }
1394
1395 proc zoom {amt} {
1396     global scaleix scales scale canvas
1397     incr scaleix $amt
1398     if {$scaleix < 0} { set scaleix 0 }
1399     set nscales [llength $scales]
1400     if {$scaleix >= $nscales} { set scaleix [expr {$nscales-1}] }
1401     set scale [lindex $scales $scaleix]
1402     debug "ZOOM $amt $scaleix $scale"
1403     draw
1404 }
1405
1406 proc invoke_acquire {} {
1407     global clipboard errorInfo
1408     set old $clipboard
1409
1410     if {[catch {
1411         set clipboard [clipboard get]
1412     } emsg]} {
1413         parser-control-failed-unexpected .cp.ctrl.acquire acquire \
1414             $emsg "fetching clipboard:\n\n$errorInfo"
1415         return
1416     }
1417
1418     reparse acquire \
1419         clipboard $old "Clipboard contents:" { acquired ok } { no vessels } {
1420             parse-clipboard
1421         } {
1422             display-note-infos
1423         }
1424     draw
1425 }
1426
1427 proc invoke_notes {} {
1428     global notes_data errorInfo notes_loc
1429     set old $notes_data
1430     
1431     if {[catch {
1432         load-notes
1433     } emsg]} {
1434         parser-control-failed-unexpected .cp.ctrl.notes notes \
1435             $emsg "loading $notes_loc:\n\n$errorInfo"
1436         return
1437     }
1438
1439     reparse notes \
1440         notes_data $old "Vessel notes:" "loaded ok" { no notes } {
1441             parse-notes
1442             parse-clipboard
1443         } {
1444             display-note-infos
1445         }
1446     draw
1447 }
1448
1449 #---------- main program ----------
1450
1451 init-scales
1452 parseargs
1453 argdefaults
1454 httpclientsetup where-vessels
1455 info-cache-update
1456 vesselinfo-init
1457 load-chart
1458 widgets-setup
1459 make-filters
1460 make-smashers
1461
1462 set notes_data {}
1463 if {[catch { parse-clipboard } emsg]} {
1464     puts stderr "$emsg\n$errorInfo"
1465     exit 1
1466 }
1467 after idle invoke_notes
1468
1469 draw
1470
1471 if {$debug} {
1472     package require Tclx
1473     commandloop -async \
1474         -prompt1 { return "where-vessels% " } \
1475         -prompt2 { return "> " }
1476 }
1477
1478 # rsync -r --exclude=\*~ yarrg/icons/. ijackson@chiark.greenend.org.uk:/home/ftp/users/ijackson/yarrg/vessel-info/.