3 # Revision 1.12 1995-03-21 13:41:03 adam
4 # Comstack cs_create not used too often. Non-blocking connect.
6 # Revision 1.11 1995/03/21 10:39:06 adam
7 # Diagnostic error message displayed with tkerror.
9 # Revision 1.10 1995/03/20 15:24:06 adam
10 # Diagnostic records saved on searchResponse.
12 # Revision 1.9 1995/03/17 18:26:16 adam
13 # Non-blocking i/o used now. Database names popup as cascade items.
15 # Revision 1.8 1995/03/17 15:45:00 adam
16 # Improved target/database setup.
18 # Revision 1.7 1995/03/16 17:54:03 adam
19 # Minor changes really.
21 # Revision 1.6 1995/03/15 19:10:20 adam
22 # Database setup in protocol-setup (rather target setup).
24 # Revision 1.5 1995/03/15 13:59:23 adam
27 # Revision 1.4 1995/03/14 17:32:29 adam
28 # Presentation of full Marc record in popup window.
30 # Revision 1.3 1995/03/12 19:31:52 adam
31 # Pattern matching implemented when retrieving MARC records. More
32 # diagnostic functions.
34 # Revision 1.2 1995/03/10 18:00:15 adam
35 # Actual presentation in line-by-line format. RPN query support.
37 # Revision 1.1 1995/03/09 16:15:07 adam
38 # First presentRequest attempts. Hot-target list.
45 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {}}
52 if {[file readable "~/.tk-c"]} {
56 proc top-down-window {w} {
57 frame $w.top -relief raised -border 1
58 frame $w.bot -relief raised -border 1
60 pack $w.top $w.bot -side top -fill both -expand yes
63 proc top-down-ok-cancel {w ok-action g} {
64 frame $w.bot.left -relief sunken -border 1
65 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
66 button $w.bot.left.ok -width 6 -text {Ok} \
68 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
69 button $w.bot.cancel -width 6 -text {Cancel} \
71 pack $w.bot.cancel -side left -expand yes
80 proc show-target {target} {
81 .bot.target configure -text "$target"
84 proc show-busy {v1 v2} {
87 .bot.status configure -fg $v1
88 after 200 [list show-busy $v2 $v1]
92 proc show-status {status b} {
95 .bot.status configure -text "$status"
96 .bot.status configure -fg black
102 # . config -cursor {watch black white}
104 # . config -cursor {top_left_arrow black white}
110 proc show-message {msg} {
111 .bot.message configure -text "$msg"
114 proc insertWithTags {w text args} {
115 set start [$w index insert]
116 $w insert insert $text
117 foreach tag [$w tag names $start] {
118 $w tag remove $tag $start insert
121 $w tag add $i $start insert
125 proc show-full-marc {no} {
130 if {[winfo exists $w]} {
131 $w.top.record delete 0.0 end
137 wm minsize $w 200 200
139 frame $w.top -relief raised -border 1
140 frame $w.bot -relief raised -border 1
142 pack $w.top -side top -fill both -expand yes
143 pack $w.bot -fill both
145 text $w.top.record -width 60 -height 12 -wrap word \
146 -yscrollcommand [list $w.top.s set]
147 scrollbar $w.top.s -command [list $w.top.record yview]
153 set r [z39.$setNo recordMarc $no line * * *]
155 $w.top.record tag configure marc-tag -foreground blue
156 $w.top.record tag configure marc-data -foreground black
157 $w.top.record tag configure marc-id -foreground red
160 set tag [lindex $line 0]
161 set indicator [lindex $line 1]
162 set fields [lindex $line 2]
164 if {$indicator != ""} {
165 insertWithTags $w.top.record "$tag $indicator" marc-tag
167 insertWithTags $w.top.record "$tag " marc-tag
169 foreach field $fields {
170 set id [lindex $field 0]
171 set data [lindex $field 1]
173 insertWithTags $w.top.record " $id " marc-id
175 set start [$w.top.record index insert]
176 insertWithTags $w.top.record $data {}
178 $w.top.record insert end "\n"
181 bind $w <Return> {destroy .full-marc}
183 pack $w.top.s -side right -fill y
184 pack $w.top.record -expand yes -fill both
186 frame $w.bot.left -relief sunken -border 1
187 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
188 button $w.bot.left.close -width 6 -text {Close} \
189 -command {destroy .full-marc}
190 pack $w.bot.left.close -expand yes -padx 3 -pady 3
191 button $w.bot.edit -width 6 -text {Edit} \
192 -command {destroy .full-marc}
193 pack $w.bot.edit -side left -expand yes
197 proc update-target-hotlist {target} {
200 set len [llength $hotTargets]
202 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
204 set indx [lsearch $hotTargets $target]
206 set hotTargets [lreplace $hotTargets $indx $indx]
208 set hotTargets [linsert $hotTargets 0 $target]
212 proc set-target-hotlist {} {
216 foreach target $hotTargets {
217 .top.target.m add command -label "$i $target" -command \
218 "menu-open-target $target {}"
226 proc menu-open-target {target base} {
227 open-target $target $base
228 update-target-hotlist $target
231 proc define-target-action {} {
234 set target [.target-define.top.target.entry get]
238 update-target-hotlist $target
239 foreach n [array names profile] {
245 set profile($target) $profile(Default)
246 protocol-setup $target
247 destroy .target-define
250 proc connect-response {target} {
251 puts "connect-response"
256 proc open-target {target base} {
259 .top.target.m disable 0
260 .top.target.m enable 1
262 z39 comstack [lindex $profile($target) 6]
263 # z39 idAuthentication [lindex $profile($target) 3]
264 z39 maximumRecordSize [lindex $profile($target) 4]
265 z39 preferredMessageSize [lindex $profile($target) 5]
266 puts -nonewline "maximumRecordSize="
267 puts [z39 maximumRecordSize]
268 puts -nonewline "preferredMessageSize="
269 puts [z39 preferredMessageSize]
271 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
273 z39 databaseNames $base
275 show-status {Connecting} 1
276 z39 callback [list connect-response $target]
277 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
280 proc load-set-action {} {
286 set fname [.load-set.top.filename.entry get]
291 show-status {Loading} 1
292 z39.$setNo loadFile $fname
294 set no [z39.$setNo numberOfRecordsReturned]
295 add-title-lines $setNo $no 1
297 show-status {Ready} 0
309 frame $w.top.filename
311 pack $w.top.filename -side top -anchor e -pady 2
313 entry-fields $w.top {filename} \
315 {load-set-action} {destroy .load-set}
317 top-down-ok-cancel $w {load-set-action} 1
320 proc init-request {} {
323 z39 callback {init-response}
325 show-status {Initializing} 1
329 proc init-response {} {
330 show-status {Ready} 0
331 bind .mid.searchentry <Return> search-request
332 focus .mid.searchentry
335 proc search-request {} {
341 z39 callback {search-response}
342 z39.$setNo search [.mid.searchentry get]
343 show-status {Search} 1
346 proc search-response {} {
352 show-status {Ready} 0
353 show-message "[z39.$setNo resultCount] hits"
354 set setMax [z39.$setNo resultCount]
357 set status [z39.$setNo responseStatus]
358 if {[lindex $status 0] == "NSD"} {
359 set code [lindex $status 1]
360 set msg [lindex $status 2]
361 set addinfo [lindex $status 3]
362 tkerror "NSD$code: $msg: $addinfo"
369 z39 callback {present-response}
371 z39.$setNo present 1 $setMax
372 show-status {Retrieve} 1
375 proc init-title-lines {} {
376 .data.list delete 0 end
379 proc add-title-lines {setno no offset} {
380 for {set i 0} {$i < $no} {incr i} {
381 set o [expr $i + $offset]
382 set title [lindex [z39.$setno recordMarc $o field 245 * a] 0]
383 set year [lindex [z39.$setno recordMarc $o field 260 * c] 0]
384 set nostr [format "%3d" $o]
385 .data.list insert end "$nostr $title - $year"
389 proc present-response {} {
394 puts "In present-response"
395 set no [z39.$setNo numberOfRecordsReturned]
396 puts "Returned $no records, setOffset $setOffset"
397 add-title-lines $setNo $no $setOffset
398 set setOffset [expr $setOffset + $no]
399 set status [z39.$setNo responseStatus]
400 if {[lindex $status 0] == "NSD"} {
401 show-status {Ready} 0
402 set code [lindex $status 1]
403 set msg [lindex $status 2]
404 set addinfo [lindex $status 3]
405 tkerror "NSD$code: $msg: $addinfo"
408 if {$no > 0 && $setOffset <= $setMax} {
409 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
411 show-status {Finished} 0
415 proc left-cursor {w} {
416 set i [$w index insert]
423 proc right-cursor {w} {
424 set i [$w index insert]
429 proc bind-fields {list returnAction escapeAction} {
430 set max [expr [llength $list]-1]
431 for {set i 0} {$i < $max} {incr i} {
432 bind [lindex $list $i] <Return> $returnAction
433 bind [lindex $list $i] <Escape> $escapeAction
434 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
435 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
436 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
438 bind [lindex $list $i] <Return> $returnAction
439 bind [lindex $list $i] <Escape> $escapeAction
440 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
441 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
442 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
443 focus [lindex $list 0]
446 proc entry-fields {parent list tlist returnAction escapeAction} {
449 foreach field $list {
450 set label ${parent}.${field}.label
451 set entry ${parent}.${field}.entry
452 label $label -text [lindex $tlist $i] -anchor e
453 entry $entry -width 32 -relief sunken
454 pack $label -side left
455 pack $entry -side right
459 bind-fields $alist $returnAction $escapeAction
462 proc define-target-dialog {} {
474 -side top -anchor e -pady 2
476 entry-fields $w.top {target} \
478 {define-target-action} {destroy .target-define}
480 top-down-ok-cancel $w {define-target-action} 1
483 proc close-target {} {
484 # pack forget .mid.searchlabel .mid.searchentry
485 .mid.searchentry -state disabled
488 show-status {Not connected} 0
490 .top.target.m disable 1
491 .top.target.m enable 0
494 proc protocol-setup-action {target} {
497 global settingsChanged
499 set w .setup-${target}.top
501 #set w .protocol-setup.top
504 set settingsChanged 1
505 set len [$w.databases.list size]
506 for {set i 0} {$i < $len} {incr i} {
507 lappend b [$w.databases.list get $i]
509 set profile($target) [list [$w.description.entry get] \
510 [$w.host.entry get] \
511 [$w.port.entry get] \
512 [$w.idAuthentication.entry get] \
513 [$w.maximumRecordSize.entry get] \
514 [$w.preferredMessageSize.entry get] \
519 puts $profile($target)
520 destroy .setup-${target}
524 proc place-force {window parent} {
525 set g [wm geometry $parent]
527 set p1 [string first + $g]
528 set p2 [string last + $g]
530 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
531 set y [expr 60+[string range $g [expr $p2 +1] end]]
532 wm geometry $window +${x}+${y}
536 proc add-database-action {target} {
537 set w .setup-${target}
539 ${w}.top.databases.list insert end \
540 [.database-select.top.database.entry get]
541 destroy .database-select
544 proc add-database {target} {
545 set w .database-select
550 place-force $w .setup-${target}
554 frame $w.top.database
556 pack $w.top.database -side top -anchor e -pady 2
558 entry-fields $w.top {database} \
559 {{Database to add:}} \
560 [list add-database-action $target] {destroy .database-select}
562 top-down-ok-cancel $w [list add-database-action $target] 1
566 proc delete-database {target} {
567 set w .setup-${target}
569 foreach i [lsort -decreasing \
570 [$w.top.databases.list curselection]] {
571 $w.top.databases.list delete $i
575 proc protocol-setup {target} {
583 wm title $w "Setup $target"
592 puts $profile($target)
596 frame $w.top.description
597 frame $w.top.idAuthentication
598 frame $w.top.maximumRecordSize
599 frame $w.top.preferredMessageSize
600 frame $w.top.cs-type -relief ridge -border 2
601 frame $w.top.query -relief ridge -border 2
602 frame $w.top.databases -relief ridge -border 2
604 # Maximum/preferred/idAuth ...
605 pack $w.top.description $w.top.host $w.top.port \
606 $w.top.idAuthentication $w.top.maximumRecordSize \
607 $w.top.preferredMessageSize -side top -anchor e -pady 2
610 entry-fields $w.top {description host port idAuthentication \
611 maximumRecordSize preferredMessageSize} \
612 {{Description:} {Host:} {Port:} {Id Authentification:} \
613 {Maximum Record Size:} {Preferred Message Size:}} \
614 [list protocol-setup-action $target] [list destroy $w]
616 $w.top.description.entry insert 0 [lindex $profile($target) 0]
617 $w.top.host.entry insert 0 [lindex $profile($target) 1]
618 $w.top.port.entry insert 0 [lindex $profile($target) 2]
619 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
620 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
621 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
624 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
626 label $w.top.databases.label -text "Databases"
627 button $w.top.databases.add -text "Add" \
628 -command "add-database $target"
629 button $w.top.databases.delete -text "Delete" \
630 -command "delete-database $target"
631 listbox $w.top.databases.list -geometry 20x6 \
632 -yscrollcommand "$w.top.databases.scroll set"
633 scrollbar $w.top.databases.scroll -orient vertical -border 1
634 pack $w.top.databases.label -side top -fill x \
636 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
638 pack $w.top.databases.list -side left -fill both -expand yes \
640 pack $w.top.databases.scroll -side right -fill y \
642 $w.top.databases.scroll config -command "$w.top.databases.list yview"
644 foreach b [lindex $profile($target) 7] {
645 $w.top.databases.list insert end $b
649 set csRadioType [lindex $profile($target) 6]
651 pack $w.top.cs-type -pady 6 -padx 6 -side top
653 label $w.top.cs-type.label -text "Transport"
654 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
655 -command {puts tcp/ip} -variable csRadioType -value tcpip
656 radiobutton $w.top.cs-type.mosi -text "MOSI" \
657 -command {puts mosi} -variable csRadioType -value mosi
659 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
660 -padx 4 -side top -fill x
663 pack $w.top.query -pady 6 -padx 6 -side top
665 label $w.top.query.label -text "Query support" -anchor e
666 checkbutton $w.top.query.c1 -text "CCL query"
667 checkbutton $w.top.query.c2 -text "RPN query"
668 checkbutton $w.top.query.c3 -text "Result sets"
670 pack $w.top.query.label -side top
671 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
672 -padx 4 -side top -fill x
674 foreach sub [winfo children $w.top] {
676 bind $sub <Control-a> "add-database $target"
678 top-down-ok-cancel $w [list protocol-setup-action $target] 0
681 proc database-select-action {} {
682 set w .database-select.top
684 foreach indx [$w.databases.list curselection] {
685 lappend b [$w.databases.list get $indx]
690 destroy .database-select
693 proc database-select {} {
694 set w .database-select
708 frame $w.top.databases -relief ridge -border 2
710 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
712 label $w.top.databases.label -text "List"
713 listbox $w.top.databases.list -geometry 20x6 \
714 -yscrollcommand "$w.top.databases.scroll set"
715 scrollbar $w.top.databases.scroll -orient vertical -border 1
716 pack $w.top.databases.label -side top -fill x \
718 pack $w.top.databases.list -side left -fill both -expand yes \
720 pack $w.top.databases.scroll -side right -fill y \
722 $w.top.databases.scroll config -command "$w.top.databases.list yview"
724 foreach b [lindex $profile($hostid) 7] {
725 $w.top.databases.list insert end $b
727 top-down-ok-cancel $w {database-select-action} 1
730 proc cascade-target-list {} {
733 foreach sub [winfo children .top.target.m.clist] {
737 .top.target.m.clist delete 0 last
738 foreach n [array names profile] {
739 if {$n != "Default"} {
740 set nl [string tolower $n]
741 if {[llength [lindex $profile($n) 7]] > 1} {
742 .top.target.m.clist add cascade -label $n \
743 -menu .top.target.m.clist.$nl
744 menu .top.target.m.clist.$nl
745 foreach b [lindex $profile($n) 7] {
746 .top.target.m.clist.$nl add command -label $b \
747 -command "menu-open-target $n $b"
750 .top.target.m.clist add command -label $n \
751 -command "menu-open-target $n {}"
755 .top.target.m.slist delete 0 last
756 foreach n [array names profile] {
757 if {$n != "Default"} {
758 .top.target.m.slist add command -label $n \
759 -command "protocol-setup $n"
764 proc save-settings {} {
767 global settingsChanged
769 set f [open "~/.tk-c" w]
770 puts $f "# Setup file"
771 puts $f "set hotTargets \{ $hotTargets \}"
773 foreach n [array names profile] {
774 puts -nonewline $f "set profile($n) \{"
775 puts -nonewline $f $profile($n)
779 set settingsChanged 0
791 message $w.top.message -text $ask
793 pack $w.top.message -side left -pady 6 -padx 20 -expand yes -fill x
796 top-down-ok-cancel $w {alert-action} 1
800 proc alert-action {} {
806 proc exit-action {} {
807 global settingsChanged
809 if {$settingsChanged} {
810 set a [alert "you havent saved your settings. Do you wish to save?"]
818 frame .top -border 1 -relief raised
819 frame .mid -border 1 -relief raised
820 frame .data -border 1 -relief raised
821 frame .bot -border 1 -relief raised
822 pack .top .mid -side top -fill x
823 pack .data -side top -fill both -expand yes
826 menubutton .top.file -text "File" -menu .top.file.m
828 .top.file.m add command -label "Save settings" -command {save-settings}
829 .top.file.m add command -label "Load Set" -command {load-set}
830 .top.file.m add separator
831 .top.file.m add command -label "Exit" -command {exit-action}
833 menubutton .top.target -text "Target" -menu .top.target.m
835 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
836 .top.target.m add command -label "Disconnect" -command {close-target}
837 #.top.target.m add command -label "Initialize" -command {init-request}
838 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
839 .top.target.m add command -label "Setup new" -command {define-target-dialog}
840 .top.target.m add separator
843 .top.target.m disable 1
845 menu .top.target.m.clist
846 menu .top.target.m.slist
849 menubutton .top.database -text "Database" -menu .top.database.m
851 .top.database.m add command -label "Select ..." -command {database-select}
852 .top.database.m add command -label "Add ..." -command {puts "Add"}
854 menubutton .top.help -text "Help" -menu .top.help.m
857 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
858 .top.help.m add command -label "About" -command {puts "About"}
860 pack .top.file .top.target .top.database -side left
861 pack .top.help -side right
863 label .mid.searchlabel -text {Search:}
864 entry .mid.searchentry -width 32 -relief sunken
865 pack .mid.searchlabel -side left
866 pack .mid.searchentry -side left -fill x -expand yes
868 bind .mid.searchentry <Left> {left-cursor .mid.searchentry}
869 bind .mid.searchentry <Right> {right-cursor .mid.searchentry}
871 listbox .data.list -yscrollcommand {.data.scroll set}
872 scrollbar .data.scroll -orient vertical -border 1
873 pack .data.list -side left -fill both -expand yes
874 pack .data.scroll -side right -fill y
875 .data.scroll config -command {.data.list yview}
877 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
878 label .bot.status -text "Not connected" -width 12 -relief \
879 sunken -anchor w -border 1
880 label .bot.set -textvariable setNo -width 5 -relief \
881 sunken -anchor w -border 1
882 label .bot.message -text "" -width 14 -relief \
883 sunken -anchor w -border 1
884 pack .bot.target .bot.status .bot.set .bot.message -anchor nw -side left -padx 2 -pady 2
886 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
887 show-full-marc $indx}