chiark / gitweb /
where-vessels: decode codes and abbrevs for the user
[ypp-sc-tools.db-test.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
107 proc parseargs {} {
108     global ai argv
109     global debug scraper
110     set ai 0
111
112     while {[regexp {^\-} [set arg [lindex $argv $ai]]]} {
113         incr ai
114         switch -exact -- $arg {
115             -- { break }
116             --pirate { glset pirate [string totitle [nextarg]] }
117             --ocean { glset ocean [string totitle [nextarg]] }
118             --clipboard-file { load-clipboard-file [nextarg] }
119             --local-html-dir { lappend scraper --local-html-dir=[nextarg] }
120             --notes { glset notes_loc [nextarg] }
121             --debug { incr debug }
122             default { badusage "unknown option $arg" }
123         }
124     }
125     set argv [lrange $argv $ai end]
126     if {[llength $argv]} { badusage "non-option args not allowed" }
127 }
128
129 proc argdefaults {} {
130     global ocean notes_loc pirate scraper
131     if {![info exists ocean] || ![info exists pirate]} {
132         set cmd {./yarrg --find-window-only --quiet}
133         if {[info exists ocean]} { lappend cmd --ocean $ocean }
134         if {[info exists pirate]} { lappend cmd --pirate $pirate }
135         manyset [split [eval exec $cmd] " "] ocean pirate
136     }
137     lappend scraper $ocean
138 }
139
140
141 #---------- loading and parsing the vessel notes ----------
142
143 proc load-notes {} {
144     global notes_loc notes_data
145     if {[regexp {^\w+\:} $notes_loc]} {
146         update
147         debug "FETCHING NOTES $notes_loc"
148         set req [::http::geturl $notes_loc]
149         switch -glob [::http::status $req].[::http::ncode $req] {
150             ok.200 { }
151             ok.* { error "retrieving vessel-notes: [::http::code $req]" }
152             * { error "Retrieving vessel-notes: [::http::error $req]" }
153         }
154         set newdata [::http::data $req]
155         ::http::cleanup $req
156     } else {
157         debug "READING NOTES $notes_loc"
158         set vn [open $notes_loc]
159         set newdata [read $vn]
160         close $vn
161     }
162     set notes_data $newdata
163 }
164
165 proc parse-notes {} {
166     global notes_data notes
167     catch { unset notes }
168
169     set lno 0
170     foreach l [split $notes_data "\n"] {
171         incr lno
172         errexpect-setline $lno $l
173         set l [string trim $l]
174         if {![string length $l]} continue
175         if {[regexp {^\#} $l]} continue
176         if {![regexp -expanded \
177                   {^ (\d+) (?: \s+([^=]*?) )? \s* =
178                       (?: \s* (\S+)
179                        (?: \s+ (\S+) )?)? $} \
180                   $l dummy vid vname owner note]} {
181               errexpect-error "badly formatted"
182         }
183         set vname [string trim $vname]
184         if {[info exists notes($vid)]} {
185             errexpect-error "duplicate vesselid $vid"
186         }
187         set notes($vid) [list $lno $vname $owner $note]
188     }
189 }
190
191 proc note-info {lno vid name island description} {
192     global note_infos
193     lappend note_infos [list $lno $vid $name $island $description]
194 }
195
196 proc display-note-infos {} {
197     global note_infos note_missings notes
198
199     set nmissing [llength $note_missings]
200     debug "display-note-infos $nmissing [array size notes]"
201
202     if {[llength $note_infos]} {
203         set tiny "[llength $note_infos] warnings"
204     } elseif {$nmissing && [array size notes]} {
205         set tiny "$nmissing missing"
206     } else {
207         return
208     }
209
210     set infodata {}
211
212     foreach info $note_infos {
213         manyset $info lno vid name island description
214         append infodata "vessel"
215         append infodata " $vid"
216         if {[string length $name]} { append infodata " $name" }
217         if {[string length $island]} { append infodata " ($island)" }
218         append infodata ": " $description "\n"
219     }
220
221     if {$nmissing} {
222         if {[string length $infodata]} { append infodata "\n" }
223         append infodata "$nmissing vessel(s) not mentioned in notes:\n"
224         set last_island {}
225         foreach info [lsort $note_missings] {
226             manyset $info island name vid
227             if {[string compare $island $last_island]} {
228                 append infodata "# $island:\n"
229                 set last_island $island
230             }
231             append infodata [format "%-9d %-29s =\n" $vid $name]
232         }
233     }
234
235     parser-control-failed-core .ctrl.notes notes \
236         white blue 0 \
237         $tiny \
238         "[llength $note_infos] warning(s);\
239          $nmissing vessel(s) missing" \
240         "Full description of warnings and missing vessels:" \
241         $infodata
242 }
243
244 #---------- vessel properties ----------
245
246 proc vesselclasses-init {} {
247     global vc_game2code vc_code2abbrev vc_code2full
248     foreach {game code abbrev full} {
249         smsloop         am      sl      Sloop
250         lgsloop         bm      ct      Cutter
251         dhow            cm      dh      Dhow
252         longship        dm      ls      Longship
253         baghlah         em      bg      Baghlah
254         merchbrig       fm      mb      {Merchant Brig}
255         warbrig         gm      wb      {War Brig}
256         xebec           hm      xe      Xebec
257         warfrig         im      wf      {War Frigate}
258         merchgal        jm      mg      {Merchant Galleon}
259         grandfrig       km      gf      {Grand Frigate}
260     } {
261         set vc_game2code($game) $code
262         set vc_code2abbrev($code) $abbrev
263         set vc_code2full($code) $full
264     }
265 }
266
267 proc code2abbrev {code} {
268     global vc_code2abbrev
269
270     manyset [split $code _] inport class subclass lockown xabbrev
271     manyset [split $lockown ""] lock notown
272
273     set abbrev {}
274     append abbrev [lindex {? {}} $inport]
275     append abbrev $vc_code2abbrev($class)
276     append abbrev $subclass
277     append abbrev [lindex {* + -} $lock]
278     append abbrev [lindex {= - ?} [regsub {\D} $notown 2]]
279     append abbrev $xabbrev
280
281     debug "CODE2ABBREV $code $abbrev"
282     return $abbrev
283 }
284
285 proc show-report {islandname code} {
286     global vc_code2full
287
288     .report.island configure -text $islandname
289     glset report_code $code
290     glset report_abbrev [code2abbrev $code]
291
292     manyset [split $code _] inport classcode subclass lockown xabbrev
293     manyset [split $lockown ""] lock notown
294     
295     report-set inport [lindex {{At Sea} {In port}} $inport]
296     report-set class $vc_code2full($classcode)
297
298     switch -exact $subclass {
299         {} { report-set subclass {Ordinary} }
300         F { report-set subclass {"Frost class"} }
301         default { report-set subclass "Subclass \"$subclass\"" }
302     }
303
304     report-set lock [lindex {
305         {Battle ready} {Unlocked} {Locked}
306     } $lock]
307
308     switch -exact $notown {
309         0 { report-set own "Yours" }
310         1 { report-set own "Other pirate's" }
311         U { report-set own "Owner not known" }
312         M { report-set own "Missing from notes" }
313         default { report-set own "?? $notown" }
314     }
315
316     if {[string length $xabbrev]} {
317         report-set xabbrev "Notes flags: $xabbrev"
318     } else {
319         report-set xabbrev "No flags in notes"
320     }
321 }
322     
323 #---------- loading and parsing the clipboard (vessel locations) ----------
324
325 proc vessel {vin} {
326     global pirate notes_used note_missings newnotes
327     upvar 1 $vin vi
328
329     set codel {}
330     lappend codel [errexpect-arrayget-boolean vi inPort]
331
332     set gameclass [errexpect-arrayget vi vesselClass]
333     upvar #0 vc_game2code($gameclass) class
334     if {![info exists class]} { errexpect-error "unexpected vesselClass"}
335     lappend codel $class
336
337     set subclass [errexpect-arrayget vi vesselSubclass]
338     switch -exact $subclass {
339         null            { lappend codel {} }
340         icy             { lappend codel F }
341         default         { lappend codel ($subclass) }
342     }
343
344     switch -exact [errexpect-arrayget vi isLocked]/[ \
345                    errexpect-arrayget vi isBattleReady] {
346         true/false      { set lock 2 }
347         false/false     { set lock 1 }
348         false/true      { set lock 0 }
349         default         { errexpect-error "unexpected isLocked/isBattleReady" }
350     }
351
352     set vid [errexpect-arrayget vi vesselId]
353     upvar #0 notes($vid) note
354     set realname [errexpect-arrayget vi vesselName]
355     set island [errexpect-arrayget vi islandName]
356
357     set owner {}
358     set xabbrev {}
359     if {[info exists note]} {
360         manyset $note lno notename owner xabbrev
361         if {[string compare -nocase $realname $notename]} {
362             note-info $lno $vid $realname $island \
363                 "notes say name is $notename"
364         }
365         if {[string length $owner]} {
366             if {![string compare $owner $pirate]} {
367                 set notown 0
368             } else {
369                 set notown 1
370             }
371         } else {
372             set notown U
373         }
374         append abbrev $xabbrev
375         set notes_used($vid) 1
376
377     } else {
378         set notown M
379         lappend note_missings [list $island $realname $vid]
380     }
381
382     lappend codel "$lock$notown" $xabbrev
383     lappend newnotes [list $vid $realname $owner $xabbrev]
384     set kk "$island [join $codel _]"
385     upvar #0 count($kk) k
386     if {![info exists k]} { set k 0 }
387     incr k
388
389     debug "CODED $kk $vid $realname"
390 }
391
392 set clipboard {}
393 proc parse-clipboard {} {
394     global clipboard count notes notes_used newnotes
395
396     catch { unset count }
397     catch { unset notes_used }
398     glset note_infos {}
399     glset note_missings {}
400
401     set newnotes {}
402     
403     set itemre { (\w+) = ([^=]*) }
404     set manyitemre "^\\\[ $itemre ( (?: ,\\ $itemre)* ) \\]\$"
405     debug $manyitemre
406
407     set lno 0
408     foreach l [split $clipboard "\n"] {
409         incr lno
410         errexpect-setline $lno $l
411         if {![string length $l]} continue
412         catch { unset vi }
413         while 1 {
414                 if {![regexp -expanded $manyitemre $l dummy \
415                         thiskey thisval rhs]} {
416                     errexpect-error "badly formatted"
417                 }
418                 set vi($thiskey) $thisval
419                 if {![string length $rhs]} break
420                 regsub {^, } $rhs {} rhs
421                 set l "\[$rhs\]"
422         }
423         vessel vi
424     }
425
426     if {[llength $newnotes]} {
427         foreach vid [lsort [array names notes]] {
428             if {![info exists notes_used($vid)]} {
429                 manyset $notes($vid) lno notename
430                 note-info $lno $vid $notename {} \
431                     "vessel in notes no longer found"
432             }
433         }
434     }
435 }
436
437 proc load-clipboard-file {fn} {
438     set f [open $fn]
439     glset clipboard [read $f]
440     close $f
441 }
442
443
444 #---------- loading and parsing the chart ----------
445
446 proc load-chart {} {
447     global chart scraper
448     debug "FETCHING CHART"
449     set chart [eval exec $scraper [list | perl -we {
450         use strict;
451         use CommodsScrape;
452         use IO::File;
453         use IO::Handle;
454         yppedia_chart_parse(\*STDIN, (new IO::File ">/dev/null"),
455                 sub { sprintf "%d %d", @_; },
456                 sub { printf "archlabel %d %d %s\n", @_; },
457                 sub { printf "island %s %s\n", @_; },
458                 sub { printf "league %s %s %s.\n", @_; },
459                 sub { printf STDERR "warning: %s: incomprehensible: %s", @_; }
460                         );
461         STDOUT->error and die $!;
462     }]]
463 }
464
465
466 set scale 16
467
468 proc coord {c} {
469         global scale
470         return [expr {$c * $scale}]
471 }
472
473 proc chart-got/archlabel {args} { }
474 proc chart-got/island {x y args} {
475 #       debug "ISLE $x $y $args"
476         global canvas isleloc
477         set isleloc($args) [list $x $y]
478         set sz 5
479 #       $canvas create oval \
480 #               [expr {[coord $x] - $sz}] [expr {[coord $y] - $sz}] \
481 #               [expr {[coord $x] + $sz}] [expr {[coord $y] + $sz}] \
482 #               -fill blue
483         $canvas create text [coord $x] [coord $y] \
484                 -text $args -anchor s
485 }
486 proc chart-got/league {x1 y1 x2 y2 kind} {
487 #       debug "LEAGUE $x1 $y1 $x2 $y2 $kind"
488         global canvas
489         set l [$canvas create line \
490                 [coord $x1] [coord $y1] \
491                 [coord $x2] [coord $y2]]
492         if {![string compare $kind .]} {
493                 $canvas itemconfigure $l -dash .
494         }
495 }
496
497 proc draw {} {
498     global chart count isleloc canvas
499     
500     $canvas delete all
501
502     foreach l [split $chart "\n"] {
503 #       debug "CHART-GOT $l"
504         set proc [lindex $l 0]
505         eval chart-got/$proc [lrange $l 1 end]
506     }
507
508     set lastislandname {}
509     foreach key [lsort [array names count]] {
510         set c $count($key)
511 #       debug "SHOWING $key $c"
512         regexp {^(.*) (\S+)$} $key dummy islandname code
513
514         set abbrev [code2abbrev $code]
515         
516         if {[string compare $lastislandname $islandname]} {
517                 manyset $isleloc($islandname) x y
518                 set x [coord $x]
519                 set y [coord $y]
520                 set lastislandname $islandname
521 #               debug "START Y $y"
522         }
523         set text $abbrev
524         regsub -all {[0-9]} $text {} text
525         if {$c > 1} {
526                 set text [format "%2d%s" $c $text]
527         } else {
528                 set text [format "  %s" $text]
529         }
530         set id [$canvas create text $x $y \
531                 -anchor nw -font fixed \
532                 -text $text]
533         set bbox [$canvas bbox $id]
534         set bid [eval $canvas create rectangle $bbox -fill white]
535         $canvas lower $bid $id
536         $canvas bind $id <ButtonPress> [list show-report $islandname $code]
537         $canvas bind $bid <ButtonPress> [list show-report $islandname $code]
538         manyset $bbox dummy dummy dummy y
539 #       debug "NEW Y $y"
540     }
541
542     panner::updatecanvas-bbox .ctrl.pan
543 }
544
545
546 #---------- parser error reporting ----------
547
548 proc parser-control-create {w base invokebuttontext etl_title} {
549     frame $w
550     button $w.do -text $invokebuttontext -command invoke_$base
551
552     frame $w.resframe -width 120 -height 32
553     button $w.resframe.res -text {} -anchor nw \
554         -padx 1 -pady 1 -borderwidth 0 -justify left
555     glset deffont_$base [$w.resframe.res cget -font]
556     place $w.resframe.res -relx 0.5 -y 0 -anchor n
557
558     pack $w.do -side top
559     pack $w.resframe -side top -expand y -fill both
560
561     set eb .err_$base
562     toplevel $eb
563     wm withdraw $eb
564     wm title $eb "where-vessels - $etl_title"
565
566     label $eb.title -text $etl_title
567     pack $eb.title -side top
568
569     button $eb.close -text Close -command [list wm withdraw $eb]
570     pack $eb.close -side bottom
571
572     frame $eb.emsg -bd 2 -relief groove
573     label $eb.emsg.lab -text "Error:"
574     text $eb.emsg.text -height 1
575     pack $eb.emsg.text -side bottom
576     pack $eb.emsg.lab -side left
577
578     pack $eb.emsg -side top -pady 2
579
580     frame $eb.text -bd 2 -relief groove
581     pack $eb.text -side bottom -pady 2
582     
583     label $eb.text.lab
584
585     text $eb.text.text -width 85 \
586         -xscrollcommand [list $eb.text.xscroll set] \
587         -yscrollcommand [list $eb.text.yscroll set]
588     $eb.text.text tag configure error \
589         -background red -foreground white
590
591     scrollbar $eb.text.xscroll -orient horizontal \
592         -command [list $eb.text.text xview]
593     scrollbar $eb.text.yscroll -orient vertical \
594         -command [list $eb.text.text yview]
595
596     grid configure $eb.text.lab -row 0 -column 0 -sticky w
597     grid configure $eb.text.text -row 1 -column 0
598     grid configure $eb.text.yscroll -sticky ns -row 1 -column 1
599     grid configure $eb.text.xscroll -sticky ew -row 2 -column 0
600 }
601
602 proc parser-control-ok-core {w base background show} {
603     debug "parser-control-ok-core $w $base $background $show"
604     upvar #0 deffont_$base deffont
605     $w.resframe.res configure \
606         -background $background -disabledforeground black -font $deffont \
607         -state disabled -command {} \
608         -text $show
609 }    
610 proc parser-control-ok {w base show} {
611     parser-control-ok-core $w $base green $show
612 }
613 proc parser-control-none {w base show} {
614     parser-control-ok-core $w $base blue $show
615 }
616 proc parser-control-failed-core {w base foreground background smallfont
617                                  tiny summary fulldesc fulldata} {
618     debug "parser-control-failed-core $w $base $summary $fulldesc"
619     upvar #0 deffont_$base deffont
620     set eb .err_$base
621
622     $eb.emsg.text delete 0.0 end
623     $eb.emsg.text insert end $summary
624
625     $eb.text.lab configure -text $fulldesc
626     $eb.text.text delete 0.0 end
627     $eb.text.text insert end $fulldata
628
629     regsub -all {.{18}} $tiny "&\n" ewrap
630
631     if {$smallfont} {
632         set font fixed
633     } else {
634         set font $deffont
635     }
636
637     $w.resframe.res configure \
638         -background $background -foreground $foreground -font $font \
639         -state normal -command [list wm deiconify $eb] \
640         -text $ewrap
641 }
642     
643 proc parser-control-failed-expected {w base emsg lno ei fulldesc newdata} {
644     set eb .err_$base
645
646     set line [lindex [split $ei "\n"] 0]
647     debug "parser-control-failed-expected: $w $base: $lno: $emsg\n $line"
648
649     parser-control-failed-core $w $base \
650         white red 1 \
651         "err: [string trim $emsg]: \"$line\"" \
652         "at line $lno: $emsg" \
653         $fulldesc $newdata
654
655     $eb.text.text tag add error $lno.0 $lno.end
656     $eb.text.text see $lno.0    
657 }
658 proc parser-control-failed-unexpected {w base emsg ei} {
659     global errorInfo
660     parser-control-failed-core $w $base \
661         black yellow 1 \
662         $emsg $emsg "Details and stack trace:" $ei
663 }
664
665 proc reparse {base varname old fulldesc okshow noneshow parse ok} {
666     upvar #0 $varname var
667     manyset [errexpect-catch {
668         uplevel 1 $parse
669         if {[string length [string trim $var]]} {
670             parser-control-ok .ctrl.$base $base $okshow
671         } else {
672             parser-control-none .ctrl.$base $base $noneshow
673         }
674     }] failed emsg lno ei
675     if {$failed} {
676         parser-control-failed-expected .ctrl.$base $base \
677             $emsg $lno $ei $fulldesc $var
678         set var $old
679         uplevel 1 $parse
680     } else {
681         uplevel 1 $ok
682     }
683 }
684
685 #---------- main user interface ----------
686
687 proc widgets-setup {} {
688     global canvas debug pirate ocean
689
690     wm geometry . 1024x480
691     wm title . "where-vessels - $pirate on the $ocean ocean"
692
693     #----- map -----
694
695     frame .f -border 1 -relief groove
696     set canvas .f.c
697     canvas $canvas
698     pack $canvas -expand 1 -fill both
699     pack .f -expand 1 -fill both -side left
700
701     #----- control panel -----
702
703     frame .ctrl
704     pack .ctrl -side left -anchor n
705
706     debug "BBOX [$canvas bbox all]"
707
708     panner::canvas-scroll-bbox .f.c
709     panner::create .ctrl.pan .f.c 120 120 $debug
710
711     pack .ctrl.pan -side top -pady 10 -padx 5
712     frame .ctrl.zoom
713     pack .ctrl.zoom -side top
714
715     button .ctrl.zoom.out -text - -font {Courier 16} -command {zoom /2}
716     button .ctrl.zoom.in  -text + -font {Courier 16} -command {zoom *2}
717     pack .ctrl.zoom.out .ctrl.zoom.in -side left
718
719     parser-control-create .ctrl.acquire \
720         acquire Acquire \
721         "Clipboard parsing error" \
722         
723     pack .ctrl.acquire -side top -pady 2
724
725     parser-control-create .ctrl.notes \
726         notes "Reload notes" \
727         "Vessel notes loading report" \
728         
729     pack .ctrl.notes -side top -pady 2
730
731     #----- decoding etc. report -----
732
733     frame .report
734     pack .report -side left -anchor n
735
736     label .report.island -text { }
737
738     frame .report.abbrev -background black
739     glset report_abbrev {         }
740     entry .report.abbrev.abbrev -state readonly \
741         -textvariable report_abbrev \
742         -borderwidth 0 -relief flat -width 0 \
743         -highlightbackground white \
744         -readonlybackground white -foreground black
745     pack .report.abbrev.abbrev -side left -padx 1 -pady 1
746
747     frame .report.code
748     label .report.code.lab -text Code:
749     glset report_code { }
750     entry .report.code.code -state readonly -textvariable report_code -width 15
751     pack .report.code.lab .report.code.code -side left
752     frame .report.details -bd 2 -relief groove -padx 2 -pady 2
753
754     listbox .report.list -height 5
755
756     pack .report.island .report.abbrev .report.details \
757         .report.list .report.code -side top
758     pack configure .report.details -fill x
759
760     foreach sw {inport class subclass lock own xabbrev} {
761         label .report.details.$sw -text { }
762         pack .report.details.$sw -side top -anchor w
763     }
764 }
765
766 proc report-set {sw val} { .report.details.$sw configure -text $val }
767
768 proc zoom {extail} {
769     global scale canvas
770     set nscale [expr "\$scale $extail"]
771     debug "ZOOM $scale $nscale"
772     if {$nscale < 1 || $nscale > 200} return
773     set scale $nscale
774     draw
775 }
776
777 proc invoke_acquire {} {
778     global clipboard errorInfo
779     set old $clipboard
780
781     if {[catch {
782         set clipboard [clipboard get]
783     } emsg]} {
784         parser-control-failed-unexpected .ctrl.acquire acquire \
785             $emsg "fetching clipboard:\n\n$errorInfo"
786         return
787     }
788
789     reparse acquire \
790         clipboard $old "Clipboard contents:" { acquired ok } { no vessels } {
791             parse-clipboard
792         } {
793             display-note-infos
794         }
795     draw
796 }
797
798 proc invoke_notes {} {
799     global notes_data errorInfo notes_loc
800     set old $notes_data
801     
802     if {[catch {
803         load-notes
804     } emsg]} {
805         parser-control-failed-unexpected .ctrl.notes notes \
806             $emsg "loading $notes_loc:\n\n$errorInfo"
807         return
808     }
809
810     reparse notes \
811         notes_data $old "Vessel notes:" "loaded ok" { no notes } {
812             parse-notes
813             parse-clipboard
814         } {
815             display-note-infos
816         }
817     draw
818 }
819
820 #---------- main program ----------
821
822 vesselclasses-init
823
824 parseargs
825 argdefaults
826 httpclientsetup where-vessels
827 load-chart
828 widgets-setup
829
830 set notes_data {}
831 if {[catch { parse-clipboard } emsg]} {
832     puts stderr "$emsg\n$errorInfo"
833     exit 1
834 }
835 after idle invoke_notes
836
837 draw