3 # Revision 1.18 1995-04-10 10:50:22 adam
4 # Result-set name defaults to suffix of ir-set name.
5 # Started working on scan. Not finished at this point.
7 # Revision 1.17 1995/03/31 09:34:57 adam
8 # Search-button disabled when there is no connection.
10 # Revision 1.16 1995/03/31 08:56:36 adam
11 # New button "Search".
13 # Revision 1.15 1995/03/28 12:45:22 adam
14 # New ir method failback: called on disconnect/protocol error.
15 # New ir set/get method: protocol: SR / Z3950.
16 # Simple popup and disconnect when failback is invoked.
18 # Revision 1.14 1995/03/22 16:07:55 adam
21 # Revision 1.13 1995/03/21 17:27:26 adam
22 # Short-hand keys in setup.
24 # Revision 1.12 1995/03/21 13:41:03 adam
25 # Comstack cs_create not used too often. Non-blocking connect.
27 # Revision 1.11 1995/03/21 10:39:06 adam
28 # Diagnostic error message displayed with tkerror.
30 # Revision 1.10 1995/03/20 15:24:06 adam
31 # Diagnostic records saved on searchResponse.
33 # Revision 1.9 1995/03/17 18:26:16 adam
34 # Non-blocking i/o used now. Database names popup as cascade items.
36 # Revision 1.8 1995/03/17 15:45:00 adam
37 # Improved target/database setup.
39 # Revision 1.7 1995/03/16 17:54:03 adam
40 # Minor changes really.
42 # Revision 1.6 1995/03/15 19:10:20 adam
43 # Database setup in protocol-setup (rather target setup).
45 # Revision 1.5 1995/03/15 13:59:23 adam
48 # Revision 1.4 1995/03/14 17:32:29 adam
49 # Presentation of full Marc record in popup window.
51 # Revision 1.3 1995/03/12 19:31:52 adam
52 # Pattern matching implemented when retrieving MARC records. More
53 # diagnostic functions.
55 # Revision 1.2 1995/03/10 18:00:15 adam
56 # Actual presentation in line-by-line format. RPN query support.
58 # Revision 1.1 1995/03/09 16:15:07 adam
59 # First presentRequest attempts. Hot-target list.
66 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {}}
73 if {[file readable "~/.tk-c"]} {
77 proc top-down-window {w} {
78 frame $w.top -relief raised -border 1
79 frame $w.bot -relief raised -border 1
81 pack $w.top $w.bot -side top -fill both -expand yes
84 proc top-down-ok-cancel {w ok-action g} {
85 frame $w.bot.left -relief sunken -border 1
86 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
87 button $w.bot.left.ok -width 6 -text {Ok} \
89 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
90 button $w.bot.cancel -width 6 -text {Cancel} \
92 pack $w.bot.cancel -side left -expand yes
101 proc show-target {target} {
102 .bot.target configure -text "$target"
105 proc show-busy {v1 v2} {
108 .bot.status configure -fg $v1
109 after 200 [list show-busy $v2 $v1]
113 proc show-status {status b} {
116 .bot.status configure -text "$status"
117 .bot.status configure -fg black
123 # . config -cursor {watch black white}
125 # . config -cursor {top_left_arrow black white}
131 proc show-message {msg} {
132 .bot.message configure -text "$msg"
135 proc insertWithTags {w text args} {
136 set start [$w index insert]
137 $w insert insert $text
138 foreach tag [$w tag names $start] {
139 $w tag remove $tag $start insert
142 $w tag add $i $start insert
146 proc show-full-marc {no} {
151 if {[winfo exists $w]} {
152 $w.top.record delete 0.0 end
158 wm minsize $w 200 200
160 frame $w.top -relief raised -border 1
161 frame $w.bot -relief raised -border 1
163 pack $w.top -side top -fill both -expand yes
164 pack $w.bot -fill both
166 text $w.top.record -width 60 -height 12 -wrap word \
167 -yscrollcommand [list $w.top.s set]
168 scrollbar $w.top.s -command [list $w.top.record yview]
174 set r [z39.$setNo recordMarc $no line * * *]
176 $w.top.record tag configure marc-tag -foreground blue
177 $w.top.record tag configure marc-data -foreground black
178 $w.top.record tag configure marc-id -foreground red
181 set tag [lindex $line 0]
182 set indicator [lindex $line 1]
183 set fields [lindex $line 2]
185 if {$indicator != ""} {
186 insertWithTags $w.top.record "$tag $indicator" marc-tag
188 insertWithTags $w.top.record "$tag " marc-tag
190 foreach field $fields {
191 set id [lindex $field 0]
192 set data [lindex $field 1]
194 insertWithTags $w.top.record " $id " marc-id
196 set start [$w.top.record index insert]
197 insertWithTags $w.top.record $data {}
199 $w.top.record insert end "\n"
202 bind $w <Return> {destroy .full-marc}
204 pack $w.top.s -side right -fill y
205 pack $w.top.record -expand yes -fill both
207 frame $w.bot.left -relief sunken -border 1
208 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
209 button $w.bot.left.close -width 6 -text {Close} \
210 -command {destroy .full-marc}
211 pack $w.bot.left.close -expand yes -padx 3 -pady 3
212 button $w.bot.edit -width 6 -text {Edit} \
213 -command {destroy .full-marc}
214 pack $w.bot.edit -side left -expand yes
218 proc update-target-hotlist {target} {
221 set len [llength $hotTargets]
223 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
225 set indx [lsearch $hotTargets $target]
227 set hotTargets [lreplace $hotTargets $indx $indx]
229 set hotTargets [linsert $hotTargets 0 $target]
233 proc set-target-hotlist {} {
237 foreach target $hotTargets {
238 .top.target.m add command -label "$i $target" -command \
239 "reopen-target $target {}"
247 proc reopen-target {target base} {
249 open-target $target $base
250 update-target-hotlist $target
253 proc define-target-action {} {
256 set target [.target-define.top.target.entry get]
260 update-target-hotlist $target
261 foreach n [array names profile] {
267 set profile($target) $profile(Default)
268 protocol-setup $target
269 destroy .target-define
272 proc fail-response {target} {
274 tkerror "Target connection closed or protocol error"
277 proc connect-response {target} {
278 puts "connect-response"
283 proc open-target {target base} {
288 z39 comstack [lindex $profile($target) 6]
289 # z39 idAuthentication [lindex $profile($target) 3]
290 z39 maximumRecordSize [lindex $profile($target) 4]
291 z39 preferredMessageSize [lindex $profile($target) 5]
292 puts -nonewline "maximumRecordSize="
293 puts [z39 maximumRecordSize]
294 puts -nonewline "preferredMessageSize="
295 puts [z39 preferredMessageSize]
297 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
299 z39 databaseNames $base
301 z39 failback [list fail-response $target]
302 z39 callback [list connect-response $target]
303 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
304 show-status {Connecting} 1
306 .top.target.m disable 0
307 .top.target.m enable 1
308 .top.search configure -state normal
311 proc close-target {} {
317 show-status {Not connected} 0
319 .top.target.m disable 1
320 .top.target.m enable 0
321 .top.search configure -state disabled
324 proc load-set-action {} {
330 set fname [.load-set.top.filename.entry get]
335 show-status {Loading} 1
336 z39.$setNo loadFile $fname
338 set no [z39.$setNo numberOfRecordsReturned]
339 add-title-lines $setNo $no 1
341 show-status {Ready} 0
354 frame $w.top.filename
356 pack $w.top.filename -side top -anchor e -pady 2
358 entry-fields $w.top {filename} \
360 {load-set-action} {destroy .load-set}
362 top-down-ok-cancel $w {load-set-action} 1
366 proc init-request {} {
369 z39 callback {init-response}
371 show-status {Initializing} 1
374 proc init-response {} {
375 show-status {Ready} 0
376 bind .mid.searchentry <Return> search-request
377 focus .mid.searchentry
380 proc search-request {} {
390 if {[lindex $profile($target) 10]} {
391 z39.$setNo setName $setNo
393 z39.$setNo setName Default
395 if {[lindex $profile($target) 8]} {
398 if {[lindex $profile($target) 9]} {
401 z39 callback {search-response}
402 z39.$setNo search [.mid.searchentry get]
403 show-status {Search} 1
406 proc search-response {} {
412 show-status {Ready} 0
413 show-message "[z39.$setNo resultCount] hits"
414 set setMax [z39.$setNo resultCount]
417 set status [z39.$setNo responseStatus]
418 if {[lindex $status 0] == "NSD"} {
419 set code [lindex $status 1]
420 set msg [lindex $status 2]
421 set addinfo [lindex $status 3]
422 tkerror "NSD$code: $msg: $addinfo"
429 z39 callback {present-response}
431 z39.$setNo present $setOffset $setMax
432 show-status {Retrieve} 1
435 proc present-more {number} {
444 set max [z39.$setNo resultCount]
445 if {$max <= $setMax} {
449 puts "setOffset=$setOffset"
455 z39 callback {present-response}
456 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
457 show-status {Retrieve} 1
460 proc init-title-lines {} {
461 .data.list delete 0 end
464 proc add-title-lines {setno no offset} {
465 for {set i 0} {$i < $no} {incr i} {
466 set o [expr $i + $offset]
467 set title [lindex [z39.$setno recordMarc $o field 245 * a] 0]
468 set year [lindex [z39.$setno recordMarc $o field 260 * c] 0]
469 set nostr [format "%3d" $o]
470 .data.list insert end "$nostr $title - $year"
474 proc present-response {} {
479 puts "In present-response"
480 set no [z39.$setNo numberOfRecordsReturned]
481 puts "Returned $no records, setOffset $setOffset"
482 add-title-lines $setNo $no $setOffset
483 set setOffset [expr $setOffset + $no]
484 set status [z39.$setNo responseStatus]
485 if {[lindex $status 0] == "NSD"} {
486 show-status {Ready} 0
487 set code [lindex $status 1]
488 set msg [lindex $status 2]
489 set addinfo [lindex $status 3]
490 tkerror "NSD$code: $msg: $addinfo"
493 if {$no > 0 && $setOffset <= $setMax} {
494 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
496 show-status {Finished} 0
500 proc left-cursor {w} {
501 set i [$w index insert]
508 proc right-cursor {w} {
509 set i [$w index insert]
514 proc bind-fields {list returnAction escapeAction} {
515 set max [expr [llength $list]-1]
516 for {set i 0} {$i < $max} {incr i} {
517 bind [lindex $list $i] <Return> $returnAction
518 bind [lindex $list $i] <Escape> $escapeAction
519 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
520 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
521 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
523 bind [lindex $list $i] <Return> $returnAction
524 bind [lindex $list $i] <Escape> $escapeAction
525 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
526 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
527 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
528 focus [lindex $list 0]
531 proc entry-fields {parent list tlist returnAction escapeAction} {
534 foreach field $list {
535 set label ${parent}.${field}.label
536 set entry ${parent}.${field}.entry
537 label $label -text [lindex $tlist $i] -anchor e
538 entry $entry -width 32 -relief sunken
539 pack $label -side left
540 pack $entry -side right
544 bind-fields $alist $returnAction $escapeAction
547 proc define-target-dialog {} {
559 -side top -anchor e -pady 2
561 entry-fields $w.top {target} \
563 {define-target-action} {destroy .target-define}
565 top-down-ok-cancel $w {define-target-action} 1
568 proc protocol-setup-action {target} {
571 global settingsChanged
574 global ResultSetCheck
576 set w .setup-${target}.top
578 #set w .protocol-setup.top
581 set settingsChanged 1
582 set len [$w.databases.list size]
583 for {set i 0} {$i < $len} {incr i} {
584 lappend b [$w.databases.list get $i]
586 set profile($target) [list [$w.description.entry get] \
587 [$w.host.entry get] \
588 [$w.port.entry get] \
589 [$w.idAuthentication.entry get] \
590 [$w.maximumRecordSize.entry get] \
591 [$w.preferredMessageSize.entry get] \
599 puts $profile($target)
600 destroy .setup-${target}
603 proc place-force {window parent} {
604 set g [wm geometry $parent]
606 set p1 [string first + $g]
607 set p2 [string last + $g]
609 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
610 set y [expr 60+[string range $g [expr $p2 +1] end]]
611 wm geometry $window +${x}+${y}
614 proc add-database-action {target} {
615 set w .setup-${target}
617 ${w}.top.databases.list insert end \
618 [.database-select.top.database.entry get]
619 destroy .database-select
622 proc add-database {target} {
623 set w .database-select
628 place-force $w .setup-${target}
632 frame $w.top.database
634 pack $w.top.database -side top -anchor e -pady 2
636 entry-fields $w.top {database} \
637 {{Database to add:}} \
638 [list add-database-action $target] {destroy .database-select}
640 top-down-ok-cancel $w [list add-database-action $target] 1
644 proc delete-database {target} {
645 set w .setup-${target}
647 foreach i [lsort -decreasing \
648 [$w.top.databases.list curselection]] {
649 $w.top.databases.list delete $i
653 proc protocol-setup {target} {
660 global ResultSetCheck
664 wm title $w "Setup $target"
673 puts $profile($target)
677 frame $w.top.description
678 frame $w.top.idAuthentication
679 frame $w.top.maximumRecordSize
680 frame $w.top.preferredMessageSize
681 frame $w.top.cs-type -relief ridge -border 2
682 frame $w.top.query -relief ridge -border 2
683 frame $w.top.databases -relief ridge -border 2
685 # Maximum/preferred/idAuth ...
686 pack $w.top.description $w.top.host $w.top.port \
687 $w.top.idAuthentication $w.top.maximumRecordSize \
688 $w.top.preferredMessageSize -side top -anchor e -pady 2
690 entry-fields $w.top {description host port idAuthentication \
691 maximumRecordSize preferredMessageSize} \
692 {{Description:} {Host:} {Port:} {Id Authentification:} \
693 {Maximum Record Size:} {Preferred Message Size:}} \
694 [list protocol-setup-action $target] [list destroy $w]
696 foreach sub {description host port idAuthentication \
697 maximumRecordSize preferredMessageSize} {
699 bind $w.top.$sub.entry <Control-a> "add-database $target"
700 bind $w.top.$sub.entry <Control-d> "delete-database $target"
702 $w.top.description.entry insert 0 [lindex $profile($target) 0]
703 $w.top.host.entry insert 0 [lindex $profile($target) 1]
704 $w.top.port.entry insert 0 [lindex $profile($target) 2]
705 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
706 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
707 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
708 set csRadioType [lindex $profile($target) 6]
709 set RPNCheck [lindex $profile($target) 8]
710 set CCLCheck [lindex $profile($target) 9]
711 set ResultSetCheck [lindex $profile($target) 10]
714 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
716 label $w.top.databases.label -text "Databases"
717 button $w.top.databases.add -text "Add" \
718 -command "add-database $target"
719 button $w.top.databases.delete -text "Delete" \
720 -command "delete-database $target"
721 listbox $w.top.databases.list -geometry 20x6 \
722 -yscrollcommand "$w.top.databases.scroll set"
723 scrollbar $w.top.databases.scroll -orient vertical -border 1
724 pack $w.top.databases.label -side top -fill x \
726 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
728 pack $w.top.databases.list -side left -fill both -expand yes \
730 pack $w.top.databases.scroll -side right -fill y \
732 $w.top.databases.scroll config -command "$w.top.databases.list yview"
734 foreach b [lindex $profile($target) 7] {
735 $w.top.databases.list insert end $b
739 pack $w.top.cs-type -pady 6 -padx 6 -side top
741 label $w.top.cs-type.label -text "Transport"
742 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
743 -command {puts tcp/ip} -variable csRadioType -value tcpip
744 radiobutton $w.top.cs-type.mosi -text "MOSI" \
745 -command {puts mosi} -variable csRadioType -value mosi
747 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
748 -padx 4 -side top -fill x
751 pack $w.top.query -pady 6 -padx 6 -side top
753 label $w.top.query.label -text "Query support" -anchor e
754 checkbutton $w.top.query.c1 -text "RPN query" -variable RPNCheck
755 checkbutton $w.top.query.c2 -text "CCL query" -variable CCLCheck
756 checkbutton $w.top.query.c3 -text "Result sets" -variable ResultSetCheck
758 pack $w.top.query.label -side top
759 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
760 -padx 4 -side top -fill x
763 top-down-ok-cancel $w [list protocol-setup-action $target] 0
766 proc database-select-action {} {
767 set w .database-select.top
769 foreach indx [$w.databases.list curselection] {
770 lappend b [$w.databases.list get $indx]
775 destroy .database-select
778 proc database-select {} {
779 set w .database-select
789 frame $w.top.databases -relief ridge -border 2
791 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
793 label $w.top.databases.label -text "List"
794 listbox $w.top.databases.list -geometry 20x6 \
795 -yscrollcommand "$w.top.databases.scroll set"
796 scrollbar $w.top.databases.scroll -orient vertical -border 1
797 pack $w.top.databases.label -side top -fill x \
799 pack $w.top.databases.list -side left -fill both -expand yes \
801 pack $w.top.databases.scroll -side right -fill y \
803 $w.top.databases.scroll config -command "$w.top.databases.list yview"
805 foreach b [lindex $profile($hostid) 7] {
806 $w.top.databases.list insert end $b
808 top-down-ok-cancel $w {database-select-action} 1
811 proc cascade-target-list {} {
814 foreach sub [winfo children .top.target.m.clist] {
818 .top.target.m.clist delete 0 last
819 foreach n [array names profile] {
820 if {$n != "Default"} {
821 set nl [string tolower $n]
822 if {[llength [lindex $profile($n) 7]] > 1} {
823 .top.target.m.clist add cascade -label $n \
824 -menu .top.target.m.clist.$nl
825 menu .top.target.m.clist.$nl
826 foreach b [lindex $profile($n) 7] {
827 .top.target.m.clist.$nl add command -label $b \
828 -command "reopen-target $n $b"
831 .top.target.m.clist add command -label $n \
832 -command "reopen-target $n {}"
836 .top.target.m.slist delete 0 last
837 foreach n [array names profile] {
838 if {$n != "Default"} {
839 .top.target.m.slist add command -label $n \
840 -command "protocol-setup $n"
845 proc save-settings {} {
848 global settingsChanged
850 set f [open "~/.tk-c" w]
851 puts $f "# Setup file"
852 puts $f "set hotTargets \{ $hotTargets \}"
854 foreach n [array names profile] {
855 puts -nonewline $f "set profile($n) \{"
856 puts -nonewline $f $profile($n)
860 set settingsChanged 0
872 message $w.top.message -text $ask
874 pack $w.top.message -side left -pady 6 -padx 20 -expand yes -fill x
877 top-down-ok-cancel $w {alert-action} 1
881 proc alert-action {} {
887 proc exit-action {} {
888 global settingsChanged
890 if {$settingsChanged} {
891 set a [alert "you havent saved your settings. Do you wish to save?"]
899 frame .top -border 1 -relief raised
900 frame .mid -border 1 -relief raised
901 frame .data -border 1 -relief raised
902 frame .bot -border 1 -relief raised
903 pack .top .mid -side top -fill x
904 pack .data -side top -fill both -expand yes
907 menubutton .top.file -text "File" -underline 0 -menu .top.file.m
909 .top.file.m add command -label "Save settings" -command {save-settings}
910 .top.file.m add command -label "Load Set" -command {load-set}
911 .top.file.m add separator
912 .top.file.m add command -label "Exit" -command {exit-action}
914 menubutton .top.target -text "Target" -underline 0 -menu .top.target.m
916 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
917 .top.target.m add command -label "Disconnect" -command {close-target}
918 #.top.target.m add command -label "Initialize" -command {init-request}
919 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
920 .top.target.m add command -label "Setup new" -command {define-target-dialog}
921 .top.target.m add separator
924 .top.target.m disable 1
926 menu .top.target.m.clist
927 menu .top.target.m.slist
930 menubutton .top.search -text "Search" -underline 0 -menu .top.search.m
932 .top.search.m add command -label "Database" -command {database-select}
933 .top.search.m add cascade -label "Query type" -menu .top.search.m.querytype
934 menu .top.search.m.querytype
935 .top.search.m.querytype add radiobutton -label "RPN"
936 .top.search.m.querytype add radiobutton -label "CCL"
937 .top.search.m add cascade -label "Present" -menu .top.search.m.present
938 menu .top.search.m.present
939 .top.search.m.present add command -label "More" -command [list present-more 10]
940 .top.search.m.present add command -label "All" -command [list present-more {}]
941 .top.search configure -state disabled
943 menubutton .top.help -text "Help" -menu .top.help.m
946 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
947 .top.help.m add command -label "About" -command {puts "About"}
949 pack .top.file .top.target .top.search -side left
950 pack .top.help -side right
952 label .mid.searchlabel -text {Search:}
953 entry .mid.searchentry -width 32 -relief sunken
954 pack .mid.searchlabel -side left
955 pack .mid.searchentry -side left -fill x -expand yes
957 focus .mid.searchentry
958 bind .mid.searchentry <Left> {left-cursor .mid.searchentry}
959 bind .mid.searchentry <Right> {right-cursor .mid.searchentry}
961 listbox .data.list -yscrollcommand {.data.scroll set}
962 scrollbar .data.scroll -orient vertical -border 1
963 pack .data.list -side left -fill both -expand yes
964 pack .data.scroll -side right -fill y
965 .data.scroll config -command {.data.list yview}
967 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
968 label .bot.status -text "Not connected" -width 12 -relief \
969 sunken -anchor w -border 1
970 label .bot.set -textvariable setNo -width 5 -relief \
971 sunken -anchor w -border 1
972 label .bot.message -text "" -width 14 -relief \
973 sunken -anchor w -border 1
974 pack .bot.target .bot.status .bot.set .bot.message -anchor nw \
975 -side left -padx 2 -pady 2
977 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
978 show-full-marc $indx}