3 # Revision 1.16 1995-03-31 08:56:36 adam
6 # Revision 1.15 1995/03/28 12:45:22 adam
7 # New ir method failback: called on disconnect/protocol error.
8 # New ir set/get method: protocol: SR / Z3950.
9 # Simple popup and disconnect when failback is invoked.
11 # Revision 1.14 1995/03/22 16:07:55 adam
14 # Revision 1.13 1995/03/21 17:27:26 adam
15 # Short-hand keys in setup.
17 # Revision 1.12 1995/03/21 13:41:03 adam
18 # Comstack cs_create not used too often. Non-blocking connect.
20 # Revision 1.11 1995/03/21 10:39:06 adam
21 # Diagnostic error message displayed with tkerror.
23 # Revision 1.10 1995/03/20 15:24:06 adam
24 # Diagnostic records saved on searchResponse.
26 # Revision 1.9 1995/03/17 18:26:16 adam
27 # Non-blocking i/o used now. Database names popup as cascade items.
29 # Revision 1.8 1995/03/17 15:45:00 adam
30 # Improved target/database setup.
32 # Revision 1.7 1995/03/16 17:54:03 adam
33 # Minor changes really.
35 # Revision 1.6 1995/03/15 19:10:20 adam
36 # Database setup in protocol-setup (rather target setup).
38 # Revision 1.5 1995/03/15 13:59:23 adam
41 # Revision 1.4 1995/03/14 17:32:29 adam
42 # Presentation of full Marc record in popup window.
44 # Revision 1.3 1995/03/12 19:31:52 adam
45 # Pattern matching implemented when retrieving MARC records. More
46 # diagnostic functions.
48 # Revision 1.2 1995/03/10 18:00:15 adam
49 # Actual presentation in line-by-line format. RPN query support.
51 # Revision 1.1 1995/03/09 16:15:07 adam
52 # First presentRequest attempts. Hot-target list.
59 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {}}
66 if {[file readable "~/.tk-c"]} {
70 proc top-down-window {w} {
71 frame $w.top -relief raised -border 1
72 frame $w.bot -relief raised -border 1
74 pack $w.top $w.bot -side top -fill both -expand yes
77 proc top-down-ok-cancel {w ok-action g} {
78 frame $w.bot.left -relief sunken -border 1
79 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
80 button $w.bot.left.ok -width 6 -text {Ok} \
82 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
83 button $w.bot.cancel -width 6 -text {Cancel} \
85 pack $w.bot.cancel -side left -expand yes
94 proc show-target {target} {
95 .bot.target configure -text "$target"
98 proc show-busy {v1 v2} {
101 .bot.status configure -fg $v1
102 after 200 [list show-busy $v2 $v1]
106 proc show-status {status b} {
109 .bot.status configure -text "$status"
110 .bot.status configure -fg black
116 # . config -cursor {watch black white}
118 # . config -cursor {top_left_arrow black white}
124 proc show-message {msg} {
125 .bot.message configure -text "$msg"
128 proc insertWithTags {w text args} {
129 set start [$w index insert]
130 $w insert insert $text
131 foreach tag [$w tag names $start] {
132 $w tag remove $tag $start insert
135 $w tag add $i $start insert
139 proc show-full-marc {no} {
144 if {[winfo exists $w]} {
145 $w.top.record delete 0.0 end
151 wm minsize $w 200 200
153 frame $w.top -relief raised -border 1
154 frame $w.bot -relief raised -border 1
156 pack $w.top -side top -fill both -expand yes
157 pack $w.bot -fill both
159 text $w.top.record -width 60 -height 12 -wrap word \
160 -yscrollcommand [list $w.top.s set]
161 scrollbar $w.top.s -command [list $w.top.record yview]
167 set r [z39.$setNo recordMarc $no line * * *]
169 $w.top.record tag configure marc-tag -foreground blue
170 $w.top.record tag configure marc-data -foreground black
171 $w.top.record tag configure marc-id -foreground red
174 set tag [lindex $line 0]
175 set indicator [lindex $line 1]
176 set fields [lindex $line 2]
178 if {$indicator != ""} {
179 insertWithTags $w.top.record "$tag $indicator" marc-tag
181 insertWithTags $w.top.record "$tag " marc-tag
183 foreach field $fields {
184 set id [lindex $field 0]
185 set data [lindex $field 1]
187 insertWithTags $w.top.record " $id " marc-id
189 set start [$w.top.record index insert]
190 insertWithTags $w.top.record $data {}
192 $w.top.record insert end "\n"
195 bind $w <Return> {destroy .full-marc}
197 pack $w.top.s -side right -fill y
198 pack $w.top.record -expand yes -fill both
200 frame $w.bot.left -relief sunken -border 1
201 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
202 button $w.bot.left.close -width 6 -text {Close} \
203 -command {destroy .full-marc}
204 pack $w.bot.left.close -expand yes -padx 3 -pady 3
205 button $w.bot.edit -width 6 -text {Edit} \
206 -command {destroy .full-marc}
207 pack $w.bot.edit -side left -expand yes
211 proc update-target-hotlist {target} {
214 set len [llength $hotTargets]
216 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
218 set indx [lsearch $hotTargets $target]
220 set hotTargets [lreplace $hotTargets $indx $indx]
222 set hotTargets [linsert $hotTargets 0 $target]
226 proc set-target-hotlist {} {
230 foreach target $hotTargets {
231 .top.target.m add command -label "$i $target" -command \
232 "menu-open-target $target {}"
240 proc menu-open-target {target base} {
241 open-target $target $base
242 update-target-hotlist $target
245 proc define-target-action {} {
248 set target [.target-define.top.target.entry get]
252 update-target-hotlist $target
253 foreach n [array names profile] {
259 set profile($target) $profile(Default)
260 protocol-setup $target
261 destroy .target-define
264 proc fail-response {target} {
266 tkerror "Target connection closed or protocol error"
269 proc connect-response {target} {
270 puts "connect-response"
275 proc open-target {target base} {
280 z39 comstack [lindex $profile($target) 6]
281 # z39 idAuthentication [lindex $profile($target) 3]
282 z39 maximumRecordSize [lindex $profile($target) 4]
283 z39 preferredMessageSize [lindex $profile($target) 5]
284 puts -nonewline "maximumRecordSize="
285 puts [z39 maximumRecordSize]
286 puts -nonewline "preferredMessageSize="
287 puts [z39 preferredMessageSize]
289 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
291 z39 databaseNames $base
293 z39 failback [list fail-response $target]
294 z39 callback [list connect-response $target]
295 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
296 show-status {Connecting} 1
298 .top.target.m disable 0
299 .top.target.m enable 1
302 proc close-target {} {
308 show-status {Not connected} 0
310 .top.target.m disable 1
311 .top.target.m enable 0
314 proc load-set-action {} {
320 set fname [.load-set.top.filename.entry get]
325 show-status {Loading} 1
326 z39.$setNo loadFile $fname
328 set no [z39.$setNo numberOfRecordsReturned]
329 add-title-lines $setNo $no 1
331 show-status {Ready} 0
344 frame $w.top.filename
346 pack $w.top.filename -side top -anchor e -pady 2
348 entry-fields $w.top {filename} \
350 {load-set-action} {destroy .load-set}
352 top-down-ok-cancel $w {load-set-action} 1
356 proc init-request {} {
359 z39 callback {init-response}
361 show-status {Initializing} 1
364 proc init-response {} {
365 show-status {Ready} 0
366 bind .mid.searchentry <Return> search-request
367 focus .mid.searchentry
370 proc search-request {} {
380 if {[lindex $profile($target) 10]} {
381 z39.$setNo setName $setNo
383 if {[lindex $profile($target) 8]} {
386 if {[lindex $profile($target) 9]} {
389 z39 callback {search-response}
390 z39.$setNo search [.mid.searchentry get]
391 show-status {Search} 1
394 proc search-response {} {
400 show-status {Ready} 0
401 show-message "[z39.$setNo resultCount] hits"
402 set setMax [z39.$setNo resultCount]
405 set status [z39.$setNo responseStatus]
406 if {[lindex $status 0] == "NSD"} {
407 set code [lindex $status 1]
408 set msg [lindex $status 2]
409 set addinfo [lindex $status 3]
410 tkerror "NSD$code: $msg: $addinfo"
417 z39 callback {present-response}
419 z39.$setNo present $setOffset $setMax
420 show-status {Retrieve} 1
423 proc present-more {number} {
429 set max [z39.$setNo resultCount]
430 if {$max <= $setMax} {
434 puts "setOffset=$setOffset"
440 z39 callback {present-response}
441 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
442 show-status {Retrieve} 1
445 proc init-title-lines {} {
446 .data.list delete 0 end
449 proc add-title-lines {setno no offset} {
450 for {set i 0} {$i < $no} {incr i} {
451 set o [expr $i + $offset]
452 set title [lindex [z39.$setno recordMarc $o field 245 * a] 0]
453 set year [lindex [z39.$setno recordMarc $o field 260 * c] 0]
454 set nostr [format "%3d" $o]
455 .data.list insert end "$nostr $title - $year"
459 proc present-response {} {
464 puts "In present-response"
465 set no [z39.$setNo numberOfRecordsReturned]
466 puts "Returned $no records, setOffset $setOffset"
467 add-title-lines $setNo $no $setOffset
468 set setOffset [expr $setOffset + $no]
469 set status [z39.$setNo responseStatus]
470 if {[lindex $status 0] == "NSD"} {
471 show-status {Ready} 0
472 set code [lindex $status 1]
473 set msg [lindex $status 2]
474 set addinfo [lindex $status 3]
475 tkerror "NSD$code: $msg: $addinfo"
478 if {$no > 0 && $setOffset <= $setMax} {
479 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
481 show-status {Finished} 0
485 proc left-cursor {w} {
486 set i [$w index insert]
493 proc right-cursor {w} {
494 set i [$w index insert]
499 proc bind-fields {list returnAction escapeAction} {
500 set max [expr [llength $list]-1]
501 for {set i 0} {$i < $max} {incr i} {
502 bind [lindex $list $i] <Return> $returnAction
503 bind [lindex $list $i] <Escape> $escapeAction
504 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
505 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
506 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
508 bind [lindex $list $i] <Return> $returnAction
509 bind [lindex $list $i] <Escape> $escapeAction
510 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
511 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
512 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
513 focus [lindex $list 0]
516 proc entry-fields {parent list tlist returnAction escapeAction} {
519 foreach field $list {
520 set label ${parent}.${field}.label
521 set entry ${parent}.${field}.entry
522 label $label -text [lindex $tlist $i] -anchor e
523 entry $entry -width 32 -relief sunken
524 pack $label -side left
525 pack $entry -side right
529 bind-fields $alist $returnAction $escapeAction
532 proc define-target-dialog {} {
544 -side top -anchor e -pady 2
546 entry-fields $w.top {target} \
548 {define-target-action} {destroy .target-define}
550 top-down-ok-cancel $w {define-target-action} 1
553 proc protocol-setup-action {target} {
556 global settingsChanged
559 global ResultSetCheck
561 set w .setup-${target}.top
563 #set w .protocol-setup.top
566 set settingsChanged 1
567 set len [$w.databases.list size]
568 for {set i 0} {$i < $len} {incr i} {
569 lappend b [$w.databases.list get $i]
571 set profile($target) [list [$w.description.entry get] \
572 [$w.host.entry get] \
573 [$w.port.entry get] \
574 [$w.idAuthentication.entry get] \
575 [$w.maximumRecordSize.entry get] \
576 [$w.preferredMessageSize.entry get] \
584 puts $profile($target)
585 destroy .setup-${target}
589 proc place-force {window parent} {
590 set g [wm geometry $parent]
592 set p1 [string first + $g]
593 set p2 [string last + $g]
595 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
596 set y [expr 60+[string range $g [expr $p2 +1] end]]
597 wm geometry $window +${x}+${y}
601 proc add-database-action {target} {
602 set w .setup-${target}
604 ${w}.top.databases.list insert end \
605 [.database-select.top.database.entry get]
606 destroy .database-select
609 proc add-database {target} {
610 set w .database-select
615 place-force $w .setup-${target}
619 frame $w.top.database
621 pack $w.top.database -side top -anchor e -pady 2
623 entry-fields $w.top {database} \
624 {{Database to add:}} \
625 [list add-database-action $target] {destroy .database-select}
627 top-down-ok-cancel $w [list add-database-action $target] 1
631 proc delete-database {target} {
632 set w .setup-${target}
634 foreach i [lsort -decreasing \
635 [$w.top.databases.list curselection]] {
636 $w.top.databases.list delete $i
640 proc protocol-setup {target} {
647 global ResultSetCheck
651 wm title $w "Setup $target"
660 puts $profile($target)
664 frame $w.top.description
665 frame $w.top.idAuthentication
666 frame $w.top.maximumRecordSize
667 frame $w.top.preferredMessageSize
668 frame $w.top.cs-type -relief ridge -border 2
669 frame $w.top.query -relief ridge -border 2
670 frame $w.top.databases -relief ridge -border 2
672 # Maximum/preferred/idAuth ...
673 pack $w.top.description $w.top.host $w.top.port \
674 $w.top.idAuthentication $w.top.maximumRecordSize \
675 $w.top.preferredMessageSize -side top -anchor e -pady 2
677 entry-fields $w.top {description host port idAuthentication \
678 maximumRecordSize preferredMessageSize} \
679 {{Description:} {Host:} {Port:} {Id Authentification:} \
680 {Maximum Record Size:} {Preferred Message Size:}} \
681 [list protocol-setup-action $target] [list destroy $w]
683 foreach sub {description host port idAuthentication \
684 maximumRecordSize preferredMessageSize} {
686 bind $w.top.$sub.entry <Control-a> "add-database $target"
687 bind $w.top.$sub.entry <Control-d> "delete-database $target"
689 $w.top.description.entry insert 0 [lindex $profile($target) 0]
690 $w.top.host.entry insert 0 [lindex $profile($target) 1]
691 $w.top.port.entry insert 0 [lindex $profile($target) 2]
692 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
693 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
694 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
695 set csRadioType [lindex $profile($target) 6]
696 set RPNCheck [lindex $profile($target) 8]
697 set CCLCheck [lindex $profile($target) 9]
698 set ResultSetCheck [lindex $profile($target) 10]
701 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
703 label $w.top.databases.label -text "Databases"
704 button $w.top.databases.add -text "Add" \
705 -command "add-database $target"
706 button $w.top.databases.delete -text "Delete" \
707 -command "delete-database $target"
708 listbox $w.top.databases.list -geometry 20x6 \
709 -yscrollcommand "$w.top.databases.scroll set"
710 scrollbar $w.top.databases.scroll -orient vertical -border 1
711 pack $w.top.databases.label -side top -fill x \
713 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
715 pack $w.top.databases.list -side left -fill both -expand yes \
717 pack $w.top.databases.scroll -side right -fill y \
719 $w.top.databases.scroll config -command "$w.top.databases.list yview"
721 foreach b [lindex $profile($target) 7] {
722 $w.top.databases.list insert end $b
726 pack $w.top.cs-type -pady 6 -padx 6 -side top
728 label $w.top.cs-type.label -text "Transport"
729 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
730 -command {puts tcp/ip} -variable csRadioType -value tcpip
731 radiobutton $w.top.cs-type.mosi -text "MOSI" \
732 -command {puts mosi} -variable csRadioType -value mosi
734 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
735 -padx 4 -side top -fill x
738 pack $w.top.query -pady 6 -padx 6 -side top
740 label $w.top.query.label -text "Query support" -anchor e
741 checkbutton $w.top.query.c1 -text "RPN query" -variable RPNCheck
742 checkbutton $w.top.query.c2 -text "CCL query" -variable CCLCheck
743 checkbutton $w.top.query.c3 -text "Result sets" -variable ResultSetCheck
745 pack $w.top.query.label -side top
746 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
747 -padx 4 -side top -fill x
750 top-down-ok-cancel $w [list protocol-setup-action $target] 0
753 proc database-select-action {} {
754 set w .database-select.top
756 foreach indx [$w.databases.list curselection] {
757 lappend b [$w.databases.list get $indx]
762 destroy .database-select
765 proc database-select {} {
766 set w .database-select
776 frame $w.top.databases -relief ridge -border 2
778 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
780 label $w.top.databases.label -text "List"
781 listbox $w.top.databases.list -geometry 20x6 \
782 -yscrollcommand "$w.top.databases.scroll set"
783 scrollbar $w.top.databases.scroll -orient vertical -border 1
784 pack $w.top.databases.label -side top -fill x \
786 pack $w.top.databases.list -side left -fill both -expand yes \
788 pack $w.top.databases.scroll -side right -fill y \
790 $w.top.databases.scroll config -command "$w.top.databases.list yview"
792 foreach b [lindex $profile($hostid) 7] {
793 $w.top.databases.list insert end $b
795 top-down-ok-cancel $w {database-select-action} 1
798 proc cascade-target-list {} {
801 foreach sub [winfo children .top.target.m.clist] {
805 .top.target.m.clist delete 0 last
806 foreach n [array names profile] {
807 if {$n != "Default"} {
808 set nl [string tolower $n]
809 if {[llength [lindex $profile($n) 7]] > 1} {
810 .top.target.m.clist add cascade -label $n \
811 -menu .top.target.m.clist.$nl
812 menu .top.target.m.clist.$nl
813 foreach b [lindex $profile($n) 7] {
814 .top.target.m.clist.$nl add command -label $b \
815 -command "menu-open-target $n $b"
818 .top.target.m.clist add command -label $n \
819 -command "menu-open-target $n {}"
823 .top.target.m.slist delete 0 last
824 foreach n [array names profile] {
825 if {$n != "Default"} {
826 .top.target.m.slist add command -label $n \
827 -command "protocol-setup $n"
832 proc save-settings {} {
835 global settingsChanged
837 set f [open "~/.tk-c" w]
838 puts $f "# Setup file"
839 puts $f "set hotTargets \{ $hotTargets \}"
841 foreach n [array names profile] {
842 puts -nonewline $f "set profile($n) \{"
843 puts -nonewline $f $profile($n)
847 set settingsChanged 0
859 message $w.top.message -text $ask
861 pack $w.top.message -side left -pady 6 -padx 20 -expand yes -fill x
864 top-down-ok-cancel $w {alert-action} 1
868 proc alert-action {} {
874 proc exit-action {} {
875 global settingsChanged
877 if {$settingsChanged} {
878 set a [alert "you havent saved your settings. Do you wish to save?"]
886 frame .top -border 1 -relief raised
887 frame .mid -border 1 -relief raised
888 frame .data -border 1 -relief raised
889 frame .bot -border 1 -relief raised
890 pack .top .mid -side top -fill x
891 pack .data -side top -fill both -expand yes
894 menubutton .top.file -text "File" -underline 0 -menu .top.file.m
896 .top.file.m add command -label "Save settings" -command {save-settings}
897 .top.file.m add command -label "Load Set" -command {load-set}
898 .top.file.m add separator
899 .top.file.m add command -label "Exit" -command {exit-action}
901 menubutton .top.target -text "Target" -underline 0 -menu .top.target.m
903 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
904 .top.target.m add command -label "Disconnect" -command {close-target}
905 #.top.target.m add command -label "Initialize" -command {init-request}
906 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
907 .top.target.m add command -label "Setup new" -command {define-target-dialog}
908 .top.target.m add separator
911 .top.target.m disable 1
913 menu .top.target.m.clist
914 menu .top.target.m.slist
917 menubutton .top.search -text "Search" -underline 0 -menu .top.search.m
919 .top.search.m add command -label "Database" -command {database-select}
920 .top.search.m add cascade -label "Query type" -menu .top.search.m.querytype
921 menu .top.search.m.querytype
922 .top.search.m.querytype add radiobutton -label "RPN"
923 .top.search.m.querytype add radiobutton -label "CCL"
924 .top.search.m add cascade -label "Present" -menu .top.search.m.present
925 menu .top.search.m.present
926 .top.search.m.present add command -label "More" -command [list present-more 10]
927 .top.search.m.present add command -label "All" -command [list present-more {}]
929 menubutton .top.help -text "Help" -menu .top.help.m
932 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
933 .top.help.m add command -label "About" -command {puts "About"}
935 pack .top.file .top.target .top.search -side left
936 pack .top.help -side right
938 label .mid.searchlabel -text {Search:}
939 entry .mid.searchentry -width 32 -relief sunken
940 pack .mid.searchlabel -side left
941 pack .mid.searchentry -side left -fill x -expand yes
943 focus .mid.searchentry
944 bind .mid.searchentry <Left> {left-cursor .mid.searchentry}
945 bind .mid.searchentry <Right> {right-cursor .mid.searchentry}
947 listbox .data.list -yscrollcommand {.data.scroll set}
948 scrollbar .data.scroll -orient vertical -border 1
949 pack .data.list -side left -fill both -expand yes
950 pack .data.scroll -side right -fill y
951 .data.scroll config -command {.data.list yview}
953 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
954 label .bot.status -text "Not connected" -width 12 -relief \
955 sunken -anchor w -border 1
956 label .bot.set -textvariable setNo -width 5 -relief \
957 sunken -anchor w -border 1
958 label .bot.message -text "" -width 14 -relief \
959 sunken -anchor w -border 1
960 pack .bot.target .bot.status .bot.set .bot.message -anchor nw \
961 -side left -padx 2 -pady 2
963 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
964 show-full-marc $indx}