1 # IR toolkit for tcl/tk
3 # See the file LICENSE for details.
4 # Sebastian Hammer, Adam Dickmeiss
7 # Revision 1.54 1995-06-27 14:41:03 adam
8 # Bug fix in search-response. Didn't always observe non-surrogate diagnostics.
10 # Revision 1.53 1995/06/26 12:40:09 adam
11 # Client defines its own tkerror.
12 # User may specify 'no preferredRecordSyntax'.
14 # Revision 1.52 1995/06/22 13:14:59 adam
15 # Feature: SUTRS. Setting getSutrs implemented.
16 # Work on display formats.
17 # Preferred record syntax can be set by the user.
19 # Revision 1.51 1995/06/21 11:11:00 adam
20 # Bug fix: libdir undefined in about-origin.
22 # Revision 1.50 1995/06/21 11:04:48 adam
23 # Uses GNU autoconf 2.3.
24 # Install procedure implemented.
25 # boook bitmaps moved to sub directory bitmaps.
27 # Revision 1.49 1995/06/20 14:16:42 adam
28 # More work on cancel mechanism.
30 # Revision 1.48 1995/06/20 08:07:23 adam
31 # New setting: failInfo.
32 # Working on better cancel mechanism.
34 # Revision 1.47 1995/06/19 14:05:29 adam
35 # Bug fix: asked for SUTRS.
37 # Revision 1.46 1995/06/19 13:06:06 adam
38 # New define: IR_TCL_VERSION.
40 # Revision 1.45 1995/06/19 08:08:44 adam
41 # client.tcl: hotTargets now contain both database and target name.
42 # ir-tcl.c: setting protocol edited. Errors in callbacks are logged
43 # by logf(LOG_WARN, ...) calls.
45 # Revision 1.44 1995/06/16 14:55:18 adam
48 # Revision 1.43 1995/06/16 14:41:05 adam
49 # Scan line entries can be copied to a search entry.
51 # Revision 1.42 1995/06/16 12:28:13 adam
52 # Implemented preferredRecordSyntax.
53 # Minor changes in diagnostic handling.
54 # Record list deleted when connection closes.
56 # Revision 1.41 1995/06/14 15:07:59 adam
57 # Bug fix in cascade-target-list. Uses yaz-version.h.
59 # Revision 1.40 1995/06/14 13:37:17 adam
60 # Setting recordType implemented.
61 # Setting implementationVersion implemented.
62 # Settings implementationId / implementationName edited.
64 # Revision 1.39 1995/06/14 12:16:22 adam
65 # hotTargets, textWrap and displayFormat saved in clientg.tcl.
67 # Revision 1.38 1995/06/14 07:22:45 adam
68 # Target definitions can be deleted.
69 # Listbox used in the query definition dialog.
71 # Revision 1.37 1995/06/13 14:37:59 adam
72 # Work on query setup.
73 # Better about origin/target.
74 # Better presentation formats.
76 # Revision 1.36 1995/06/13 07:42:14 adam
77 # Bindings removed from text widgets.
79 # Revision 1.35 1995/06/12 15:17:31 adam
80 # Text widget used in main window (instead of listbox) to support
81 # better presentation formats.
83 # Revision 1.34 1995/06/12 07:59:07 adam
84 # More work on geometry handling.
86 # Revision 1.33 1995/06/09 11:17:35 adam
87 # Start work on geometry management.
89 # Revision 1.32 1995/06/07 09:16:37 adam
90 # New presentation format.
92 # Revision 1.31 1995/06/06 16:31:09 adam
93 # Bug fix: target names couldn't contain blanks.
96 # Revision 1.30 1995/06/06 11:35:41 adam
97 # Work on scan. Display of old sets.
99 # Revision 1.29 1995/06/05 14:11:18 adam
100 # Bug fix in present-more.
102 # Revision 1.28 1995/06/02 14:52:13 adam
103 # Minor changes really.
105 # Revision 1.27 1995/06/02 14:29:42 adam
106 # Work on scan interface - up/down buttons.
108 # Revision 1.26 1995/06/01 16:36:46 adam
109 # About buttons. Minor bug fixes.
111 # Revision 1.25 1995/05/31 13:09:57 adam
112 # Client searches/presents may be interrupted.
113 # New moving book-logo.
115 # Revision 1.24 1995/05/31 08:36:24 adam
116 # Bug fix in client.tcl: didn't save options on clientrc.tcl.
117 # New method: referenceId. More work on scan.
119 # Revision 1.23 1995/05/29 10:33:41 adam
120 # README and rename of startup script.
122 # Revision 1.22 1995/05/26 11:44:09 adam
123 # Bugs fixed. More work on MARC utilities and queries. Test
124 # client is up-to-date again.
126 # Revision 1.21 1995/05/11 15:34:46 adam
127 # Scan request changed a bit. This version works with RLG.
129 # Revision 1.20 1995/04/21 16:31:57 adam
130 # New radiobutton: protocol (z39v2/SR).
132 # Revision 1.19 1995/04/18 16:11:50 adam
133 # First version of graphical Scan. Some work on query-by-form.
135 # Revision 1.18 1995/04/10 10:50:22 adam
136 # Result-set name defaults to suffix of ir-set name.
137 # Started working on scan. Not finished at this point.
139 # Revision 1.17 1995/03/31 09:34:57 adam
140 # Search-button disabled when there is no connection.
142 # Revision 1.16 1995/03/31 08:56:36 adam
143 # New button "Search".
145 # Revision 1.15 1995/03/28 12:45:22 adam
146 # New ir method failback: called on disconnect/protocol error.
147 # New ir set/get method: protocol: SR / Z3950.
148 # Simple popup and disconnect when failback is invoked.
150 # Revision 1.14 1995/03/22 16:07:55 adam
153 # Revision 1.13 1995/03/21 17:27:26 adam
154 # Short-hand keys in setup.
156 # Revision 1.12 1995/03/21 13:41:03 adam
157 # Comstack cs_create not used too often. Non-blocking connect.
159 # Revision 1.11 1995/03/21 10:39:06 adam
160 # Diagnostic error message displayed with tkerror.
162 # Revision 1.10 1995/03/20 15:24:06 adam
163 # Diagnostic records saved on searchResponse.
165 # Revision 1.9 1995/03/17 18:26:16 adam
166 # Non-blocking i/o used now. Database names popup as cascade items.
168 # Revision 1.8 1995/03/17 15:45:00 adam
169 # Improved target/database setup.
171 # Revision 1.7 1995/03/16 17:54:03 adam
172 # Minor changes really.
174 # Revision 1.6 1995/03/15 19:10:20 adam
175 # Database setup in protocol-setup (rather target setup).
177 # Revision 1.5 1995/03/15 13:59:23 adam
180 # Revision 1.4 1995/03/14 17:32:29 adam
181 # Presentation of full Marc record in popup window.
183 # Revision 1.3 1995/03/12 19:31:52 adam
184 # Pattern matching implemented when retrieving MARC records. More
185 # diagnostic functions.
187 # Revision 1.2 1995/03/10 18:00:15 adam
188 # Actual presentation in line-by-line format. RPN query support.
190 # Revision 1.1 1995/03/09 16:15:07 adam
191 # First presentRequest attempts. Hot-target list.
196 if {[file readable clientrc.tcl]} {
203 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {} 1 {} {} Z39}
205 set settingsChanged 0
214 set recordSyntax None
217 set queryTypes {Simple}
218 set queryButtons { { {I 0} {I 1} {I 2} } }
219 set queryInfo { { {Title {1=4 4=1}} {Author {1=1}} \
220 {Subject {1=21}} {Any {1=1016}} } }
229 if {[winfo exists $w]} {
238 label $w.top.b -bitmap error
239 message $w.top.t -aspect 300 -text "Error: $err" \
240 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
241 pack $w.top.b $w.top.t -side left -padx 10 -pady 10
243 bottom-buttons $w [list {Close} [list destroy $w]] 0
246 proc read-formats {} {
247 global displayFormats
249 set formats [glob -nocomplain ${libdir}/formats/*.tcl]
251 if {[file readable $f]} {
253 set l [string length $f]
254 set f [string range $f [string length "${libdir}/formats/"] \
256 lappend displayFormats $f
265 .data.record configure -wrap $m
272 proc set-display-format {f} {
282 .bot.a.status configure -text "Reformatting"
285 add-title-lines -1 10000 1
287 .bot.a.status configure -text "Ready"
291 proc initBindings {} {
294 bind $w <Double-1> {}
295 bind $w <Triple-1> {}
296 bind $w <B1-Motion> {}
298 bind $w <Shift-B1-Motion> {}
300 bind $w <B2-Motion> {}
301 bind $w <Any-KeyPress> {}
303 bind $w <BackSpace> {}
305 bind $w <Control-h> {}
306 bind $w <Control-d> {}
307 bind $w <Control-v> {}
310 bind $w <B1-Motion> {}
311 bind $w <Shift-B1-Motion> {}
316 proc post-menu {wbutton wmenu} {
319 $wmenu post [winfo rootx $wbutton] \
320 [expr [winfo rooty $wbutton]+[winfo height $wbutton]]
325 global windowGeometry
326 set windowGeometry($w) [wm geometry $w]
329 global windowGeometry
332 if {[info exists windowGeometry($w)]} {
333 set g $windowGeometry($w)
338 bind $w <Destroy> [list destroyGW $w]
341 if {[file readable "${libdir}/clientrc.tcl"]} {
342 source "${libdir}/clientrc.tcl"
345 if {[file readable "~/.clientrc.tcl"]} {
346 source "~/.clientrc.tcl"
349 set queryButtonsFind [lindex $queryButtons 0]
350 set queryInfoFind [lindex $queryInfo 0]
352 proc top-down-window {w} {
353 frame $w.top -relief raised -border 1
354 frame $w.bot -relief raised -border 1
356 pack $w.top -side top -fill both -expand yes
357 pack $w.bot -fill both
360 proc top-down-ok-cancel {w ok-action g} {
361 frame $w.bot.left -relief sunken -border 1
362 pack $w.bot.left -side left -expand yes -ipadx 2 -ipady 2 -padx 5 -pady 5
363 button $w.bot.left.ok -width 6 -text {Ok} \
364 -command ${ok-action}
365 pack $w.bot.left.ok -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3
366 button $w.bot.cancel -width 6 -text {Cancel} \
367 -command [list destroy $w]
368 pack $w.bot.cancel -side left -expand yes
376 proc bottom-buttons {w buttonList g} {
378 set l [llength $buttonList]
380 frame $w.bot.$i -relief sunken -border 1
381 pack $w.bot.$i -side left -expand yes -padx 5 -pady 5
382 button $w.bot.$i.ok -text [lindex $buttonList $i] \
383 -command [lindex $buttonList [expr $i+1]]
384 pack $w.bot.$i.ok -expand yes -ipadx 3 -ipady 2 -padx 3 -pady 3 -side left
388 button $w.bot.$i -text [lindex $buttonList $i] \
389 -command [lindex $buttonList [expr $i+1]]
390 pack $w.bot.$i -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3 -side left
400 proc cancel-operation {} {
408 show-status Cancel 0 1
412 proc show-target {target base} {
416 .bot.a.target configure -text ""
420 .bot.a.target configure -text "$target"
422 .bot.a.target configure -text "$target - $base"
426 proc show-logo {v1} {
435 .bot.logo configure -bitmap @${libdir}/bitmaps/book${v1}
436 after 140 [list show-logo $v1]
440 .bot.logo configure -bitmap @${libdir}/bitmaps/book1
449 proc show-status {status b sb} {
456 .bot.a.status configure -text "$status"
458 if {$busy == 0} {set busy 1}
466 .top.service configure -state normal
467 .mid.search configure -state normal
469 .mid.scan configure -state normal
472 .top.service.m disable 1
473 } elseif {$setOffset > 0 && $setOffset <= [z39.$setNo resultCount]} {
474 .top.service.m enable 1
475 .mid.present configure -state normal
477 .top.service.m disable 1
479 if {[winfo exists .scan-window]} {
480 .scan-window.bot.2 configure -state normal
481 .scan-window.bot.4 configure -state normal
484 .top.service configure -state disabled
485 .mid.search configure -state disabled
486 .mid.scan configure -state disabled
487 .mid.present configure -state disabled
489 if {[winfo exists .scan-window]} {
490 .scan-window.bot.2 configure -state disabled
491 .scan-window.bot.4 configure -state disabled
496 proc show-message {msg} {
497 .bot.a.message configure -text "$msg"
500 proc insertWithTags {w text args} {
501 set start [$w index insert]
502 $w insert insert $text
503 foreach tag [$w tag names $start] {
504 $w tag remove $tag $start insert
507 $w tag add $i $start insert
511 proc popup-license {} {
516 wm title $w "License"
522 text $w.top.t -width 80 -height 10 -wrap word \
523 -yscrollcommand [list $w.top.s set]
524 scrollbar $w.top.s -command [list $w.top.t yview]
526 pack $w.top.s -side right -fill y
527 pack $w.top.t -expand yes -fill both
529 if {[file readable "${libdir}/LICENSE"]} {
530 set f [open "${libdir}/LICENSE" r]
531 while {[gets $f buf] != -1} {
532 $w.top.t insert end $buf
533 $w.top.t insert end "\n"
537 bottom-buttons $w [list {Close} [list destroy $w]] 1
540 proc about-target {} {
541 set w .about-target-w
546 wm title $w "About target"
550 frame $w.top.a -relief ridge -border 2
551 frame $w.top.p -relief ridge -border 2
553 pack $w.top.a $w.top.p -side top -fill x
555 label $w.top.a.about -text "About"
556 label $w.top.a.irtcl -text $hostid \
557 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
558 pack $w.top.a.about $w.top.a.irtcl -side top
560 set i [z39 targetImplementationName]
561 label $w.top.p.in -text "Implementation name: $i"
562 set i [z39 targetImplementationId]
563 label $w.top.p.ii -text "Implementation id: $i"
564 set i [z39 targetImplementationVersion]
565 label $w.top.p.iv -text "Implementation version: $i"
567 label $w.top.p.op -text "Protocol options: $i"
569 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.op -side top -anchor nw
571 bottom-buttons $w [list {Close} [list destroy $w]] 1
574 proc about-origin-logo {n} {
576 set w .about-origin-w
577 if {![winfo exists $w]} {
584 $w.top.a.logo configure -bitmap @${libdir}/bitmaps/book$n
585 after 140 [list about-origin-logo $n]
588 proc about-origin {} {
589 set w .about-origin-w
592 if {[winfo exists $w]} {
597 wm title $w "About IrTcl"
601 frame $w.top.a -relief ridge -border 2
602 frame $w.top.p -relief ridge -border 2
604 pack $w.top.a $w.top.p -side top -fill x
606 label $w.top.a.irtcl -text "IrTcl" \
607 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
608 label $w.top.a.logo -bitmap @${libdir}/bitmaps/book1
609 pack $w.top.a.irtcl $w.top.a.logo -side left -expand yes
611 set i [z39 implementationName]
612 label $w.top.p.in -text "Implementation name: $i"
613 set i [z39 implementationId]
614 label $w.top.p.ii -text "Implementation id: $i"
615 set i [z39 implementationVersion]
616 label $w.top.p.iv -text "Implementation version: $i"
618 pack $w.top.p.in $w.top.p.ii $w.top.p.iv -side top -anchor nw
621 bottom-buttons $w [list {Close} [list destroy $w] \
622 {License} [list popup-license]] 0
625 proc popup-marc {sno no b df} {
627 global displayFormats
630 if {[z39.$sno type $no] != "DB"} {
634 set w .full-marc-$fullMarcSeq
641 if {[winfo exists $w]} {
649 frame $w.top -relief raised -border 1
650 frame $w.bot -relief raised -border 1
652 pack $w.top -side top -fill both -expand yes
653 pack $w.bot -fill both
655 text $w.top.record -width 60 -height 5 -wrap word \
656 -yscrollcommand [list $w.top.s set]
657 scrollbar $w.top.s -command [list $w.top.record yview]
659 if {[tk colormodel .] == "color"} {
660 $w.top.record tag configure marc-tag -foreground blue
661 $w.top.record tag configure marc-id -foreground red
663 $w.top.record tag configure marc-tag -foreground black
664 $w.top.record tag configure marc-id -foreground black
666 $w.top.record tag configure marc-data -foreground black
669 $w.top.record delete 0.0 end
670 set recordType [z39.$sno recordType $no]
671 wm title $w "$recordType record #$no"
674 bind $w.top.record <Return> {destroy .full-marc}
676 pack $w.top.s -side right -fill y
677 pack $w.top.record -expand yes -fill both
680 bottom-buttons $w [list \
681 {Close} [list destroy $w]] 0
683 bottom-buttons $w [list \
684 {Close} [list destroy $w] \
685 {Duplicate} [list popup-marc $sno $no 1 0]] 0
686 menubutton $w.bot.formats -text "Format" -menu $w.bot.formats.m
687 menu $w.bot.formats.m
689 foreach f $displayFormats {
690 $w.bot.formats.m add radiobutton -label $f \
691 -variable popupMarcdf -value $i \
692 -command [list display-$f $sno $no $w.top.record 0]
695 pack $w.bot.formats -expand yes -ipadx 2 -ipady 2 \
696 -padx 3 -pady 3 -side left
700 foreach f $displayFormats {
701 $w.bot.formats.m entryconfigure $i \
702 -command [list display-$f $sno $no $w.top.record 0]
706 set ffunc [lindex $displayFormats $df]
707 set ffunc "display-$ffunc"
709 $ffunc $sno $no $w.top.record 0
712 proc update-target-hotlist {target base} {
715 set len [llength $hotTargets]
717 .top.target.m delete 6 [expr 6+[llength $hotTargets]]
720 foreach e $hotTargets {
721 if {$target == [lindex $e 0] && $base == [lindex $e 1]} {
722 set hotTargets [lreplace $hotTargets $i $i]
727 set hotTargets [linsert $hotTargets 0 [list $target $base]]
731 proc set-target-hotlist {} {
735 foreach e $hotTargets {
736 set target [lindex $e 0]
737 set base [lindex $e 1]
739 .top.target.m add command -label "$i $target" -command \
740 [list reopen-target $target {}]
742 .top.target.m add command -label "$i $target - $base" -command \
743 [list reopen-target $target $base]
752 proc reopen-target {target base} {
754 open-target $target $base
755 update-target-hotlist $target $base
758 proc define-target-action {} {
761 set target [.target-define.top.target.entry get]
765 foreach n [array names profile] {
771 set seq [lindex $profile(Default) 12]
773 set profile($target) $profile(Default)
774 set profile(Default) [lreplace $profile(Default) 12 12 [incr seq]]
776 protocol-setup $target
777 destroy .target-define
780 proc fail-response {target} {
781 set c [lindex [z39 failInfo] 0]
782 set m [lindex [z39 failInfo] 1]
787 proc connect-response {target base} {
788 dputs "connect-response"
789 show-target $target $base
793 proc open-target {target base} {
798 z39 comstack [lindex $profile($target) 6]
799 z39 protocol [lindex $profile($target) 11]
800 z39 idAuthentication [lindex $profile($target) 3]
801 z39 maximumRecordSize [lindex $profile($target) 4]
802 z39 preferredMessageSize [lindex $profile($target) 5]
803 dputs "maximumRecordSize="
804 dputs [z39 maximumRecordSize]
805 dputs "preferredMessageSize="
806 dputs [z39 preferredMessageSize]
807 show-status {Connecting} 1 0
809 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
811 z39 databaseNames $base
813 z39 failback [list fail-response $target]
814 z39 callback [list connect-response $target $base]
817 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
820 tkerror $errorMessage
821 show-status Ready 0 {}
825 .top.target.m disable 0
826 .top.target.m enable 1
827 .top.target.m enable 2
830 proc close-target {} {
837 .bot.a.set configure -text ""
841 show-status {Not connected} 0 0
844 .top.target.m disable 1
845 .top.target.m disable 2
846 .top.target.m enable 0
849 proc load-set-action {} {
853 ir-set z39.$setNo z39
855 set fname [.load-set.top.filename.entry get]
858 show-status {Loading} 1 {}
860 z39.$setNo loadFile $fname
862 set no [z39.$setNo numberOfRecordsReturned]
863 add-title-lines $setNo $no 1
865 set l [format "%-4d %7d" $setNo $no]
866 .top.rset.m add command -label $l \
867 -command [list add-title-lines $setNo 10000 1]
868 show-status {Ready} 0 {}
880 frame $w.top.filename
881 pack $w.top.filename -side top -anchor e -pady 2
883 entry-fields $w.top {filename} \
885 {load-set-action} {destroy .load-set}
887 top-down-ok-cancel $w {load-set-action} 1
891 proc init-request {} {
899 z39 callback {init-response}
900 show-status {Initializing} 1 {}
901 set err [catch {z39 init} errorMessage]
903 tkerror $errorMessage
904 show-status Ready 0 {}
908 proc init-response {} {
916 if {![z39 initResult]} {
917 show-status {Ready} 0 1
918 set u [z39 userInformationField]
920 tkerror "Connection rejected by target: $u"
922 if {[lsearch [z39 options] scan] >= 0} {
927 show-status {Ready} 0 1
931 proc search-request {bflag} {
942 dputs "search-request"
944 if {!$bflag && $busy} {
945 dputs "busy: search-request ignored"
950 show-status {Searching} 1 0
951 set delayRequest {search-request 1}
956 set query [index-query]
961 ir-set z39.$setNo z39
963 if {[lindex $profile($target) 10] == 1} {
964 z39.$setNo setName $setNo
965 dputs "setName=${setNo}"
967 z39.$setNo setName Default
968 dputs "setName=Default"
970 if {[lindex $profile($target) 8] == 1} {
971 z39.$setNo queryType rpn
973 if {[lindex $profile($target) 9] == 1} {
974 z39.$setNo queryType ccl
978 if {$recordSyntax == "None" } {
979 z39.$setNo preferredRecordSyntax {}
981 z39.$setNo preferredRecordSyntax $recordSyntax
983 z39 callback {search-response}
984 z39.$setNo search $query
985 show-status {Searching} 1 0
988 proc scan-copy {y entry} {
990 set no [$w.top.list nearest $y]
992 .lines.$entry.e delete 0 end
993 .lines.$entry.e insert 0 [string range [$w.top.list get $no] 8 end]
996 proc scan-request {} {
1003 global curIndexEntry
1004 global queryButtonsFind
1005 global queryInfoFind
1009 dputs "scan-request"
1012 show-status {Scanning} 1 0
1013 set delayRequest scan-request
1022 set b [lindex $queryButtonsFind $curIndexEntry]
1024 foreach a [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end] {
1025 set attr "@attr $a $attr"
1027 set title [lindex [lindex $queryInfoFind [lindex $b 1]] 0]
1028 ir-scan z39.scan z39
1030 if {![winfo exists $w]} {
1037 entry $w.top.entry -relief sunken
1038 pack $w.top.entry -fill x -padx 4 -pady 2
1039 bind $w.top.entry <KeyRelease> [list scan-term-h $attr]
1041 listbox $w.top.list -yscrollcommand [list $w.top.scroll set] \
1043 scrollbar $w.top.scroll -orient vertical -border 1
1044 pack $w.top.list -side left -fill both -expand yes
1045 pack $w.top.scroll -side right -fill y
1046 $w.top.scroll config -command [list $w.top.list yview]
1048 listbox $w.top.list -font fixed -geometry 60x14
1049 pack $w.top.list -side left -fill both -expand yes
1052 bottom-buttons $w [list {Close} [list destroy $w] \
1053 {Up} [list scan-up $attr] \
1054 {Down} [list scan-down $attr]] 0
1055 bind $w.top.list <Up> [list scan-up $attr]
1056 bind $w.top.list <Down> [list scan-down $attr]
1058 bind $w.top.list <Double-Button-1> [list scan-copy %y $curIndexEntry]
1059 wm title $w "Scan $title"
1061 z39 callback [list scan-response $attr 0 35]
1062 z39.scan numberOfTermsRequested 5
1063 z39.scan preferredPositionInResponse 1
1064 z39.scan scan "${attr} 0"
1066 show-status {Scanning} 1 0
1069 proc scan-term-h {attr} {
1077 set nScanTerm [$w.top.entry get]
1078 if {$nScanTerm == $scanTerm} {
1081 set scanTerm $nScanTerm
1082 z39 callback [list scan-response $attr 0 35]
1083 z39.scan numberOfTermsRequested 5
1084 z39.scan preferredPositionInResponse 1
1085 dputs "${attr} \{${scanTerm}\}"
1086 if {$scanTerm == ""} {
1087 z39.scan scan "${attr} 0"
1089 z39.scan scan "${attr} \{${scanTerm}\}"
1091 show-status {Scanning} 1 0
1094 proc scan-response {attr start toget} {
1101 dputs "In scan-response"
1102 set m [z39.scan numberOfEntriesReturned]
1108 if {![winfo exists .scan-window]} {
1111 dputs "Handling cancel"
1112 if {$delayRequest != ""} {
1117 show-status {Ready} 0 1
1120 set nScanTerm [$w.top.entry get]
1121 if {$nScanTerm != $scanTerm} {
1122 z39 callback [list scan-response $attr 0 35]
1123 z39.scan numberOfTermsRequested 5
1124 z39.scan preferredPositionInResponse 1
1125 set scanTerm $nScanTerm
1126 dputs "${attr} \{${scanTerm}\}"
1127 if {$scanTerm == ""} {
1128 z39.scan scan "${attr} 0"
1130 z39.scan scan "${attr} \{${scanTerm}\}"
1132 show-status {Scanning} 1 0
1135 set status [z39.scan scanStatus]
1138 show-status {Ready} 0 1
1143 for {set i 0} {$i < $m} {incr i} {
1144 set term [lindex [z39.scan scanLine $i] 1]
1145 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1146 $w.top.list insert $i "$nostr $term"
1149 $w.top.list yview $scanView
1151 $w.top.list delete $start end
1152 for {set i 0} {$i < $m} {incr i} {
1153 set term [lindex [z39.scan scanLine $i] 1]
1154 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1155 $w.top.list insert end "$nostr $term"
1159 dputs "Handling cancel"
1161 if {$delayRequest != ""} {
1167 if {$toget > 0 && $m > 1 && $m < $toget} {
1168 set ntoget [expr $toget - $m + 1]
1169 dputs ntoget=$ntoget
1170 z39 callback [list scan-response $attr [expr $start + $m - 1] $ntoget]
1172 dputs "down continue: $q"
1174 z39.scan numberOfTermsRequested 10
1176 z39.scan numberOfTermsRequested $ntoget
1178 z39.scan preferredPositionInResponse 1
1179 dputs "${attr} \{$q\}"
1180 z39.scan scan "${attr} \{$q\}"
1183 if {$toget < 0 && $m > 1 && $m < [expr - $toget]} {
1184 set ntoget [expr - $toget - $m]
1185 dputs ntoget=$ntoget
1186 z39 callback [list scan-response $attr 0 -$ntoget]
1187 set q [string range [$w.top.list get 0] 8 end]
1188 dputs "up continue: $q"
1190 z39.scan numberOfTermsRequested 10
1191 z39.scan preferredPositionInResponse 11
1193 z39.scan numberOfTermsRequested $ntoget
1194 z39.scan preferredPositionInResponse [incr ntoget]
1196 dputs "${attr} \{$q\}"
1197 z39.scan scan "${attr} \{$q\}"
1200 show-status {Ready} 0 1
1203 proc scan-down {attr} {
1211 show-status {Scanning down} 1 0
1212 set delayRequest [list scan-down $attr]
1218 set scanView [expr $scanView + 5]
1219 set s [$w.top.list size]
1220 if {$scanView > $s} {
1221 z39 callback [list scan-response $attr [expr $s - 1] 25]
1222 set q [string range [$w.top.list get [expr $s - 1]] 8 end]
1224 z39.scan numberOfTermsRequested 10
1225 z39.scan preferredPositionInResponse 1
1226 show-status {Scanning} 1 0
1227 dputs "${attr} \{$q\}"
1228 z39.scan scan "${attr} \{$q\}"
1231 $w.top.list yview $scanView
1234 proc scan-up {attr} {
1242 show-status {Scanning up} 1 0
1243 set delayRequest [list scan-up $attr]
1249 set scanView [expr $scanView - 5]
1250 if {$scanView < 0} {
1251 z39 callback [list scan-response $attr 0 -25]
1252 set q [string range [$w.top.list get 0] 8 end]
1254 z39.scan numberOfTermsRequested 10
1255 z39.scan preferredPositionInResponse 11
1256 show-status {Scanning} 1 0
1257 z39.scan scan "${attr} \{$q\}"
1260 $w.top.list yview $scanView
1263 proc search-response {} {
1271 dputs "In search-response"
1273 dputs "Handling cancel"
1275 if {$delayRequest != ""} {
1282 set setMax [z39.$setNo resultCount]
1283 show-status {Ready} 0 1
1284 set status [z39.$setNo responseStatus]
1285 if {[lindex $status 0] == "NSD"} {
1287 set code [lindex $status 1]
1288 set msg [lindex $status 2]
1289 set addinfo [lindex $status 3]
1290 tkerror "NSD$code: $msg: $addinfo"
1296 show-message "${setMax} hits"
1298 show-status {Ready} 0 1
1299 set l [format "%-4d %7d" $setNo $setMax]
1300 .top.rset.m add command -label $l \
1301 -command [list add-title-lines $setNo 10000 1]
1302 z39 callback {present-response}
1303 z39.$setNo present $setOffset 1
1304 show-status {Retrieving} 1 0
1307 proc present-more {number} {
1315 dputs "present-more"
1317 show-status {Retrieving} 1 0
1318 set delayRequest "present-more $number"
1324 dputs "setNo=$setNo"
1327 set max [z39.$setNo resultCount]
1328 if {$max <= $setOffset} {
1330 dputs "setOffset=$setOffset"
1333 if {$number == ""} {
1337 if {$setMax > $max} {
1341 z39 callback {present-response}
1343 set toGet [expr $setMax - $setOffset + 1]
1350 z39.$setNo present $setOffset $toGet
1351 show-status {Retrieving} 1 0
1354 proc init-title-lines {} {
1355 .data.record delete 0.0 end
1358 proc title-press {y setno} {
1359 show-full-marc $setno [expr 1 + [.data.list nearest $y]] 0
1362 proc add-title-lines {setno no offset} {
1363 global displayFormats
1364 global displayFormat
1368 set setno $lastSetNo
1370 set lastSetNo $setno
1373 .bot.a.set configure -text $setno
1374 .data.record delete 0.0 end
1376 set ffunc [lindex $displayFormats $displayFormat]
1377 dputs "ffunc=$ffunc"
1378 set ffunc "display-$ffunc"
1379 for {set i 0} {$i < $no} {incr i} {
1380 set o [expr $i + $offset]
1381 set type [z39.$setno type $o]
1385 .data.record tag bind r$o <Any-Enter> {}
1386 .data.record tag bind r$o <Any-Leave> {}
1387 set insert0 [.data.record index insert]
1388 $ffunc $setno $o .data.record 1
1389 .data.record tag add r$o $insert0 insert
1390 .data.record tag bind r$o <1> \
1391 [list popup-marc $setno $o 0 0]
1396 proc present-response {} {
1403 dputs "In present-response"
1404 set no [z39.$setNo numberOfRecordsReturned]
1405 dputs "Returned $no records, setOffset $setOffset"
1406 add-title-lines $setNo $no $setOffset
1407 set setOffset [expr $setOffset + $no]
1409 dputs "Handling cancel"
1411 if {$delayRequest != ""} {
1416 set status [z39.$setNo responseStatus]
1417 if {[lindex $status 0] == "NSD"} {
1418 show-status {Ready} 0 1
1419 set code [lindex $status 1]
1420 set msg [lindex $status 2]
1421 set addinfo [lindex $status 3]
1422 tkerror "NSD$code: $msg: $addinfo"
1425 if {$no > 0 && $setOffset <= $setMax} {
1426 dputs "present-request from ${setOffset}"
1427 set toGet [expr $setMax - $setOffset + 1]
1431 z39.$setNo present $setOffset $toGet
1433 show-status {Ready} 0 1
1437 proc left-cursor {w} {
1438 set i [$w index insert]
1445 proc right-cursor {w} {
1446 set i [$w index insert]
1451 proc bind-fields {list returnAction escapeAction} {
1452 set max [expr [llength $list]-1]
1453 for {set i 0} {$i < $max} {incr i} {
1454 bind [lindex $list $i] <Return> $returnAction
1455 bind [lindex $list $i] <Escape> $escapeAction
1456 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
1457 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1458 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1460 bind [lindex $list $i] <Return> $returnAction
1461 bind [lindex $list $i] <Escape> $escapeAction
1462 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
1463 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1464 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1465 focus [lindex $list 0]
1468 proc entry-fields {parent list tlist returnAction escapeAction} {
1471 foreach field $list {
1472 set label ${parent}.${field}.label
1473 set entry ${parent}.${field}.entry
1474 label $label -text [lindex $tlist $i] -anchor e
1475 entry $entry -width 32 -relief sunken
1476 pack $label -side left
1477 pack $entry -side right
1478 lappend alist $entry
1481 bind-fields $alist $returnAction $escapeAction
1484 proc define-target-dialog {} {
1485 set w .target-define
1491 pack $w.top.target \
1492 -side top -anchor e -pady 2
1493 entry-fields $w.top {target} \
1495 {define-target-action} {destroy .target-define}
1496 top-down-ok-cancel $w {define-target-action} 1
1499 proc protocol-setup-delete {target} {
1501 global settingsChanged
1503 set a [alert "Are you sure you want to delete the target \
1504 definition $target ?"]
1506 set wno [lindex $profile($target) 12]
1509 unset profile($target)
1510 set settingsChanged 1
1515 proc protocol-setup-action {target} {
1518 global protocolRadioType
1519 global settingsChanged
1522 global ResultSetCheck
1524 set wno [lindex $profile($target) 12]
1528 set settingsChanged 1
1529 set len [$w.top.databases.list size]
1530 for {set i 0} {$i < $len} {incr i} {
1531 lappend b [$w.top.databases.list get $i]
1533 set profile($target) [list [$w.top.description.entry get] \
1534 [$w.top.host.entry get] \
1535 [$w.top.port.entry get] \
1536 [$w.top.idAuthentication.entry get] \
1537 [$w.top.maximumRecordSize.entry get] \
1538 [$w.top.preferredMessageSize.entry get] \
1544 $protocolRadioType \
1548 dputs $profile($target)
1552 proc place-force {window parent} {
1553 set g [wm geometry $parent]
1555 set p1 [string first + $g]
1556 set p2 [string last + $g]
1558 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
1559 set y [expr 60+[string range $g [expr $p2 +1] end]]
1560 wm geometry $window +${x}+${y}
1563 proc add-database-action {target} {
1566 set wno [lindex $profile($target) 12]
1569 $w.top.databases.list insert end \
1570 [.database-select.top.database.entry get]
1571 destroy .database-select
1574 proc add-database {target} {
1577 set w .database-select
1579 set oldFocus [focus]
1582 set wno [lindex $profile($target) 12]
1583 place-force $w .setup-${wno}
1587 frame $w.top.database
1589 pack $w.top.database -side top -anchor e -pady 2
1591 entry-fields $w.top {database} \
1592 {{Database to add:}} \
1593 [list add-database-action $target] {destroy .database-select}
1595 top-down-ok-cancel $w [list add-database-action $target] 1
1599 proc delete-database {target} {
1602 set wno [lindex $profile($target) 12]
1605 foreach i [$w.top.databases.list curselection] {
1606 set b [$w.top.databases.list get $i]
1609 set a [alert "Are you sure you want to remove the database(s)${l}?"]
1611 foreach i [lsort -decreasing \
1612 [$w.top.databases.list curselection]] {
1613 $w.top.databases.list delete $i
1618 proc protocol-setup {target} {
1621 global protocolRadioType
1624 global ResultSetCheck
1626 set wno [lindex $profile($target) 12]
1631 wm title $w "Setup $target"
1635 if {$target == ""} {
1639 dputs $profile($target)
1643 frame $w.top.description
1644 frame $w.top.idAuthentication
1645 frame $w.top.maximumRecordSize
1646 frame $w.top.preferredMessageSize
1647 frame $w.top.cs-type -relief ridge -border 2
1648 frame $w.top.protocol -relief ridge -border 2
1649 frame $w.top.query -relief ridge -border 2
1650 frame $w.top.databases -relief ridge -border 2
1652 # Maximum/preferred/idAuth ...
1653 pack $w.top.description $w.top.host $w.top.port \
1654 $w.top.idAuthentication $w.top.maximumRecordSize \
1655 $w.top.preferredMessageSize -side top -anchor e -pady 2
1657 entry-fields $w.top {description host port idAuthentication \
1658 maximumRecordSize preferredMessageSize} \
1659 {{Description:} {Host:} {Port:} {Id Authentication:} \
1660 {Maximum Record Size:} {Preferred Message Size:}} \
1661 [list protocol-setup-action $target] [list destroy $w]
1663 foreach sub {description host port idAuthentication \
1664 maximumRecordSize preferredMessageSize} {
1666 bind $w.top.$sub.entry <Control-a> [list add-database $target]
1667 bind $w.top.$sub.entry <Control-d> [list delete-database $target]
1669 $w.top.description.entry insert 0 [lindex $profile($target) 0]
1670 $w.top.host.entry insert 0 [lindex $profile($target) 1]
1671 $w.top.port.entry insert 0 [lindex $profile($target) 2]
1672 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
1673 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
1674 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
1675 set csRadioType [lindex $profile($target) 6]
1676 set RPNCheck [lindex $profile($target) 8]
1677 set CCLCheck [lindex $profile($target) 9]
1678 set ResultSetCheck [lindex $profile($target) 10]
1679 set protocolRadioType [lindex $profile($target) 11]
1680 if {$protocolRadioType == ""} {
1681 set protocolRadioType Z39
1685 pack $w.top.databases -side left -pady 4 -padx 4 -expand yes -fill both
1687 label $w.top.databases.label -text "Databases"
1688 button $w.top.databases.add -text "Add" \
1689 -command [list add-database $target]
1690 button $w.top.databases.delete -text "Delete" \
1691 -command [list delete-database $target]
1692 listbox $w.top.databases.list -geometry 20x6 \
1693 -yscrollcommand "$w.top.databases.scroll set"
1694 scrollbar $w.top.databases.scroll -orient vertical -border 1
1695 pack $w.top.databases.label -side top -fill x \
1697 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
1699 pack $w.top.databases.list -side left -fill both -expand yes \
1701 pack $w.top.databases.scroll -side right -fill y \
1703 $w.top.databases.scroll config -command "$w.top.databases.list yview"
1705 foreach b [lindex $profile($target) 7] {
1706 $w.top.databases.list insert end $b
1710 pack $w.top.cs-type -pady 4 -padx 4 -side top -fill x
1712 label $w.top.cs-type.label -text "Transport"
1713 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" -anchor w \
1714 -variable csRadioType -value tcpip
1715 radiobutton $w.top.cs-type.mosi -text "MOSI" -anchor w\
1716 -variable csRadioType -value mosi
1718 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
1719 -padx 4 -side top -fill x
1722 pack $w.top.protocol -pady 4 -padx 4 -side top -fill x
1724 label $w.top.protocol.label -text "Protocol"
1725 radiobutton $w.top.protocol.z39v2 -text "Z39.50" -anchor w \
1726 -variable protocolRadioType -value Z39
1727 radiobutton $w.top.protocol.sr -text "SR" -anchor w \
1728 -variable protocolRadioType -value SR
1730 pack $w.top.protocol.label $w.top.protocol.z39v2 $w.top.protocol.sr \
1731 -padx 4 -side top -fill x
1734 pack $w.top.query -pady 4 -padx 4 -side top -fill x
1736 label $w.top.query.label -text "Query support"
1737 checkbutton $w.top.query.c1 -text "RPN query" -anchor w -variable RPNCheck
1738 checkbutton $w.top.query.c2 -text "CCL query" -anchor w -variable CCLCheck
1739 checkbutton $w.top.query.c3 -text "Result sets" -anchor w -variable ResultSetCheck
1741 pack $w.top.query.label -side top
1742 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
1743 -padx 4 -side top -fill x
1746 bottom-buttons $w [list {Ok} [list protocol-setup-action $target] \
1747 {Delete} [list protocol-setup-delete $target] \
1748 {Cancel} [list destroy $w]] 0
1751 proc database-select-action {} {
1752 set w .database-select.top
1754 foreach indx [$w.databases.list curselection] {
1755 lappend b [$w.databases.list get $indx]
1758 z39 databaseNames $b
1760 destroy .database-select
1763 proc database-select {} {
1764 set w .database-select
1774 frame $w.top.databases -relief ridge -border 2
1776 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
1778 label $w.top.databases.label -text "List"
1779 listbox $w.top.databases.list -geometry 20x6 \
1780 -yscrollcommand "$w.top.databases.scroll set"
1781 scrollbar $w.top.databases.scroll -orient vertical -border 1
1782 pack $w.top.databases.label -side top -fill x \
1784 pack $w.top.databases.list -side left -fill both -expand yes \
1786 pack $w.top.databases.scroll -side right -fill y \
1788 $w.top.databases.scroll config -command "$w.top.databases.list yview"
1790 foreach b [lindex $profile($hostid) 7] {
1791 $w.top.databases.list insert end $b
1793 top-down-ok-cancel $w {database-select-action} 1
1796 proc cascade-target-list {} {
1799 foreach sub [winfo children .top.target.m.clist] {
1802 .top.target.m.clist delete 0 last
1803 foreach n [array names profile] {
1804 if {$n != "Default"} {
1805 set nl [lindex $profile($n) 12]
1806 if {[llength [lindex $profile($n) 7]] > 1} {
1807 .top.target.m.clist add cascade -label $n \
1808 -menu .top.target.m.clist.$nl
1809 menu .top.target.m.clist.$nl
1810 foreach b [lindex $profile($n) 7] {
1811 .top.target.m.clist.$nl add command -label $b \
1812 -command [list reopen-target $n $b]
1815 .top.target.m.clist add command -label $n \
1816 -command [list reopen-target $n {}]
1820 .top.target.m.slist delete 0 last
1821 foreach n [array names profile] {
1822 if {$n != "Default"} {
1823 .top.target.m.slist add command -label $n \
1824 -command [list protocol-setup $n]
1829 proc query-select {i} {
1830 global queryButtonsFind
1831 global queryInfoFind
1835 set queryInfoFind [lindex $queryInfo $i]
1836 set queryButtonsFind [lindex $queryButtons $i]
1838 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
1841 proc query-new-action {} {
1845 global settingsChanged
1847 set settingsChanged 1
1848 lappend queryTypes [.query-new.top.index.entry get]
1849 lappend queryButtons {}
1850 lappend queryInfo {}
1864 -side top -anchor e -pady 2
1865 entry-fields $w.top index \
1867 query-new-action {destroy .query-new}
1868 top-down-ok-cancel $w query-new-action 1
1871 proc query-delete-action {queryNo} {
1875 global settingsChanged
1877 set settingsChanged 1
1879 set queryTypes [lreplace $queryTypes $queryNo $queryNo]
1880 set queryButtons [lreplace $queryButtons $queryNo $queryNo]
1881 set queryInfo [lreplace $queryInfo $queryNo $queryNo]
1882 destroy .query-delete
1886 proc query-delete {queryNo} {
1894 set n [lindex $queryTypes $queryNo]
1896 label $w.top.warning -bitmap warning
1897 message $w.top.quest -text "Are you sure you want to delete the \
1898 query type $n ?" -aspect 200
1899 pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
1900 bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
1901 {Cancel} [list destroy $w]] 1
1904 proc cascade-query-list {} {
1906 set w .top.options.m.query
1909 $w.slist delete 0 last
1910 foreach n $queryTypes {
1911 $w.slist add command -label $n -command [list query-setup $i]
1916 $w.clist delete 0 last
1917 foreach n $queryTypes {
1918 $w.clist add command -label $n -command [list query-select $i]
1922 $w.dlist delete 0 last
1923 foreach n $queryTypes {
1924 $w.dlist add command -label $n -command [list query-delete $i]
1929 proc save-geometry {} {
1930 global windowGeometry
1933 global displayFormat
1937 set windowGeometry(.) [wm geometry .]
1939 set f [open "~/.clientrc.tcl" w]
1941 puts $f "set hotTargets \{ $hotTargets \}"
1942 puts $f "set textWrap $textWrap"
1943 puts $f "set displayFormat $displayFormat"
1944 puts $f "set popupMarcdf $popupMarcdf"
1945 puts $f "set recordSyntax $recordSyntax"
1946 foreach n [array names windowGeometry] {
1947 puts -nonewline $f "set \{windowGeometry($n)\} \{"
1948 puts -nonewline $f $windowGeometry($n)
1954 proc save-settings {} {
1957 global settingsChanged
1962 if {![file writable "${libdir}/clientrc.tcl"]} {
1965 set f [open "${libdir}/clientrc.tcl" w]
1966 puts $f "# Setup file"
1968 foreach n [array names profile] {
1969 puts -nonewline $f "set \{profile($n)\} \{"
1970 puts -nonewline $f $profile($n)
1973 puts -nonewline $f "set queryTypes \{"
1974 puts -nonewline $f $queryTypes
1977 puts -nonewline $f "set queryButtons \{"
1978 puts -nonewline $f $queryButtons
1981 puts -nonewline $f "set queryInfo \{"
1982 puts -nonewline $f $queryInfo
1985 set settingsChanged 0
1997 label $w.top.warning -bitmap warning
1998 message $w.top.message -text $ask -aspect 200 \
1999 -font -Adobe-Times-Medium-R-Normal-*-180-*
2001 pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
2004 top-down-ok-cancel $w {alert-action} 1
2008 proc alert-action {} {
2014 proc exit-action {} {
2015 global settingsChanged
2017 if {$settingsChanged} {
2018 set a [alert "you haven't saved your settings. Do you wish to save?"]
2027 proc listbuttonaction {w name h user i} {
2028 $w configure -text [lindex $name 0]
2029 $h [lindex $name 1] $user $i
2032 proc listbuttonx {button no names handle user} {
2033 if {[winfo exists $button]} {
2034 $button configure -text [lindex [lindex $names $no] 0]
2035 ${button}.m delete 0 last
2037 menubutton $button -text [lindex [lindex $names $no] 0] \
2038 -width 10 -menu ${button}.m -relief raised -border 1
2042 foreach name $names {
2043 ${button}.m add command -label [lindex $name 0] \
2044 -command [list listbuttonaction ${button} $name \
2050 proc listbutton {button no names} {
2051 menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
2052 -relief raised -border 1
2054 foreach name $names {
2055 ${button}.m add command -label $name \
2056 -command [list ${button} configure -text $name]
2060 proc listbuttonv-action {button var names i} {
2063 set $var [lindex $names [expr $i+1]]
2064 $button configure -text [lindex $names $i]
2067 proc listbuttonv {button var names} {
2071 eval "set val $$var"
2072 set l [llength $names]
2073 for {set i 1} {$i < $l} {incr i 2} {
2074 if {$val == [lindex $names $i]} {
2076 set n [lindex $names $i]
2080 if {[winfo exists $button]} {
2081 $button configure -text $n
2084 menubutton $button -text $n -menu ${button}.m \
2085 -relief raised -border 1
2087 for {set i 0} {$i < $l} {incr i 2} {
2088 ${button}.m add command -label [lindex $names $i] \
2089 -command [list listbuttonv-action $button $var $names $i]
2093 proc query-add-index-action {queryNo} {
2097 global queryButtonsTmp
2099 set newI [.query-add-index.top.index.entry get]
2100 lappend queryInfoTmp [list $newI {}]
2101 $w.top.index.list insert end $newI
2102 destroy .query-add-index
2103 #destroy $w.top.lines
2104 #frame $w.top.lines -relief ridge -border 2
2105 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2106 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2109 proc query-add-line {queryNo} {
2113 global queryButtonsTmp
2115 lappend queryButtonsTmp {I 0}
2117 #destroy $w.top.lines
2118 #frame $w.top.lines -relief ridge -border 2
2119 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2120 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2123 proc query-del-line {queryNo} {
2127 global queryButtonsTmp
2129 set l [llength $queryButtonsTmp]
2134 set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
2135 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2138 proc query-add-index {queryNo} {
2139 set w .query-add-index
2142 place-force $w .query-setup
2146 -side top -anchor e -pady 2
2147 entry-fields $w.top {index} \
2149 [list query-add-index-action $queryNo] [list destroy $w]
2150 top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
2153 proc query-setup-action {queryNo} {
2156 global queryButtonsTmp
2158 global queryButtonsFind
2159 global queryInfoFind
2161 global settingsChanged
2163 set settingsChanged 1
2165 set queryInfo [lreplace $queryInfo $queryNo $queryNo \
2167 set queryButtons [lreplace $queryButtons $queryNo $queryNo \
2169 set queryInfoFind $queryInfoTmp
2170 set queryButtonsFind $queryButtonsTmp
2172 destroy .query-setup
2173 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2176 proc activate-e-index {value no i} {
2177 global queryButtonsTmp
2178 global queryIndexTmp
2180 set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
2181 dputs $queryButtonsTmp
2182 set queryIndexTmp $i
2185 proc activate-index {value no i} {
2186 global queryButtonsFind
2188 set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
2190 dputs "queryButtonsFind $queryButtonsFind"
2193 proc update-attr {} {
2195 listbuttonv $w.top.relation.b relationTmpValue\
2196 {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
2197 {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
2198 {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
2199 listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
2200 {First in field} 1 {First in subfield} 2 {Any position in field} 3}
2201 listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
2202 {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list} 6 \
2203 {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
2204 {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
2205 {local-number} 107 {string} 108 {numeric string} 109}
2206 listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
2207 {Left} 2 {Left and right} 3 {No truncation} 100 \
2208 {Process #} 101 {Re-1} 102 {Re-2} 103}
2209 listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
2210 {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
2213 proc use-attr {init} {
2225 {BNB card number} 10
2226 {BGF(sic) number} 11
2228 {Dewey classification} 13
2229 {UDC classification} 14
2230 {Bliss classification} 15
2232 {NLM call number} 17
2233 {NAL call number} 18
2234 {MOS call number} 19
2235 {Local classification} 20
2236 {Subject heading} 21
2238 {BDI-index-subject} 23
2242 {LC-subject-heading} 27
2243 {RVM-subject-heading} 28
2244 {Local subject index} 29
2246 {Date of publication} 31
2247 {Date of acquisition} 32
2249 {Title-collective} 34
2252 {Title-added-title-page} 37
2256 {Title-other-variant} 41
2258 {Title-abbreviated} 43
2262 {Subject-subdivision} 47
2263 {Number-natl-bibliography} 48
2264 {Number-legal-deposit} 49
2265 {Number-govt-publication} 50
2266 {Number-publisher-for-music} 51
2268 {Number-local-call} 53
2270 {Code-geographic-area} 55
2271 {Code-institution} 56
2273 {Name-geographic} 58
2274 {Place-publication} 59
2276 {Microform-generation} 61
2283 {Author-name-personal} 1004
2284 {Author-name-corporate} 1005
2285 {Author-name-conference} 1006
2286 {Identifier-standard} 1007
2287 {Subject-LC-children's} 1008
2288 {Subject-name-personal} 1009
2290 {Date/time added to database} 1011
2291 {Date/time last modified} 1012
2292 {Authority/format identifier} 1013
2294 {Concept-reference} 1015
2296 {Server choice} 1017
2298 {Record source} 1019
2301 {Geographic class} 1022
2305 {Related periodical} 1026
2306 {Report number} 1027
2308 {Thematic number} 1030
2309 {Material type} 1031
2317 set l [llength $attr]
2322 for {set i 0} {$i < $l} {incr i} {
2323 $w.top.use.list insert end [lindex $attr $i]
2325 if {$useTmpValue == [lindex $attr $i]} {
2330 $w.top.use.list select from $s
2331 $w.top.use.list select to $s
2336 $w.top.use.list yview $s
2338 set lno [lindex [$w.top.use.list curselection] 0]
2339 set i [expr $lno+$lno+1]
2340 set useTmpValue [lindex $attr $i]
2341 dputs "useTmpValue=$useTmpValue"
2345 proc index-setup-action {oldAttr queryNo indexNo} {
2346 set attr [lindex $oldAttr 0]
2349 global relationTmpValue
2350 global structureTmpValue
2351 global truncationTmpValue
2352 global completenessTmpValue
2353 global positionTmpValue
2358 dputs "index-setup-action"
2359 dputs "queryNo $queryNo"
2360 dputs "indexNo $indexNo"
2361 if {$useTmpValue > 0} {
2362 lappend attr "1=$useTmpValue"
2364 if {$relationTmpValue > 0} {
2365 lappend attr "2=$relationTmpValue"
2367 if {$positionTmpValue > 0} {
2368 lappend attr "3=$positionTmpValue"
2370 if {$structureTmpValue > 0} {
2371 lappend attr "4=$structureTmpValue"
2373 if {$truncationTmpValue > 0} {
2374 lappend attr "5=$truncationTmpValue"
2376 if {$completenessTmpValue > 0} {
2377 lappend attr "6=$completenessTmpValue"
2379 dputs "new attr $attr"
2380 set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
2381 destroy .index-setup
2384 proc index-setup {attr queryNo indexNo} {
2387 global relationTmpValue
2388 global structureTmpValue
2389 global truncationTmpValue
2390 global completenessTmpValue
2391 global positionTmpValue
2393 set relationTmpValue 0
2394 set truncationTmpValue 0
2395 set structureTmpValue 0
2396 set positionTmpValue 0
2397 set completenessTmpValue 0
2400 set len [llength $attr]
2401 for {set i 1} {$i < $len} {incr i} {
2402 set q [lindex $attr $i]
2403 set l [string first = $q]
2405 set t [string range $q 0 [expr $l - 1]]
2406 set v [string range $q [expr $l + 1] end]
2409 { set useTmpValue $v }
2411 { set relationTmpValue $v }
2413 { set positionTmpValue $v }
2415 { set structureTmpValue $v }
2417 { set truncationTmpValue $v }
2419 { set completenessTmpValue $v }
2423 if {[winfo exists $w]} {
2428 set n [lindex $attr 0]
2429 wm title $w "Index setup $n"
2433 frame $w.top.use -relief ridge -border 2
2434 frame $w.top.relation -relief ridge -border 2
2435 frame $w.top.position -relief ridge -border 2
2436 frame $w.top.structure -relief ridge -border 2
2437 frame $w.top.truncation -relief ridge -border 2
2438 frame $w.top.completeness -relief ridge -border 2
2444 pack $w.top.use -side left -pady 6 -padx 6 -fill y
2446 label $w.top.use.label -text "Use"
2447 listbox $w.top.use.list -geometry 26x10 \
2448 -yscrollcommand "$w.top.use.scroll set"
2449 scrollbar $w.top.use.scroll -orient vertical -border 1
2450 pack $w.top.use.label -side top -fill x \
2452 pack $w.top.use.list -side left -fill both -expand yes \
2454 pack $w.top.use.scroll -side right -fill y \
2456 $w.top.use.scroll config -command "$w.top.use.list yview"
2460 # Relation Attributes
2462 pack $w.top.relation -pady 6 -padx 6 -side top
2463 label $w.top.relation.label -text "Relation" -width 18
2465 pack $w.top.relation.label $w.top.relation.b -fill x
2467 # Position Attributes
2469 pack $w.top.position -pady 6 -padx 6 -side top
2470 label $w.top.position.label -text "Position" -width 18
2472 pack $w.top.position.label $w.top.position.b -fill x
2474 # Structure Attributes
2476 pack $w.top.structure -pady 6 -padx 6 -side top
2477 label $w.top.structure.label -text "Structure" -width 18
2479 pack $w.top.structure.label $w.top.structure.b -fill x
2481 # Truncation Attributes
2483 pack $w.top.truncation -pady 6 -padx 6 -side top
2484 label $w.top.truncation.label -text "Truncation" -width 18
2486 pack $w.top.truncation.label $w.top.truncation.b -fill x
2488 # Completeness Attributes
2490 pack $w.top.completeness -pady 6 -padx 6 -side top
2491 label $w.top.completeness.label -text "Completeness" -width 18
2493 pack $w.top.completeness.label $w.top.completeness.b -fill x
2496 bottom-buttons $w [list \
2497 {Ok} [list index-setup-action $attr $queryNo $indexNo] \
2498 {Cancel} [list destroy $w]] 0
2502 proc query-edit-index {queryNo} {
2506 set i [lindex [$w.top.index.list curselection] 0]
2510 set attr [lindex $queryInfoTmp $i]
2511 dputs "Editing no $i $attr"
2512 index-setup $attr $queryNo $i
2515 proc query-delete-index {queryNo} {
2517 global queryButtonsTmp
2520 set i [lindex [$w.top.index.list curselection] 0]
2524 set queryInfoTmp [lreplace $queryInfoTmp $i $i]
2525 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2526 $w.top.index.list delete $i
2529 proc query-setup {queryNo} {
2535 global queryButtonsTmp
2537 global queryIndexTmp
2540 set queryName [lindex $queryTypes $queryNo]
2541 set queryInfoTmp [lindex $queryInfo $queryNo]
2542 set queryButtonsTmp [lindex $queryButtons $queryNo]
2547 wm title $w "Query setup $queryName"
2551 frame $w.top.lines -relief ridge -border 2
2553 pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2557 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2559 button $w.top.lines.add -text "Add" \
2560 -command [list query-add-line $queryNo]
2561 button $w.top.lines.del -text "Remove" \
2562 -command [list query-del-line $queryNo]
2564 pack $w.top.lines.del -fill x -side bottom
2565 pack $w.top.lines.add -fill x -pady 10 -side bottom
2569 frame $w.top.index -relief ridge -border 2
2570 pack $w.top.index -pady 6 -padx 6 -side right -fill y
2572 listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
2573 scrollbar $w.top.index.scroll -orient vertical -border 1 \
2574 -command [list $w.top.index.list yview]
2575 bind $w.top.index.list <2> [list query-edit-index $queryNo]
2577 pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
2578 pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
2580 $w.top.index.list select from 0
2581 $w.top.index.list select to 0
2583 foreach x $queryInfoTmp {
2584 $w.top.index.list insert end [lindex $x 0]
2587 bottom-buttons $w [list \
2588 {Ok} [list query-setup-action $queryNo] \
2589 {Add index} [list query-add-index $queryNo] \
2590 {Edit index} [list query-edit-index $queryNo] \
2591 {Delete index} [list query-delete-index $queryNo] \
2592 {Cancel} [list destroy $w]] 0
2595 proc index-clear {} {
2596 global queryButtonsFind
2599 foreach b $queryButtonsFind {
2600 .lines.$i.e delete 0 end
2605 proc index-query {} {
2606 global queryButtonsFind
2607 global queryInfoFind
2612 foreach b $queryButtonsFind {
2613 set term [string trim [.lines.$i.e get]]
2615 set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
2617 set len [string length $term]
2621 if {[string index $term $len] == "?"} {
2623 set term [string range $term 0 [expr $len - 1]]
2625 if {[string index $term 0] == "?"} {
2627 set term [string range $term 1 end]
2629 set term "\{${term}\}"
2630 if {$right && $left} {
2631 set term "@attr 5=3 ${term}"
2633 set term "@attr 5=1 ${term}"
2635 set term "@attr 5=2 ${term}"
2638 set term "@attr $a ${term}"
2641 set qs "@and ${qs} ${term}"
2652 proc index-focus-in {w i} {
2653 global curIndexEntry
2655 $w.$i configure -background red
2656 set curIndexEntry $i
2659 proc index-lines {w realOp buttonInfo queryInfo handle} {
2661 foreach b $buttonInfo {
2662 if {! [winfo exists $w.$i]} {
2663 frame $w.$i -background white -border 1
2665 listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
2668 if {! [winfo exists $w.$i.e]} {
2669 entry $w.$i.e -width 32 -relief sunken -border 1
2670 bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
2671 bind $w.$i.e <FocusOut> [list $w.$i configure \
2673 pack $w.$i.l -side left
2674 pack $w.$i.e -side left -fill x -expand yes
2675 pack $w.$i -side top -fill x -padx 2 -pady 2
2676 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
2677 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
2678 bind $w.$i.e <Return> {search-request 0}
2681 pack $w.$i.l -side left
2682 pack $w.$i -side top -fill x -padx 2 -pady 2
2687 while {[winfo exists $w.$j]} {
2698 bind $w.$j.e <Tab> "focus $w.$k.e"
2702 bind $w.$i.e <Tab> "focus $w.0.e"
2707 proc search-fields {w buttondefs} {
2709 foreach buttondef $buttondefs {
2710 frame $w.$i -background white
2712 listbutton $w.$i.l 0 $buttondef
2713 entry $w.$i.e -width 32 -relief sunken
2715 pack $w.$i.l -side left
2716 pack $w.$i.e -side left -fill x -expand yes
2718 pack $w.$i -side top -fill x -padx 2 -pady 2
2720 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
2721 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
2729 bind $w.$j.e <Tab> "focus $w.$k.e \n
2730 $w.$k configure -background red \n
2731 $w.$j configure -background white"
2734 bind $w.$i.e <Tab> "focus $w.0.e \n
2735 $w.0 configure -background red \n
2736 $w.$i configure -background white"
2738 $w.0 configure -background red
2741 if {[info exists windowGeometry(.)]} {
2742 set g $windowGeometry(.)
2750 frame .top -border 1 -relief raised
2751 frame .lines -border 1 -relief raised
2752 frame .mid -border 1 -relief raised
2753 frame .data -border 1 -relief raised
2754 frame .bot -border 1 -relief raised
2755 pack .top .lines .mid -side top -fill x
2756 pack .data -side top -fill both -expand yes
2759 menubutton .top.file -text "File" -menu .top.file.m
2761 .top.file.m add command -label "Save settings" -command {save-settings}
2762 .top.file.m add separator
2763 .top.file.m add command -label "Exit" -command {exit-action}
2765 menubutton .top.target -text "Target" -menu .top.target.m
2767 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
2768 .top.target.m add command -label "Disconnect" -command {close-target}
2769 .top.target.m add command -label "About" -command {about-target}
2770 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
2771 .top.target.m add command -label "Setup new" -command {define-target-dialog}
2772 .top.target.m add separator
2775 .top.target.m disable 1
2776 .top.target.m disable 2
2778 menu .top.target.m.clist
2779 menu .top.target.m.slist
2782 menubutton .top.service -text "Service" -menu .top.service.m
2784 .top.service.m add command -label "Database" -command {database-select}
2785 .top.service.m add cascade -label "Present" -menu .top.service.m.present
2786 menu .top.service.m.present
2787 .top.service.m.present add command -label "10 More" \
2788 -command [list present-more 10]
2789 .top.service.m.present add command -label "All" \
2790 -command [list present-more {}]
2791 .top.service.m add command -label "Search" -command {search-request 0}
2792 .top.service.m add command -label "Scan" -command {scan-request}
2794 .top.service configure -state disabled
2796 menubutton .top.rset -text "Set" -menu .top.rset.m
2798 .top.rset.m add command -label "Load" -command {load-set}
2799 .top.rset.m add separator
2801 menubutton .top.options -text "Options" -menu .top.options.m
2803 .top.options.m add cascade -label "Query" -menu .top.options.m.query
2804 .top.options.m add cascade -label "Format" -menu .top.options.m.formats
2805 .top.options.m add cascade -label "Wrap" -menu .top.options.m.wrap
2806 .top.options.m add cascade -label "Syntax" -menu .top.options.m.syntax
2808 menu .top.options.m.query
2809 .top.options.m.query add cascade -label "Select" \
2810 -menu .top.options.m.query.clist
2811 .top.options.m.query add cascade -label "Edit" \
2812 -menu .top.options.m.query.slist
2813 .top.options.m.query add command -label "New" \
2814 -command {query-new}
2815 .top.options.m.query add cascade -label "Delete" \
2816 -menu .top.options.m.query.dlist
2818 menu .top.options.m.query.slist
2819 menu .top.options.m.query.clist
2820 menu .top.options.m.query.dlist
2823 menu .top.options.m.formats
2825 foreach f $displayFormats {
2826 .top.options.m.formats add radiobutton -label $f -value $i \
2827 -command [list set-display-format $i] -variable displayFormat
2831 menu .top.options.m.wrap
2832 .top.options.m.wrap add radiobutton -label "Character" \
2833 -value char -variable textWrap -command {set-wrap char}
2834 .top.options.m.wrap add radiobutton -label "Word" \
2835 -value word -variable textWrap -command {set-wrap word}
2836 .top.options.m.wrap add radiobutton -label "None" \
2837 -value none -variable textWrap -command {set-wrap none}
2839 menu .top.options.m.syntax
2840 .top.options.m.syntax add radiobutton -label "None" \
2841 -value None -variable recordSyntax
2842 .top.options.m.syntax add separator
2843 .top.options.m.syntax add radiobutton -label "USMARC" \
2844 -value USMARC -variable recordSyntax
2845 .top.options.m.syntax add radiobutton -label "UNIMARC" \
2846 -value UNIMARC -variable recordSyntax
2847 .top.options.m.syntax add radiobutton -label "UKMARC" \
2848 -value UKMARC -variable recordSyntax
2849 .top.options.m.syntax add radiobutton -label "DANMARC" \
2850 -value DANMARC -variable recordSyntax
2851 .top.options.m.syntax add radiobutton -label "FINMARC" \
2852 -value FINMARC -variable recordSyntax
2853 .top.options.m.syntax add radiobutton -label "NORMARC" \
2854 -value NORMARC -variable recordSyntax
2855 .top.options.m.syntax add radiobutton -label "PICAMARC" \
2856 -value PICAMARC -variable recordSyntax
2857 .top.options.m.syntax add separator
2858 .top.options.m.syntax add radiobutton -label "SUTRS" \
2859 -value SUTRS -variable recordSyntax
2861 menubutton .top.help -text "Help" -menu .top.help.m
2864 .top.help.m add command -label "Help on help" \
2865 -command {tkerror "Help on help not available. Sorry"}
2866 .top.help.m add command -label "About" -command {about-origin}
2868 pack .top.file .top.target .top.service .top.rset .top.options -side left
2869 pack .top.help -side right
2871 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
2873 button .mid.search -width 7 -text {Search} -command {search-request 0} \
2875 button .mid.scan -width 7 -text {Scan} \
2876 -command scan-request -state disabled
2877 button .mid.present -width 7 -text {Present} -command [list present-more 10] \
2880 button .mid.clear -width 7 -text {Clear} -command index-clear
2881 pack .mid.search .mid.scan .mid.present .mid.clear -side left \
2882 -fill y -padx 5 -pady 3
2884 text .data.record -height 2 -width 20 -wrap none \
2885 -yscrollcommand [list .data.scroll set] -wrap $textWrap
2886 scrollbar .data.scroll -command [list .data.record yview]
2887 pack .data.scroll -side right -fill y
2888 pack .data.record -expand yes -fill both
2891 if {[tk colormodel .] == "color"} {
2892 .data.record tag configure marc-tag -foreground blue
2893 .data.record tag configure marc-id -foreground red
2895 .data.record tag configure marc-tag -foreground black
2896 .data.record tag configure marc-id -foreground black
2898 .data.record tag configure marc-data -foreground black
2900 button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
2902 pack .bot.a -side left -fill x
2903 pack .bot.logo -side right -padx 2 -pady 2
2905 message .bot.a.target -text "" -aspect 1000 -border 1
2907 label .bot.a.status -text "Not connected" -width 15 -relief \
2908 sunken -anchor w -border 1
2909 label .bot.a.set -text "" -width 5 -relief \
2910 sunken -anchor w -border 1
2911 label .bot.a.message -text "" -width 15 -relief \
2912 sunken -anchor w -border 1
2914 pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
2915 pack .bot.a.status .bot.a.set .bot.a.message \
2916 -side left -padx 2 -pady 2