3 # Revision 1.10 1995-03-20 15:24:06 adam
4 # Diagnostic records saved on searchResponse.
6 # Revision 1.9 1995/03/17 18:26:16 adam
7 # Non-blocking i/o used now. Database names popup as cascade items.
9 # Revision 1.8 1995/03/17 15:45:00 adam
10 # Improved target/database setup.
12 # Revision 1.7 1995/03/16 17:54:03 adam
13 # Minor changes really.
15 # Revision 1.6 1995/03/15 19:10:20 adam
16 # Database setup in protocol-setup (rather target setup).
18 # Revision 1.5 1995/03/15 13:59:23 adam
21 # Revision 1.4 1995/03/14 17:32:29 adam
22 # Presentation of full Marc record in popup window.
24 # Revision 1.3 1995/03/12 19:31:52 adam
25 # Pattern matching implemented when retrieving MARC records. More
26 # diagnostic functions.
28 # Revision 1.2 1995/03/10 18:00:15 adam
29 # Actual presentation in line-by-line format. RPN query support.
31 # Revision 1.1 1995/03/09 16:15:07 adam
32 # First presentRequest attempts. Hot-target list.
39 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {}}
46 if {[file readable "~/.tk-c"]} {
50 proc top-down-window {w} {
51 frame $w.top -relief raised -border 1
52 frame $w.bot -relief raised -border 1
54 pack $w.top $w.bot -side top -fill both -expand yes
57 proc top-down-ok-cancel {w ok-action g} {
58 frame $w.bot.left -relief sunken -border 1
59 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
60 button $w.bot.left.ok -width 6 -text {Ok} \
62 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
63 button $w.bot.cancel -width 6 -text {Cancel} \
65 pack $w.bot.cancel -side left -expand yes
74 proc show-target {target} {
75 .bot.target configure -text "$target"
78 proc show-busy {v1 v2} {
81 .bot.status configure -fg $v1
82 after 200 [list show-busy $v2 $v1]
86 proc show-status {status b} {
89 .bot.status configure -text "$status"
90 .bot.status configure -fg black
96 # . config -cursor {watch black white}
98 # . config -cursor {top_left_arrow black white}
104 proc show-message {msg} {
105 .bot.message configure -text "$msg"
108 proc insertWithTags {w text args} {
109 set start [$w index insert]
110 $w insert insert $text
111 foreach tag [$w tag names $start] {
112 $w tag remove $tag $start insert
115 $w tag add $i $start insert
119 proc show-full-marc {no} {
124 if {[winfo exists $w]} {
125 $w.top.record delete 0.0 end
131 wm minsize $w 200 200
133 frame $w.top -relief raised -border 1
134 frame $w.bot -relief raised -border 1
136 # pack $w.top $w.bot -side top -fill both -expand yes
137 pack $w.top -side top -fill both -expand yes
138 pack $w.bot -fill both
140 text $w.top.record -width 60 -height 10 -wrap word \
141 -yscrollcommand [list $w.top.s set]
142 scrollbar $w.top.s -command [list $w.top.record yview]
148 set r [z39.$setNo recordMarc $no line * * *]
150 $w.top.record tag configure marc-tag -foreground blue
151 $w.top.record tag configure marc-data -foreground black
152 $w.top.record tag configure marc-id -foreground red
155 set tag [lindex $line 0]
156 set indicator [lindex $line 1]
157 set fields [lindex $line 2]
159 if {$indicator != ""} {
160 insertWithTags $w.top.record "$tag $indicator" marc-tag
162 insertWithTags $w.top.record "$tag " marc-tag
164 foreach field $fields {
165 set id [lindex $field 0]
166 set data [lindex $field 1]
168 insertWithTags $w.top.record " $id " marc-id
170 set start [$w.top.record index insert]
171 insertWithTags $w.top.record $data {}
173 $w.top.record insert end "\n"
176 bind $w <Return> {destroy .full-marc}
178 pack $w.top.s -side right -fill y
179 pack $w.top.record -expand yes -fill both
181 frame $w.bot.left -relief sunken -border 1
182 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
183 button $w.bot.left.close -width 6 -text {Close} \
184 -command {destroy .full-marc}
185 pack $w.bot.left.close -expand yes -padx 3 -pady 3
186 button $w.bot.edit -width 6 -text {Edit} \
187 -command {destroy .full-marc}
188 pack $w.bot.edit -side left -expand yes
192 proc update-target-hotlist {target} {
195 set len [llength $hotTargets]
197 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
199 set indx [lsearch $hotTargets $target]
201 set hotTargets [lreplace $hotTargets $indx $indx]
203 set hotTargets [linsert $hotTargets 0 $target]
207 proc set-target-hotlist {} {
211 foreach target $hotTargets {
212 .top.target.m add command -label "$i $target" -command \
213 "menu-open-target $target {}"
221 proc menu-open-target {target base} {
222 open-target $target $base
223 update-target-hotlist $target
226 proc define-target-action {} {
229 set target [.target-define.top.target.entry get]
233 update-target-hotlist $target
234 foreach n [array names profile] {
240 set profile($target) $profile(Default)
241 protocol-setup $target
242 destroy .target-define
245 proc open-target {target base} {
248 .top.target.m disable 0
249 .top.target.m enable 1
251 z39 comstack [lindex $profile($target) 6]
252 # z39 idAuthentication [lindex $profile($target) 3]
253 z39 maximumRecordSize [lindex $profile($target) 4]
254 z39 preferredMessageSize [lindex $profile($target) 5]
255 puts -nonewline "maximumRecordSize="
256 puts [z39 maximumRecordSize]
257 puts -nonewline "preferredMessageSize="
258 puts [z39 preferredMessageSize]
260 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
262 z39 databaseNames $base
265 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
269 proc load-set-action {} {
275 set fname [.load-set.top.filename.entry get]
278 .data.list delete 0 end
280 show-status {Loading} 1
281 z39.$setNo loadFile $fname
283 set no [z39.$setNo numberOfRecordsReturned]
284 add-title-lines $no 1
286 show-status {Ready} 0
298 frame $w.top.filename
300 pack $w.top.filename -side top -anchor e -pady 2
302 entry-fields $w.top {filename} \
304 {load-set-action} {destroy .load-set}
306 top-down-ok-cancel $w {load-set-action} 1
309 proc init-request {} {
312 z39 callback {init-response}
314 show-status {Initializing} 1
318 proc init-response {} {
319 show-status {Ready} 0
320 pack .mid.searchlabel .mid.searchentry -side left
321 bind .mid.searchentry <Return> search-request
322 focus .mid.searchentry
325 proc search-request {} {
331 z39 callback {search-response}
332 z39.$setNo search [.mid.searchentry get]
333 show-status {Search} 1
336 proc search-response {} {
341 .data.list delete 0 end
342 show-status {Ready} 0
343 show-message "[z39.$setNo resultCount] hits"
344 set setMax [z39.$setNo resultCount]
352 z39 callback {present-response}
354 z39.$setNo present 1 $setMax
355 show-status {Retrieve} 1
358 proc add-title-lines {no offset} {
361 for {set i 0} {$i < $no} {incr i} {
362 set o [expr $i + $offset]
363 set title [lindex [z39.$setNo recordMarc $o field 245 * a] 0]
364 set year [lindex [z39.$setNo recordMarc $o field 260 * c] 0]
365 set nostr [format "%3d" $o]
366 .data.list insert end "$nostr $title - $year"
370 proc present-response {} {
375 puts "In present-response"
376 set no [z39.$setNo numberOfRecordsReturned]
377 puts "Returned $no records, setOffset $setOffset"
378 add-title-lines $no $setOffset
379 set setOffset [expr $setOffset + $no]
380 if {$no > 0 && $setOffset <= $setMax} {
381 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
383 show-status {Finished} 0
387 proc left-cursor {w} {
388 set i [$w index insert]
395 proc right-cursor {w} {
396 set i [$w index insert]
401 proc bind-fields {list returnAction escapeAction} {
402 set max [expr [llength $list]-1]
403 for {set i 0} {$i < $max} {incr i} {
404 bind [lindex $list $i] <Return> $returnAction
405 bind [lindex $list $i] <Escape> $escapeAction
406 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
407 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
408 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
410 bind [lindex $list $i] <Return> $returnAction
411 bind [lindex $list $i] <Escape> $escapeAction
412 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
413 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
414 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
415 focus [lindex $list 0]
418 proc entry-fields {parent list tlist returnAction escapeAction} {
421 foreach field $list {
422 set label ${parent}.${field}.label
423 set entry ${parent}.${field}.entry
424 label $label -text [lindex $tlist $i] -anchor e
425 entry $entry -width 32 -relief sunken
426 pack $label -side left
427 pack $entry -side right
431 bind-fields $alist $returnAction $escapeAction
434 proc define-target-dialog {} {
446 -side top -anchor e -pady 2
448 entry-fields $w.top {target} \
450 {define-target-action} {destroy .target-define}
452 top-down-ok-cancel $w {define-target-action} 1
455 proc close-target {} {
456 pack forget .mid.searchlabel .mid.searchentry
459 show-status {Not connected} 0
461 .top.target.m disable 1
462 .top.target.m enable 0
465 proc protocol-setup-action {target} {
468 global settingsChanged
470 set w .setup-${target}.top
472 #set w .protocol-setup.top
475 set settingsChanged 1
476 set len [$w.databases.list size]
477 for {set i 0} {$i < $len} {incr i} {
478 lappend b [$w.databases.list get $i]
480 set profile($target) [list [$w.description.entry get] \
481 [$w.host.entry get] \
482 [$w.port.entry get] \
483 [$w.idAuthentication.entry get] \
484 [$w.maximumRecordSize.entry get] \
485 [$w.preferredMessageSize.entry get] \
490 puts $profile($target)
491 destroy .setup-${target}
495 proc place-force {window parent} {
496 set g [wm geometry $parent]
498 set p1 [string first + $g]
499 set p2 [string last + $g]
501 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
502 set y [expr 60+[string range $g [expr $p2 +1] end]]
503 wm geometry $window +${x}+${y}
507 proc add-database-action {target} {
508 set w .setup-${target}
510 ${w}.top.databases.list insert end \
511 [.database-select.top.database.entry get]
512 destroy .database-select
515 proc add-database {target} {
516 set w .database-select
521 place-force $w .setup-${target}
525 frame $w.top.database
527 pack $w.top.database -side top -anchor e -pady 2
529 entry-fields $w.top {database} \
530 {{Database to add:}} \
531 [list add-database-action $target] {destroy .database-select}
533 top-down-ok-cancel $w [list add-database-action $target] 1
537 proc delete-database {target} {
538 set w .setup-${target}
540 foreach i [lsort -decreasing \
541 [$w.top.databases.list curselection]] {
542 $w.top.databases.list delete $i
546 proc protocol-setup {target} {
554 wm title $w "Setup $target"
563 puts $profile($target)
567 frame $w.top.description
568 frame $w.top.idAuthentication
569 frame $w.top.maximumRecordSize
570 frame $w.top.preferredMessageSize
571 frame $w.top.cs-type -relief ridge -border 2
572 frame $w.top.query -relief ridge -border 2
573 frame $w.top.databases -relief ridge -border 2
575 # Maximum/preferred/idAuth ...
576 pack $w.top.description $w.top.host $w.top.port \
577 $w.top.idAuthentication $w.top.maximumRecordSize \
578 $w.top.preferredMessageSize -side top -anchor e -pady 2
581 entry-fields $w.top {description host port idAuthentication \
582 maximumRecordSize preferredMessageSize} \
583 {{Description:} {Host:} {Port:} {Id Authentification:} \
584 {Maximum Record Size:} {Preferred Message Size:}} \
585 [list protocol-setup-action $target] [list destroy $w]
587 $w.top.description.entry insert 0 [lindex $profile($target) 0]
588 $w.top.host.entry insert 0 [lindex $profile($target) 1]
589 $w.top.port.entry insert 0 [lindex $profile($target) 2]
590 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
591 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
592 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
595 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
597 label $w.top.databases.label -text "Databases"
598 button $w.top.databases.add -text "Add" \
599 -command "add-database $target"
600 button $w.top.databases.delete -text "Delete" \
601 -command "delete-database $target"
602 listbox $w.top.databases.list -geometry 20x6 \
603 -yscrollcommand "$w.top.databases.scroll set"
604 scrollbar $w.top.databases.scroll -orient vertical -border 1
605 pack $w.top.databases.label -side top -fill x \
607 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
609 pack $w.top.databases.list -side left -fill both -expand yes \
611 pack $w.top.databases.scroll -side right -fill y \
613 $w.top.databases.scroll config -command "$w.top.databases.list yview"
615 foreach b [lindex $profile($target) 7] {
616 $w.top.databases.list insert end $b
620 set csRadioType [lindex $profile($target) 6]
622 pack $w.top.cs-type -pady 6 -padx 6 -side top
624 label $w.top.cs-type.label -text "Transport"
625 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
626 -command {puts tcp/ip} -variable csRadioType -value tcpip
627 radiobutton $w.top.cs-type.mosi -text "MOSI" \
628 -command {puts mosi} -variable csRadioType -value mosi
630 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
631 -padx 4 -side top -fill x
634 pack $w.top.query -pady 6 -padx 6 -side top
636 label $w.top.query.label -text "Query support" -anchor e
637 checkbutton $w.top.query.c1 -text "CCL query"
638 checkbutton $w.top.query.c2 -text "RPN query"
639 checkbutton $w.top.query.c3 -text "Result sets"
641 pack $w.top.query.label -side top
642 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
643 -padx 4 -side top -fill x
645 foreach sub [winfo children $w.top] {
647 bind $sub <Control-a> "add-database $target"
649 top-down-ok-cancel $w [list protocol-setup-action $target] 0
652 proc database-select-action {} {
653 set w .database-select.top
655 foreach indx [$w.databases.list curselection] {
656 lappend b [$w.databases.list get $indx]
661 destroy .database-select
664 proc database-select {} {
665 set w .database-select
679 frame $w.top.databases -relief ridge -border 2
681 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
683 label $w.top.databases.label -text "List"
684 listbox $w.top.databases.list -geometry 20x6 \
685 -yscrollcommand "$w.top.databases.scroll set"
686 scrollbar $w.top.databases.scroll -orient vertical -border 1
687 pack $w.top.databases.label -side top -fill x \
689 pack $w.top.databases.list -side left -fill both -expand yes \
691 pack $w.top.databases.scroll -side right -fill y \
693 $w.top.databases.scroll config -command "$w.top.databases.list yview"
695 foreach b [lindex $profile($hostid) 7] {
696 $w.top.databases.list insert end $b
698 top-down-ok-cancel $w {database-select-action} 1
701 proc cascade-target-list {} {
704 foreach sub [winfo children .top.target.m.clist] {
708 .top.target.m.clist delete 0 last
709 foreach n [array names profile] {
710 if {$n != "Default"} {
711 set nl [string tolower $n]
712 if {[llength [lindex $profile($n) 7]] > 1} {
713 .top.target.m.clist add cascade -label $n \
714 -menu .top.target.m.clist.$nl
715 menu .top.target.m.clist.$nl
716 foreach b [lindex $profile($n) 7] {
717 .top.target.m.clist.$nl add command -label $b \
718 -command "menu-open-target $n $b"
721 .top.target.m.clist add command -label $n \
722 -command "menu-open-target $n {}"
726 .top.target.m.slist delete 0 last
727 foreach n [array names profile] {
728 if {$n != "Default"} {
729 .top.target.m.slist add command -label $n \
730 -command "protocol-setup $n"
735 proc save-settings {} {
738 global settingsChanged
740 set f [open "~/.tk-c" w]
741 puts $f "# Setup file"
742 puts $f "set hotTargets \{ $hotTargets \}"
744 foreach n [array names profile] {
745 puts -nonewline $f "set profile($n) \{"
746 puts -nonewline $f $profile($n)
750 set settingsChanged 0
762 message $w.top.message -text $ask
764 pack $w.top.message -side left -pady 6 -padx 20 -expand yes -fill x
767 top-down-ok-cancel $w {alert-action} 1
771 proc alert-action {} {
777 proc exit-action {} {
778 global settingsChanged
780 if {$settingsChanged} {
781 set a [alert "you havent saved your settings. Do you wish to save?"]
789 frame .top -border 1 -relief raised
790 frame .mid -border 1 -relief raised
791 frame .data -border 1 -relief raised
792 frame .bot -border 1 -relief raised
793 pack .top .mid -side top -fill x
794 pack .data -side top -fill both -expand yes
797 menubutton .top.file -text "File" -menu .top.file.m
799 .top.file.m add command -label "Save settings" -command {save-settings}
800 .top.file.m add command -label "Load Set" -command {load-set}
801 .top.file.m add separator
802 .top.file.m add command -label "Exit" -command {exit-action}
804 menubutton .top.target -text "Target" -menu .top.target.m
806 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
807 .top.target.m add command -label "Disconnect" -command {close-target}
808 #.top.target.m add command -label "Initialize" -command {init-request}
809 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
810 .top.target.m add command -label "Setup new" -command {define-target-dialog}
811 .top.target.m add separator
814 .top.target.m disable 1
816 menu .top.target.m.clist
817 menu .top.target.m.slist
820 menubutton .top.database -text "Database" -menu .top.database.m
822 .top.database.m add command -label "Select ..." -command {database-select}
823 .top.database.m add command -label "Add ..." -command {puts "Add"}
825 menubutton .top.help -text "Help" -menu .top.help.m
828 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
829 .top.help.m add command -label "About" -command {puts "About"}
831 pack .top.file .top.target .top.database -side left
832 pack .top.help -side right
834 label .mid.searchlabel -text {Search:}
835 entry .mid.searchentry -width 40 -relief sunken
837 bind .mid.searchentry <Left> {left-cursor .mid.searchentry}
838 bind .mid.searchentry <Right> {right-cursor .mid.searchentry}
840 listbox .data.list -yscrollcommand {.data.scroll set}
841 scrollbar .data.scroll -orient vertical -border 1
842 pack .data.list -side left -fill both -expand yes
843 pack .data.scroll -side right -fill y
844 .data.scroll config -command {.data.list yview}
846 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
847 label .bot.status -text "Not connected" -width 12 -relief \
848 sunken -anchor w -border 1
849 label .bot.message -text "" -width 20 -relief \
850 sunken -anchor w -border 1
851 pack .bot.target .bot.status .bot.message -anchor nw -side left -padx 2 -pady 2
853 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
854 show-full-marc $indx}