1 # IR toolkit for tcl/tk
3 # See the file LICENSE for details.
4 # Sebastian Hammer, Adam Dickmeiss
7 # Revision 1.50 1995-06-21 11:04:48 adam
8 # Uses GNU autoconf 2.3.
9 # Install procedure implemented.
10 # boook bitmaps moved to sub directory bitmaps.
12 # Revision 1.49 1995/06/20 14:16:42 adam
13 # More work on cancel mechanism.
15 # Revision 1.48 1995/06/20 08:07:23 adam
16 # New setting: failInfo.
17 # Working on better cancel mechanism.
19 # Revision 1.47 1995/06/19 14:05:29 adam
20 # Bug fix: asked for SUTRS.
22 # Revision 1.46 1995/06/19 13:06:06 adam
23 # New define: IR_TCL_VERSION.
25 # Revision 1.45 1995/06/19 08:08:44 adam
26 # client.tcl: hotTargets now contain both database and target name.
27 # ir-tcl.c: setting protocol edited. Errors in callbacks are logged
28 # by logf(LOG_WARN, ...) calls.
30 # Revision 1.44 1995/06/16 14:55:18 adam
33 # Revision 1.43 1995/06/16 14:41:05 adam
34 # Scan line entries can be copied to a search entry.
36 # Revision 1.42 1995/06/16 12:28:13 adam
37 # Implemented preferredRecordSyntax.
38 # Minor changes in diagnostic handling.
39 # Record list deleted when connection closes.
41 # Revision 1.41 1995/06/14 15:07:59 adam
42 # Bug fix in cascade-target-list. Uses yaz-version.h.
44 # Revision 1.40 1995/06/14 13:37:17 adam
45 # Setting recordType implemented.
46 # Setting implementationVersion implemented.
47 # Settings implementationId / implementationName edited.
49 # Revision 1.39 1995/06/14 12:16:22 adam
50 # hotTargets, textWrap and displayFormat saved in clientg.tcl.
52 # Revision 1.38 1995/06/14 07:22:45 adam
53 # Target definitions can be deleted.
54 # Listbox used in the query definition dialog.
56 # Revision 1.37 1995/06/13 14:37:59 adam
57 # Work on query setup.
58 # Better about origin/target.
59 # Better presentation formats.
61 # Revision 1.36 1995/06/13 07:42:14 adam
62 # Bindings removed from text widgets.
64 # Revision 1.35 1995/06/12 15:17:31 adam
65 # Text widget used in main window (instead of listbox) to support
66 # better presentation formats.
68 # Revision 1.34 1995/06/12 07:59:07 adam
69 # More work on geometry handling.
71 # Revision 1.33 1995/06/09 11:17:35 adam
72 # Start work on geometry management.
74 # Revision 1.32 1995/06/07 09:16:37 adam
75 # New presentation format.
77 # Revision 1.31 1995/06/06 16:31:09 adam
78 # Bug fix: target names couldn't contain blanks.
81 # Revision 1.30 1995/06/06 11:35:41 adam
82 # Work on scan. Display of old sets.
84 # Revision 1.29 1995/06/05 14:11:18 adam
85 # Bug fix in present-more.
87 # Revision 1.28 1995/06/02 14:52:13 adam
88 # Minor changes really.
90 # Revision 1.27 1995/06/02 14:29:42 adam
91 # Work on scan interface - up/down buttons.
93 # Revision 1.26 1995/06/01 16:36:46 adam
94 # About buttons. Minor bug fixes.
96 # Revision 1.25 1995/05/31 13:09:57 adam
97 # Client searches/presents may be interrupted.
98 # New moving book-logo.
100 # Revision 1.24 1995/05/31 08:36:24 adam
101 # Bug fix in client.tcl: didn't save options on clientrc.tcl.
102 # New method: referenceId. More work on scan.
104 # Revision 1.23 1995/05/29 10:33:41 adam
105 # README and rename of startup script.
107 # Revision 1.22 1995/05/26 11:44:09 adam
108 # Bugs fixed. More work on MARC utilities and queries. Test
109 # client is up-to-date again.
111 # Revision 1.21 1995/05/11 15:34:46 adam
112 # Scan request changed a bit. This version works with RLG.
114 # Revision 1.20 1995/04/21 16:31:57 adam
115 # New radiobutton: protocol (z39v2/SR).
117 # Revision 1.19 1995/04/18 16:11:50 adam
118 # First version of graphical Scan. Some work on query-by-form.
120 # Revision 1.18 1995/04/10 10:50:22 adam
121 # Result-set name defaults to suffix of ir-set name.
122 # Started working on scan. Not finished at this point.
124 # Revision 1.17 1995/03/31 09:34:57 adam
125 # Search-button disabled when there is no connection.
127 # Revision 1.16 1995/03/31 08:56:36 adam
128 # New button "Search".
130 # Revision 1.15 1995/03/28 12:45:22 adam
131 # New ir method failback: called on disconnect/protocol error.
132 # New ir set/get method: protocol: SR / Z3950.
133 # Simple popup and disconnect when failback is invoked.
135 # Revision 1.14 1995/03/22 16:07:55 adam
138 # Revision 1.13 1995/03/21 17:27:26 adam
139 # Short-hand keys in setup.
141 # Revision 1.12 1995/03/21 13:41:03 adam
142 # Comstack cs_create not used too often. Non-blocking connect.
144 # Revision 1.11 1995/03/21 10:39:06 adam
145 # Diagnostic error message displayed with tkerror.
147 # Revision 1.10 1995/03/20 15:24:06 adam
148 # Diagnostic records saved on searchResponse.
150 # Revision 1.9 1995/03/17 18:26:16 adam
151 # Non-blocking i/o used now. Database names popup as cascade items.
153 # Revision 1.8 1995/03/17 15:45:00 adam
154 # Improved target/database setup.
156 # Revision 1.7 1995/03/16 17:54:03 adam
157 # Minor changes really.
159 # Revision 1.6 1995/03/15 19:10:20 adam
160 # Database setup in protocol-setup (rather target setup).
162 # Revision 1.5 1995/03/15 13:59:23 adam
165 # Revision 1.4 1995/03/14 17:32:29 adam
166 # Presentation of full Marc record in popup window.
168 # Revision 1.3 1995/03/12 19:31:52 adam
169 # Pattern matching implemented when retrieving MARC records. More
170 # diagnostic functions.
172 # Revision 1.2 1995/03/10 18:00:15 adam
173 # Actual presentation in line-by-line format. RPN query support.
175 # Revision 1.1 1995/03/09 16:15:07 adam
176 # First presentRequest attempts. Hot-target list.
181 if {[file readable clientrc.tcl]} {
188 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {} 1 {} {} Z39}
190 set settingsChanged 0
201 set queryTypes {Simple}
202 set queryButtons { { {I 0} {I 1} {I 2} } }
203 set queryInfo { { {Title {1=4 4=1}} {Author {1=1}} \
204 {Subject {1=21}} {Any {1=1016}} } }
210 proc read-formats {} {
211 global displayFormats
213 set formats [glob -nocomplain ${libdir}/formats/*.tcl]
215 if {[file readable $f]} {
217 set l [expr [string length $f] - 5]
218 lappend displayFormats [string range $f 8 $l]
227 .data.record configure -wrap $m
234 proc set-display-format {f} {
244 .bot.a.status configure -text "Reformatting"
247 add-title-lines 0 10000 1
249 .bot.a.status configure -text "Ready"
253 proc initBindings {} {
256 bind $w <Double-1> {}
257 bind $w <Triple-1> {}
258 bind $w <B1-Motion> {}
260 bind $w <Shift-B1-Motion> {}
262 bind $w <B2-Motion> {}
263 bind $w <Any-KeyPress> {}
265 bind $w <BackSpace> {}
267 bind $w <Control-h> {}
268 bind $w <Control-d> {}
269 bind $w <Control-v> {}
272 bind $w <B1-Motion> {}
273 bind $w <Shift-B1-Motion> {}
278 proc post-menu {wbutton wmenu} {
281 $wmenu post [winfo rootx $wbutton] \
282 [expr [winfo rooty $wbutton]+[winfo height $wbutton]]
287 global windowGeometry
288 set windowGeometry($w) [wm geometry $w]
291 global windowGeometry
294 if {[info exists windowGeometry($w)]} {
295 set g $windowGeometry($w)
300 bind $w <Destroy> [list destroyGW $w]
303 if {[file readable "${libdir}/clientrc.tcl"]} {
304 source "${libdir}/clientrc.tcl"
307 if {[file readable "~/.clientrc.tcl"]} {
308 source "~/.clientrc.tcl"
311 set queryButtonsFind [lindex $queryButtons 0]
312 set queryInfoFind [lindex $queryInfo 0]
314 proc top-down-window {w} {
315 frame $w.top -relief raised -border 1
316 frame $w.bot -relief raised -border 1
318 pack $w.top -side top -fill both -expand yes
319 pack $w.bot -fill both
322 proc top-down-ok-cancel {w ok-action g} {
323 frame $w.bot.left -relief sunken -border 1
324 pack $w.bot.left -side left -expand yes -ipadx 2 -ipady 2 -padx 5 -pady 5
325 button $w.bot.left.ok -width 6 -text {Ok} \
326 -command ${ok-action}
327 pack $w.bot.left.ok -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3
328 button $w.bot.cancel -width 6 -text {Cancel} \
329 -command [list destroy $w]
330 pack $w.bot.cancel -side left -expand yes
338 proc bottom-buttons {w buttonList g} {
340 set l [llength $buttonList]
342 frame $w.bot.$i -relief sunken -border 1
343 pack $w.bot.$i -side left -expand yes -padx 5 -pady 5
344 button $w.bot.$i.ok -text [lindex $buttonList $i] \
345 -command [lindex $buttonList [expr $i+1]]
346 pack $w.bot.$i.ok -expand yes -ipadx 3 -ipady 2 -padx 3 -pady 3 -side left
350 button $w.bot.$i -text [lindex $buttonList $i] \
351 -command [lindex $buttonList [expr $i+1]]
352 pack $w.bot.$i -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3 -side left
362 proc cancel-operation {} {
370 show-status Cancel 0 1
374 proc show-target {target base} {
378 .bot.a.target configure -text ""
382 .bot.a.target configure -text "$target"
384 .bot.a.target configure -text "$target - $base"
388 proc show-logo {v1} {
397 .bot.logo configure -bitmap @${libdir}/bitmaps/book${v1}
398 after 140 [list show-logo $v1]
402 .bot.logo configure -bitmap @${libdir}/bitmaps/book1
411 proc show-status {status b sb} {
418 .bot.a.status configure -text "$status"
420 if {$busy == 0} {set busy 1}
428 .top.service configure -state normal
429 .mid.search configure -state normal
431 .mid.scan configure -state normal
434 .top.service.m disable 1
435 } elseif {$setOffset > 0 && $setOffset <= [z39.$setNo resultCount]} {
436 .top.service.m enable 1
437 .mid.present configure -state normal
439 .top.service.m disable 1
441 if {[winfo exists .scan-window]} {
442 .scan-window.bot.2 configure -state normal
443 .scan-window.bot.4 configure -state normal
446 .top.service configure -state disabled
447 .mid.search configure -state disabled
448 .mid.scan configure -state disabled
449 .mid.present configure -state disabled
451 if {[winfo exists .scan-window]} {
452 .scan-window.bot.2 configure -state disabled
453 .scan-window.bot.4 configure -state disabled
458 proc show-message {msg} {
459 .bot.a.message configure -text "$msg"
462 proc insertWithTags {w text args} {
463 set start [$w index insert]
464 $w insert insert $text
465 foreach tag [$w tag names $start] {
466 $w tag remove $tag $start insert
469 $w tag add $i $start insert
473 proc popup-license {} {
478 wm title $w "License"
484 text $w.top.t -width 80 -height 10 -wrap word \
485 -yscrollcommand [list $w.top.s set]
486 scrollbar $w.top.s -command [list $w.top.t yview]
488 pack $w.top.s -side right -fill y
489 pack $w.top.t -expand yes -fill both
491 if {[file readable "${libdir}/LICENSE"]} {
492 set f [open "${libdir}/LICENSE" r]
493 while {[gets $f buf] != -1} {
494 $w.top.t insert end $buf
495 $w.top.t insert end "\n"
499 bottom-buttons $w [list {Close} [list destroy $w]] 1
502 proc about-target {} {
503 set w .about-target-w
508 wm title $w "About target"
511 frame $w.top.a -relief ridge -border 2
512 frame $w.top.p -relief ridge -border 2
514 pack $w.top.a $w.top.p -side top -fill x
516 label $w.top.a.about -text "About"
517 label $w.top.a.irtcl -text $hostid \
518 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
519 pack $w.top.a.about $w.top.a.irtcl -side top
521 set i [z39 targetImplementationName]
522 label $w.top.p.in -text "Implementation name: $i"
523 set i [z39 targetImplementationId]
524 label $w.top.p.ii -text "Implementation id: $i"
525 set i [z39 targetImplementationVersion]
526 label $w.top.p.iv -text "Implementation version: $i"
528 label $w.top.p.op -text "Protocol options: $i"
530 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.op -side top -anchor nw
532 bottom-buttons $w [list {Close} [list destroy $w]] 1
535 proc about-origin-logo {n} {
537 set w .about-origin-w
538 if {![winfo exists $w]} {
545 $w.top.a.logo configure -bitmap @${libdir}/bitmaps/book$n
546 after 140 [list about-origin-logo $n]
549 proc about-origin {} {
550 set w .about-origin-w
552 if {[winfo exists $w]} {
557 wm title $w "About IrTcl"
561 frame $w.top.a -relief ridge -border 2
562 frame $w.top.p -relief ridge -border 2
564 pack $w.top.a $w.top.p -side top -fill x
566 label $w.top.a.irtcl -text "IrTcl" \
567 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
568 label $w.top.a.logo -bitmap @${libdir}/bitmaps/book1
569 pack $w.top.a.irtcl $w.top.a.logo -side left -expand yes
571 set i [z39 implementationName]
572 label $w.top.p.in -text "Implementation name: $i"
573 set i [z39 implementationId]
574 label $w.top.p.ii -text "Implementation id: $i"
575 set i [z39 implementationVersion]
576 label $w.top.p.iv -text "Implementation version: $i"
578 pack $w.top.p.in $w.top.p.ii $w.top.p.iv -side top -anchor nw
581 bottom-buttons $w [list {Close} [list destroy $w] \
582 {License} [list popup-license]] 0
585 proc popup-marc {sno no b df} {
587 global displayFormats
590 if {[z39.$sno type $no] != "DB"} {
594 set w .full-marc-$fullMarcSeq
601 if {[winfo exists $w]} {
609 frame $w.top -relief raised -border 1
610 frame $w.bot -relief raised -border 1
612 pack $w.top -side top -fill both -expand yes
613 pack $w.bot -fill both
615 text $w.top.record -width 60 -height 5 -wrap word \
616 -yscrollcommand [list $w.top.s set]
617 scrollbar $w.top.s -command [list $w.top.record yview]
619 if {[tk colormodel .] == "color"} {
620 $w.top.record tag configure marc-tag -foreground blue
621 $w.top.record tag configure marc-id -foreground red
623 $w.top.record tag configure marc-tag -foreground black
624 $w.top.record tag configure marc-id -foreground black
626 $w.top.record tag configure marc-data -foreground black
629 $w.top.record delete 0.0 end
630 set recordType [z39.$sno recordType $no]
631 wm title $w "$recordType record #$no"
633 set ffunc [lindex $displayFormats $df]
634 set ffunc "display-$ffunc"
636 $ffunc $sno $no $w.top.record 0
639 bind $w.top.record <Return> {destroy .full-marc}
641 pack $w.top.s -side right -fill y
642 pack $w.top.record -expand yes -fill both
645 bottom-buttons $w [list \
646 {Close} [list destroy $w]] 0
648 bottom-buttons $w [list \
649 {Close} [list destroy $w] \
650 {Duplicate} [list popup-marc $sno $no 1 0]] 0
651 menubutton $w.bot.formats -text "Format" -menu $w.bot.formats.m
652 menu $w.bot.formats.m
654 foreach f $displayFormats {
655 $w.bot.formats.m add radiobutton -label $f \
656 -variable popupMarcdf -value $i \
657 -command [list display-$f $sno $no $w.top.record 0]
660 pack $w.bot.formats -expand yes -ipadx 2 -ipady 2 \
661 -padx 3 -pady 3 -side left
665 foreach f $displayFormats {
666 $w.bot.formats.m entryconfigure $i \
667 -command [list display-$f $sno $no $w.top.record 0]
673 proc update-target-hotlist {target base} {
676 set len [llength $hotTargets]
678 .top.target.m delete 6 [expr 6+[llength $hotTargets]]
681 foreach e $hotTargets {
682 if {$target == [lindex $e 0] && $base == [lindex $e 1]} {
683 set hotTargets [lreplace $hotTargets $i $i]
688 set hotTargets [linsert $hotTargets 0 [list $target $base]]
692 proc set-target-hotlist {} {
696 foreach e $hotTargets {
697 set target [lindex $e 0]
698 set base [lindex $e 1]
700 .top.target.m add command -label "$i $target" -command \
701 [list reopen-target $target {}]
703 .top.target.m add command -label "$i $target - $base" -command \
704 [list reopen-target $target $base]
713 proc reopen-target {target base} {
715 open-target $target $base
716 update-target-hotlist $target $base
719 proc define-target-action {} {
722 set target [.target-define.top.target.entry get]
726 foreach n [array names profile] {
732 set seq [lindex $profile(Default) 12]
734 set profile($target) $profile(Default)
735 set profile(Default) [lreplace $profile(Default) 12 12 [incr seq]]
737 protocol-setup $target
738 destroy .target-define
741 proc fail-response {target} {
742 set c [lindex [z39 failInfo] 0]
743 set m [lindex [z39 failInfo] 1]
748 proc connect-response {target base} {
749 dputs "connect-response"
750 show-target $target $base
754 proc open-target {target base} {
759 z39 comstack [lindex $profile($target) 6]
760 z39 protocol [lindex $profile($target) 11]
761 z39 idAuthentication [lindex $profile($target) 3]
762 z39 maximumRecordSize [lindex $profile($target) 4]
763 z39 preferredMessageSize [lindex $profile($target) 5]
764 dputs "maximumRecordSize="
765 dputs [z39 maximumRecordSize]
766 dputs "preferredMessageSize="
767 dputs [z39 preferredMessageSize]
768 show-status {Connecting} 1 0
770 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
772 z39 databaseNames $base
774 z39 failback [list fail-response $target]
775 z39 callback [list connect-response $target $base]
778 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
781 tkerror $errorMessage
782 show-status Ready 0 {}
785 # z39 options search present scan namedResultSets triggerResourceCtrl
787 .top.target.m disable 0
788 .top.target.m enable 1
789 .top.target.m enable 2
792 proc close-target {} {
799 .bot.a.set configure -text ""
803 show-status {Not connected} 0 0
806 .top.target.m disable 1
807 .top.target.m disable 2
808 .top.target.m enable 0
811 proc load-set-action {} {
815 ir-set z39.$setNo z39
817 set fname [.load-set.top.filename.entry get]
820 show-status {Loading} 1 {}
822 z39.$setNo loadFile $fname
824 set no [z39.$setNo numberOfRecordsReturned]
825 add-title-lines $setNo $no 1
827 set l [format "%-4d %7d" $setNo $no]
828 .top.rset.m add command -label $l \
829 -command [list add-title-lines $setNo 10000 1]
830 show-status {Ready} 0 {}
842 frame $w.top.filename
843 pack $w.top.filename -side top -anchor e -pady 2
845 entry-fields $w.top {filename} \
847 {load-set-action} {destroy .load-set}
849 top-down-ok-cancel $w {load-set-action} 1
853 proc init-request {} {
861 z39 callback {init-response}
862 show-status {Initializing} 1 {}
863 set err [catch {z39 init} errorMessage]
865 tkerror $errorMessage
866 show-status Ready 0 {}
870 proc init-response {} {
878 if {![z39 initResult]} {
879 show-status {Ready} 0 1
880 set u [z39 userInformationField]
882 tkerror "Connection rejected by target: $u"
884 if {[lsearch [z39 options] scan] >= 0} {
889 show-status {Ready} 0 1
893 proc search-request {bflag} {
903 dputs "search-request"
905 if {!$bflag && $busy} {
906 dputs "busy: search-request ignored"
911 show-status {Searching} 1 0
912 set delayRequest {search-request 1}
917 set query [index-query]
922 ir-set z39.$setNo z39
924 if {[lindex $profile($target) 10] == 1} {
925 z39.$setNo setName $setNo
926 dputs "setName=${setNo}"
928 z39.$setNo setName Default
929 dputs "setName=Default"
931 if {[lindex $profile($target) 8] == 1} {
932 z39.$setNo queryType rpn
934 if {[lindex $profile($target) 9] == 1} {
935 z39.$setNo queryType ccl
937 z39 callback {search-response}
938 z39.$setNo search $query
939 show-status {Searching} 1 0
942 proc scan-copy {y entry} {
944 set no [$w.top.list nearest $y]
946 .lines.$entry.e delete 0 end
947 .lines.$entry.e insert 0 [string range [$w.top.list get $no] 8 end]
950 proc scan-request {} {
958 global queryButtonsFind
966 show-status {Scanning} 1 0
967 set delayRequest scan-request
976 set b [lindex $queryButtonsFind $curIndexEntry]
978 foreach a [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end] {
979 set attr "@attr $a $attr"
981 set title [lindex [lindex $queryInfoFind [lindex $b 1]] 0]
984 if {![winfo exists $w]} {
991 entry $w.top.entry -relief sunken
992 pack $w.top.entry -fill x -padx 4 -pady 2
993 bind $w.top.entry <KeyRelease> [list scan-term-h $attr]
995 listbox $w.top.list -yscrollcommand [list $w.top.scroll set] \
997 scrollbar $w.top.scroll -orient vertical -border 1
998 pack $w.top.list -side left -fill both -expand yes
999 pack $w.top.scroll -side right -fill y
1000 $w.top.scroll config -command [list $w.top.list yview]
1002 listbox $w.top.list -font fixed -geometry 60x14
1003 pack $w.top.list -side left -fill both -expand yes
1006 bottom-buttons $w [list {Close} [list destroy $w] \
1007 {Up} [list scan-up $attr] \
1008 {Down} [list scan-down $attr]] 0
1009 bind $w.top.list <Up> [list scan-up $attr]
1010 bind $w.top.list <Down> [list scan-down $attr]
1012 bind $w.top.list <Double-Button-1> [list scan-copy %y $curIndexEntry]
1013 wm title $w "Scan $title"
1015 z39 callback [list scan-response $attr 0 35]
1016 z39.scan numberOfTermsRequested 5
1017 z39.scan preferredPositionInResponse 1
1018 z39.scan scan "${attr} 0"
1020 show-status {Scanning} 1 0
1023 proc scan-term-h {attr} {
1031 set nScanTerm [$w.top.entry get]
1032 if {$nScanTerm == $scanTerm} {
1035 set scanTerm $nScanTerm
1036 z39 callback [list scan-response $attr 0 35]
1037 z39.scan numberOfTermsRequested 5
1038 z39.scan preferredPositionInResponse 1
1039 dputs "${attr} \{${scanTerm}\}"
1040 if {$scanTerm == ""} {
1041 z39.scan scan "${attr} 0"
1043 z39.scan scan "${attr} \{${scanTerm}\}"
1045 show-status {Scanning} 1 0
1048 proc scan-response {attr start toget} {
1055 dputs "In scan-response"
1056 set m [z39.scan numberOfEntriesReturned]
1062 if {![winfo exists .scan-window]} {
1065 dputs "Handling cancel"
1066 if {$delayRequest != ""} {
1071 show-status {Ready} 0 1
1074 set nScanTerm [$w.top.entry get]
1075 if {$nScanTerm != $scanTerm} {
1076 z39 callback [list scan-response $attr 0 35]
1077 z39.scan numberOfTermsRequested 5
1078 z39.scan preferredPositionInResponse 1
1079 set scanTerm $nScanTerm
1080 dputs "${attr} \{${scanTerm}\}"
1081 if {$scanTerm == ""} {
1082 z39.scan scan "${attr} 0"
1084 z39.scan scan "${attr} \{${scanTerm}\}"
1086 show-status {Scanning} 1 0
1089 set status [z39.scan scanStatus]
1092 show-status {Ready} 0 1
1097 for {set i 0} {$i < $m} {incr i} {
1098 set term [lindex [z39.scan scanLine $i] 1]
1099 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1100 $w.top.list insert $i "$nostr $term"
1103 $w.top.list yview $scanView
1105 $w.top.list delete $start end
1106 for {set i 0} {$i < $m} {incr i} {
1107 set term [lindex [z39.scan scanLine $i] 1]
1108 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1109 $w.top.list insert end "$nostr $term"
1113 dputs "Handling cancel"
1115 if {$delayRequest != ""} {
1121 if {$toget > 0 && $m > 1 && $m < $toget} {
1122 set ntoget [expr $toget - $m + 1]
1123 dputs ntoget=$ntoget
1124 z39 callback [list scan-response $attr [expr $start + $m - 1] $ntoget]
1126 dputs "down continue: $q"
1128 z39.scan numberOfTermsRequested 10
1130 z39.scan numberOfTermsRequested $ntoget
1132 z39.scan preferredPositionInResponse 1
1133 dputs "${attr} \{$q\}"
1134 z39.scan scan "${attr} \{$q\}"
1137 if {$toget < 0 && $m > 1 && $m < [expr - $toget]} {
1138 set ntoget [expr - $toget - $m]
1139 dputs ntoget=$ntoget
1140 z39 callback [list scan-response $attr 0 -$ntoget]
1141 set q [string range [$w.top.list get 0] 8 end]
1142 dputs "up continue: $q"
1144 z39.scan numberOfTermsRequested 10
1145 z39.scan preferredPositionInResponse 11
1147 z39.scan numberOfTermsRequested $ntoget
1148 z39.scan preferredPositionInResponse [incr ntoget]
1150 dputs "${attr} \{$q\}"
1151 z39.scan scan "${attr} \{$q\}"
1154 show-status {Ready} 0 1
1157 proc scan-down {attr} {
1165 show-status {Scanning down} 1 0
1166 set delayRequest [list scan-down $attr]
1172 set scanView [expr $scanView + 5]
1173 set s [$w.top.list size]
1174 if {$scanView > $s} {
1175 z39 callback [list scan-response $attr [expr $s - 1] 25]
1176 set q [string range [$w.top.list get [expr $s - 1]] 8 end]
1178 z39.scan numberOfTermsRequested 10
1179 z39.scan preferredPositionInResponse 1
1180 show-status {Scanning} 1 0
1181 dputs "${attr} \{$q\}"
1182 z39.scan scan "${attr} \{$q\}"
1185 $w.top.list yview $scanView
1188 proc scan-up {attr} {
1196 show-status {Scanning up} 1 0
1197 set delayRequest [list scan-up $attr]
1203 set scanView [expr $scanView - 5]
1204 if {$scanView < 0} {
1205 z39 callback [list scan-response $attr 0 -25]
1206 set q [string range [$w.top.list get 0] 8 end]
1208 z39.scan numberOfTermsRequested 10
1209 z39.scan preferredPositionInResponse 11
1210 show-status {Scanning} 1 0
1211 z39.scan scan "${attr} \{$q\}"
1214 $w.top.list yview $scanView
1217 proc search-response {} {
1225 dputs "In search-response"
1227 dputs "Handling cancel"
1229 if {$delayRequest != ""} {
1236 set setMax [z39.$setNo resultCount]
1237 show-message "${setMax} hits"
1238 set l [format "%-4d %7d" $setNo $setMax]
1239 .top.rset.m add command -label $l \
1240 -command [list add-title-lines $setNo 10000 1]
1242 show-status {Ready} 0 1
1243 set status [z39.$setNo responseStatus]
1244 if {[lindex $status 0] == "NSD"} {
1245 set code [lindex $status 1]
1246 set msg [lindex $status 2]
1247 set addinfo [lindex $status 3]
1248 tkerror "NSD$code: $msg: $addinfo"
1256 show-status {Ready} 0 1
1257 z39 callback {present-response}
1258 z39.$setNo present $setOffset 1
1259 show-status {Retrieving} 1 0
1262 proc present-more {number} {
1270 dputs "present-more"
1272 show-status {Retrieving} 1 0
1273 set delayRequest "present-more $number"
1279 dputs "setNo=$setNo"
1282 set max [z39.$setNo resultCount]
1283 if {$max <= $setOffset} {
1285 dputs "setOffset=$setOffset"
1288 if {$number == ""} {
1292 if {$setMax > $max} {
1296 z39 callback {present-response}
1298 set toGet [expr $setMax - $setOffset + 1]
1305 z39.$setNo present $setOffset $toGet
1306 show-status {Retrieving} 1 0
1309 proc init-title-lines {} {
1310 .data.record delete 0.0 end
1313 proc title-press {y setno} {
1314 show-full-marc $setno [expr 1 + [.data.list nearest $y]] 0
1317 proc add-title-lines {setno no offset} {
1318 global displayFormats
1319 global displayFormat
1323 set setno $lastSetNo
1325 set lastSetNo $setno
1328 .bot.a.set configure -text $setno
1329 .data.record delete 0.0 end
1331 set ffunc [lindex $displayFormats $displayFormat]
1332 set ffunc "display-$ffunc"
1333 for {set i 0} {$i < $no} {incr i} {
1334 set o [expr $i + $offset]
1335 set type [z39.$setno type $o]
1339 .data.record tag bind r$o <Any-Enter> {}
1340 .data.record tag bind r$o <Any-Leave> {}
1341 set insert0 [.data.record index insert]
1342 $ffunc $setno $o .data.record 1
1343 .data.record tag add r$o $insert0 insert
1344 .data.record tag bind r$o <1> \
1345 [list popup-marc $setno $o 0 0]
1350 proc present-response {} {
1357 dputs "In present-response"
1358 set no [z39.$setNo numberOfRecordsReturned]
1359 dputs "Returned $no records, setOffset $setOffset"
1360 add-title-lines $setNo $no $setOffset
1361 set setOffset [expr $setOffset + $no]
1363 dputs "Handling cancel"
1365 if {$delayRequest != ""} {
1370 set status [z39.$setNo responseStatus]
1371 if {[lindex $status 0] == "NSD"} {
1372 show-status {Ready} 0 1
1373 set code [lindex $status 1]
1374 set msg [lindex $status 2]
1375 set addinfo [lindex $status 3]
1376 tkerror "NSD$code: $msg: $addinfo"
1379 if {$no > 0 && $setOffset <= $setMax} {
1380 dputs "present-request from ${setOffset}"
1381 set toGet [expr $setMax - $setOffset + 1]
1385 z39.$setNo present $setOffset $toGet
1387 show-status {Ready} 0 1
1391 proc left-cursor {w} {
1392 set i [$w index insert]
1399 proc right-cursor {w} {
1400 set i [$w index insert]
1405 proc bind-fields {list returnAction escapeAction} {
1406 set max [expr [llength $list]-1]
1407 for {set i 0} {$i < $max} {incr i} {
1408 bind [lindex $list $i] <Return> $returnAction
1409 bind [lindex $list $i] <Escape> $escapeAction
1410 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
1411 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1412 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1414 bind [lindex $list $i] <Return> $returnAction
1415 bind [lindex $list $i] <Escape> $escapeAction
1416 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
1417 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1418 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1419 focus [lindex $list 0]
1422 proc entry-fields {parent list tlist returnAction escapeAction} {
1425 foreach field $list {
1426 set label ${parent}.${field}.label
1427 set entry ${parent}.${field}.entry
1428 label $label -text [lindex $tlist $i] -anchor e
1429 entry $entry -width 32 -relief sunken
1430 pack $label -side left
1431 pack $entry -side right
1432 lappend alist $entry
1435 bind-fields $alist $returnAction $escapeAction
1438 proc define-target-dialog {} {
1439 set w .target-define
1445 pack $w.top.target \
1446 -side top -anchor e -pady 2
1447 entry-fields $w.top {target} \
1449 {define-target-action} {destroy .target-define}
1450 top-down-ok-cancel $w {define-target-action} 1
1453 proc protocol-setup-delete {target} {
1455 global settingsChanged
1457 set a [alert "Are you sure you want to delete the target \
1458 definition $target ?"]
1460 set wno [lindex $profile($target) 12]
1463 unset profile($target)
1464 set settingsChanged 1
1469 proc protocol-setup-action {target} {
1472 global protocolRadioType
1473 global settingsChanged
1476 global ResultSetCheck
1478 set wno [lindex $profile($target) 12]
1482 set settingsChanged 1
1483 set len [$w.top.databases.list size]
1484 for {set i 0} {$i < $len} {incr i} {
1485 lappend b [$w.top.databases.list get $i]
1487 set profile($target) [list [$w.top.description.entry get] \
1488 [$w.top.host.entry get] \
1489 [$w.top.port.entry get] \
1490 [$w.top.idAuthentication.entry get] \
1491 [$w.top.maximumRecordSize.entry get] \
1492 [$w.top.preferredMessageSize.entry get] \
1498 $protocolRadioType \
1502 dputs $profile($target)
1506 proc place-force {window parent} {
1507 set g [wm geometry $parent]
1509 set p1 [string first + $g]
1510 set p2 [string last + $g]
1512 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
1513 set y [expr 60+[string range $g [expr $p2 +1] end]]
1514 wm geometry $window +${x}+${y}
1517 proc add-database-action {target} {
1520 set wno [lindex $profile($target) 12]
1523 $w.top.databases.list insert end \
1524 [.database-select.top.database.entry get]
1525 destroy .database-select
1528 proc add-database {target} {
1531 set w .database-select
1533 set oldFocus [focus]
1536 set wno [lindex $profile($target) 12]
1537 place-force $w .setup-${wno}
1541 frame $w.top.database
1543 pack $w.top.database -side top -anchor e -pady 2
1545 entry-fields $w.top {database} \
1546 {{Database to add:}} \
1547 [list add-database-action $target] {destroy .database-select}
1549 top-down-ok-cancel $w [list add-database-action $target] 1
1553 proc delete-database {target} {
1556 set wno [lindex $profile($target) 12]
1559 foreach i [$w.top.databases.list curselection] {
1560 set b [$w.top.databases.list get $i]
1563 set a [alert "Are you sure you want to remove the database(s)${l}?"]
1565 foreach i [lsort -decreasing \
1566 [$w.top.databases.list curselection]] {
1567 $w.top.databases.list delete $i
1572 proc protocol-setup {target} {
1575 global protocolRadioType
1578 global ResultSetCheck
1580 set wno [lindex $profile($target) 12]
1585 wm title $w "Setup $target"
1589 if {$target == ""} {
1593 dputs $profile($target)
1597 frame $w.top.description
1598 frame $w.top.idAuthentication
1599 frame $w.top.maximumRecordSize
1600 frame $w.top.preferredMessageSize
1601 frame $w.top.cs-type -relief ridge -border 2
1602 frame $w.top.protocol -relief ridge -border 2
1603 frame $w.top.query -relief ridge -border 2
1604 frame $w.top.databases -relief ridge -border 2
1606 # Maximum/preferred/idAuth ...
1607 pack $w.top.description $w.top.host $w.top.port \
1608 $w.top.idAuthentication $w.top.maximumRecordSize \
1609 $w.top.preferredMessageSize -side top -anchor e -pady 2
1611 entry-fields $w.top {description host port idAuthentication \
1612 maximumRecordSize preferredMessageSize} \
1613 {{Description:} {Host:} {Port:} {Id Authentication:} \
1614 {Maximum Record Size:} {Preferred Message Size:}} \
1615 [list protocol-setup-action $target] [list destroy $w]
1617 foreach sub {description host port idAuthentication \
1618 maximumRecordSize preferredMessageSize} {
1620 bind $w.top.$sub.entry <Control-a> [list add-database $target]
1621 bind $w.top.$sub.entry <Control-d> [list delete-database $target]
1623 $w.top.description.entry insert 0 [lindex $profile($target) 0]
1624 $w.top.host.entry insert 0 [lindex $profile($target) 1]
1625 $w.top.port.entry insert 0 [lindex $profile($target) 2]
1626 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
1627 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
1628 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
1629 set csRadioType [lindex $profile($target) 6]
1630 set RPNCheck [lindex $profile($target) 8]
1631 set CCLCheck [lindex $profile($target) 9]
1632 set ResultSetCheck [lindex $profile($target) 10]
1633 set protocolRadioType [lindex $profile($target) 11]
1634 if {$protocolRadioType == ""} {
1635 set protocolRadioType Z39
1639 pack $w.top.databases -side left -pady 4 -padx 4 -expand yes -fill both
1641 label $w.top.databases.label -text "Databases"
1642 button $w.top.databases.add -text "Add" \
1643 -command [list add-database $target]
1644 button $w.top.databases.delete -text "Delete" \
1645 -command [list delete-database $target]
1646 listbox $w.top.databases.list -geometry 20x6 \
1647 -yscrollcommand "$w.top.databases.scroll set"
1648 scrollbar $w.top.databases.scroll -orient vertical -border 1
1649 pack $w.top.databases.label -side top -fill x \
1651 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
1653 pack $w.top.databases.list -side left -fill both -expand yes \
1655 pack $w.top.databases.scroll -side right -fill y \
1657 $w.top.databases.scroll config -command "$w.top.databases.list yview"
1659 foreach b [lindex $profile($target) 7] {
1660 $w.top.databases.list insert end $b
1664 pack $w.top.cs-type -pady 4 -padx 4 -side top -fill x
1666 label $w.top.cs-type.label -text "Transport"
1667 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" -anchor w \
1668 -variable csRadioType -value tcpip
1669 radiobutton $w.top.cs-type.mosi -text "MOSI" -anchor w\
1670 -variable csRadioType -value mosi
1672 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
1673 -padx 4 -side top -fill x
1676 pack $w.top.protocol -pady 4 -padx 4 -side top -fill x
1678 label $w.top.protocol.label -text "Protocol"
1679 radiobutton $w.top.protocol.z39v2 -text "Z39.50" -anchor w \
1680 -variable protocolRadioType -value Z39
1681 radiobutton $w.top.protocol.sr -text "SR" -anchor w \
1682 -variable protocolRadioType -value SR
1684 pack $w.top.protocol.label $w.top.protocol.z39v2 $w.top.protocol.sr \
1685 -padx 4 -side top -fill x
1688 pack $w.top.query -pady 4 -padx 4 -side top -fill x
1690 label $w.top.query.label -text "Query support"
1691 checkbutton $w.top.query.c1 -text "RPN query" -anchor w -variable RPNCheck
1692 checkbutton $w.top.query.c2 -text "CCL query" -anchor w -variable CCLCheck
1693 checkbutton $w.top.query.c3 -text "Result sets" -anchor w -variable ResultSetCheck
1695 pack $w.top.query.label -side top
1696 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
1697 -padx 4 -side top -fill x
1700 bottom-buttons $w [list {Ok} [list protocol-setup-action $target] \
1701 {Delete} [list protocol-setup-delete $target] \
1702 {Cancel} [list destroy $w]] 0
1705 proc database-select-action {} {
1706 set w .database-select.top
1708 foreach indx [$w.databases.list curselection] {
1709 lappend b [$w.databases.list get $indx]
1712 z39 databaseNames $b
1714 destroy .database-select
1717 proc database-select {} {
1718 set w .database-select
1728 frame $w.top.databases -relief ridge -border 2
1730 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
1732 label $w.top.databases.label -text "List"
1733 listbox $w.top.databases.list -geometry 20x6 \
1734 -yscrollcommand "$w.top.databases.scroll set"
1735 scrollbar $w.top.databases.scroll -orient vertical -border 1
1736 pack $w.top.databases.label -side top -fill x \
1738 pack $w.top.databases.list -side left -fill both -expand yes \
1740 pack $w.top.databases.scroll -side right -fill y \
1742 $w.top.databases.scroll config -command "$w.top.databases.list yview"
1744 foreach b [lindex $profile($hostid) 7] {
1745 $w.top.databases.list insert end $b
1747 top-down-ok-cancel $w {database-select-action} 1
1750 proc cascade-target-list {} {
1753 foreach sub [winfo children .top.target.m.clist] {
1756 .top.target.m.clist delete 0 last
1757 foreach n [array names profile] {
1758 if {$n != "Default"} {
1759 set nl [lindex $profile($n) 12]
1760 if {[llength [lindex $profile($n) 7]] > 1} {
1761 .top.target.m.clist add cascade -label $n \
1762 -menu .top.target.m.clist.$nl
1763 menu .top.target.m.clist.$nl
1764 foreach b [lindex $profile($n) 7] {
1765 .top.target.m.clist.$nl add command -label $b \
1766 -command [list reopen-target $n $b]
1769 .top.target.m.clist add command -label $n \
1770 -command [list reopen-target $n {}]
1774 .top.target.m.slist delete 0 last
1775 foreach n [array names profile] {
1776 if {$n != "Default"} {
1777 .top.target.m.slist add command -label $n \
1778 -command [list protocol-setup $n]
1783 proc query-select {i} {
1784 global queryButtonsFind
1785 global queryInfoFind
1789 set queryInfoFind [lindex $queryInfo $i]
1790 set queryButtonsFind [lindex $queryButtons $i]
1792 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
1795 proc query-new-action {} {
1799 global settingsChanged
1801 set settingsChanged 1
1802 lappend queryTypes [.query-new.top.index.entry get]
1803 lappend queryButtons {}
1804 lappend queryInfo {}
1818 -side top -anchor e -pady 2
1819 entry-fields $w.top index \
1821 query-new-action {destroy .query-new}
1822 top-down-ok-cancel $w query-new-action 1
1825 proc query-delete-action {queryNo} {
1829 global settingsChanged
1831 set settingsChanged 1
1833 set queryTypes [lreplace $queryTypes $queryNo $queryNo]
1834 set queryButtons [lreplace $queryButtons $queryNo $queryNo]
1835 set queryInfo [lreplace $queryInfo $queryNo $queryNo]
1836 destroy .query-delete
1840 proc query-delete {queryNo} {
1848 set n [lindex $queryTypes $queryNo]
1850 label $w.top.warning -bitmap warning
1851 message $w.top.quest -text "Are you sure you want to delete the \
1852 query type $n ?" -aspect 200
1853 pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
1854 bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
1855 {Cancel} [list destroy $w]] 1
1858 proc cascade-query-list {} {
1860 set w .top.options.m.query
1863 $w.slist delete 0 last
1864 foreach n $queryTypes {
1865 $w.slist add command -label $n -command [list query-setup $i]
1870 $w.clist delete 0 last
1871 foreach n $queryTypes {
1872 $w.clist add command -label $n -command [list query-select $i]
1876 $w.dlist delete 0 last
1877 foreach n $queryTypes {
1878 $w.dlist add command -label $n -command [list query-delete $i]
1883 proc save-geometry {} {
1884 global windowGeometry
1887 global displayFormat
1890 set windowGeometry(.) [wm geometry .]
1892 set f [open "~/.clientrc.tcl" w]
1894 puts $f "set hotTargets \{ $hotTargets \}"
1895 puts $f "set textWrap $textWrap"
1896 puts $f "set displayFormat $displayFormat"
1897 puts $f "set popupMarcdf $popupMarcdf"
1898 foreach n [array names windowGeometry] {
1899 puts -nonewline $f "set \{windowGeometry($n)\} \{"
1900 puts -nonewline $f $windowGeometry($n)
1906 proc save-settings {} {
1909 global settingsChanged
1914 if {![file writeable "${libdir}/clientrc.tcl"]} {
1917 set f [open "${libdir}/clientrc.tcl" w]
1918 puts $f "# Setup file"
1920 foreach n [array names profile] {
1921 puts -nonewline $f "set \{profile($n)\} \{"
1922 puts -nonewline $f $profile($n)
1925 puts -nonewline $f "set queryTypes \{"
1926 puts -nonewline $f $queryTypes
1929 puts -nonewline $f "set queryButtons \{"
1930 puts -nonewline $f $queryButtons
1933 puts -nonewline $f "set queryInfo \{"
1934 puts -nonewline $f $queryInfo
1937 set settingsChanged 0
1949 label $w.top.warning -bitmap warning
1950 message $w.top.message -text $ask -aspect 200 \
1951 -font -Adobe-Times-Medium-R-Normal-*-180-*
1953 pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
1956 top-down-ok-cancel $w {alert-action} 1
1960 proc alert-action {} {
1966 proc exit-action {} {
1967 global settingsChanged
1969 if {$settingsChanged} {
1970 set a [alert "you haven't saved your settings. Do you wish to save?"]
1979 proc listbuttonaction {w name h user i} {
1980 $w configure -text [lindex $name 0]
1981 $h [lindex $name 1] $user $i
1984 proc listbuttonx {button no names handle user} {
1985 if {[winfo exists $button]} {
1986 $button configure -text [lindex [lindex $names $no] 0]
1987 ${button}.m delete 0 last
1989 menubutton $button -text [lindex [lindex $names $no] 0] \
1990 -width 10 -menu ${button}.m -relief raised -border 1
1994 foreach name $names {
1995 ${button}.m add command -label [lindex $name 0] \
1996 -command [list listbuttonaction ${button} $name \
2002 proc listbutton {button no names} {
2003 menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
2004 -relief raised -border 1
2006 foreach name $names {
2007 ${button}.m add command -label $name \
2008 -command [list ${button} configure -text $name]
2012 proc listbuttonv-action {button var names i} {
2015 set $var [lindex $names [expr $i+1]]
2016 $button configure -text [lindex $names $i]
2019 proc listbuttonv {button var names} {
2023 eval "set val $$var"
2024 set l [llength $names]
2025 for {set i 1} {$i < $l} {incr i 2} {
2026 if {$val == [lindex $names $i]} {
2028 set n [lindex $names $i]
2032 if {[winfo exists $button]} {
2033 $button configure -text $n
2036 menubutton $button -text $n -menu ${button}.m \
2037 -relief raised -border 1
2039 for {set i 0} {$i < $l} {incr i 2} {
2040 ${button}.m add command -label [lindex $names $i] \
2041 -command [list listbuttonv-action $button $var $names $i]
2045 proc query-add-index-action {queryNo} {
2049 global queryButtonsTmp
2051 set newI [.query-add-index.top.index.entry get]
2052 lappend queryInfoTmp [list $newI {}]
2053 $w.top.index.list insert end $newI
2054 destroy .query-add-index
2055 #destroy $w.top.lines
2056 #frame $w.top.lines -relief ridge -border 2
2057 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2058 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2061 proc query-add-line {queryNo} {
2065 global queryButtonsTmp
2067 lappend queryButtonsTmp {I 0}
2069 #destroy $w.top.lines
2070 #frame $w.top.lines -relief ridge -border 2
2071 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2072 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2075 proc query-del-line {queryNo} {
2079 global queryButtonsTmp
2081 set l [llength $queryButtonsTmp]
2086 set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
2087 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2090 proc query-add-index {queryNo} {
2091 set w .query-add-index
2094 place-force $w .query-setup
2098 -side top -anchor e -pady 2
2099 entry-fields $w.top {index} \
2101 [list query-add-index-action $queryNo] [list destroy $w]
2102 top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
2105 proc query-setup-action {queryNo} {
2108 global queryButtonsTmp
2110 global queryButtonsFind
2111 global queryInfoFind
2113 global settingsChanged
2115 set settingsChanged 1
2117 set queryInfo [lreplace $queryInfo $queryNo $queryNo \
2119 set queryButtons [lreplace $queryButtons $queryNo $queryNo \
2121 set queryInfoFind $queryInfoTmp
2122 set queryButtonsFind $queryButtonsTmp
2124 destroy .query-setup
2125 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2128 proc activate-e-index {value no i} {
2129 global queryButtonsTmp
2130 global queryIndexTmp
2132 set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
2133 dputs $queryButtonsTmp
2134 set queryIndexTmp $i
2137 proc activate-index {value no i} {
2138 global queryButtonsFind
2140 set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
2142 dputs "queryButtonsFind $queryButtonsFind"
2145 proc update-attr {} {
2147 listbuttonv $w.top.relation.b relationTmpValue\
2148 {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
2149 {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
2150 {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
2151 listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
2152 {First in field} 1 {First in subfield} 2 {Any position in field} 3}
2153 listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
2154 {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list} 6 \
2155 {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
2156 {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
2157 {local-number} 107 {string} 108 {numeric string} 109}
2158 listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
2159 {Left} 2 {Left and right} 3 {No truncation} 100 \
2160 {Process #} 101 {Re-1} 102 {Re-2} 103}
2161 listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
2162 {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
2165 proc use-attr {init} {
2177 {BNB card number} 10
2178 {BGF(sic) number} 11
2180 {Dewey classification} 13
2181 {UDC classification} 14
2182 {Bliss classification} 15
2184 {NLM call number} 17
2185 {NAL call number} 18
2186 {MOS call number} 19
2187 {Local classification} 20
2188 {Subject heading} 21
2190 {BDI-index-subject} 23
2194 {LC-subject-heading} 27
2195 {RVM-subject-heading} 28
2196 {Local subject index} 29
2198 {Date of publication} 31
2199 {Date of acquisition} 32
2201 {Title-collective} 34
2204 {Title-added-title-page} 37
2208 {Title-other-variant} 41
2210 {Title-abbreviated} 43
2214 {Subject-subdivision} 47
2215 {Number-natl-bibliography} 48
2216 {Number-legal-deposit} 49
2217 {Number-govt-publication} 50
2218 {Number-publisher-for-music} 51
2220 {Number-local-call} 53
2222 {Code-geographic-area} 55
2223 {Code-institution} 56
2225 {Name-geographic} 58
2226 {Place-publication} 59
2228 {Microform-generation} 61
2235 {Author-name-personal} 1004
2236 {Author-name-corporate} 1005
2237 {Author-name-conference} 1006
2238 {Identifier-standard} 1007
2239 {Subject-LC-children's} 1008
2240 {Subject-name-personal} 1009
2242 {Date/time added to database} 1011
2243 {Date/time last modified} 1012
2244 {Authority/format identifier} 1013
2246 {Concept-reference} 1015
2248 {Server choice} 1017
2250 {Record source} 1019
2253 {Geographic class} 1022
2257 {Related periodical} 1026
2258 {Report number} 1027
2260 {Thematic number} 1030
2261 {Material type} 1031
2269 set l [llength $attr]
2274 for {set i 0} {$i < $l} {incr i} {
2275 $w.top.use.list insert end [lindex $attr $i]
2277 if {$useTmpValue == [lindex $attr $i]} {
2282 $w.top.use.list select from $s
2283 $w.top.use.list select to $s
2288 $w.top.use.list yview $s
2290 set lno [lindex [$w.top.use.list curselection] 0]
2291 set i [expr $lno+$lno+1]
2292 set useTmpValue [lindex $attr $i]
2293 dputs "useTmpValue=$useTmpValue"
2297 proc index-setup-action {oldAttr queryNo indexNo} {
2298 set attr [lindex $oldAttr 0]
2301 global relationTmpValue
2302 global structureTmpValue
2303 global truncationTmpValue
2304 global completenessTmpValue
2305 global positionTmpValue
2310 dputs "index-setup-action"
2311 dputs "queryNo $queryNo"
2312 dputs "indexNo $indexNo"
2313 if {$useTmpValue > 0} {
2314 lappend attr "1=$useTmpValue"
2316 if {$relationTmpValue > 0} {
2317 lappend attr "2=$relationTmpValue"
2319 if {$positionTmpValue > 0} {
2320 lappend attr "3=$positionTmpValue"
2322 if {$structureTmpValue > 0} {
2323 lappend attr "4=$structureTmpValue"
2325 if {$truncationTmpValue > 0} {
2326 lappend attr "5=$truncationTmpValue"
2328 if {$completenessTmpValue > 0} {
2329 lappend attr "6=$completenessTmpValue"
2331 dputs "new attr $attr"
2332 set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
2333 destroy .index-setup
2336 proc index-setup {attr queryNo indexNo} {
2339 global relationTmpValue
2340 global structureTmpValue
2341 global truncationTmpValue
2342 global completenessTmpValue
2343 global positionTmpValue
2345 set relationTmpValue 0
2346 set truncationTmpValue 0
2347 set structureTmpValue 0
2348 set positionTmpValue 0
2349 set completenessTmpValue 0
2352 set len [llength $attr]
2353 for {set i 1} {$i < $len} {incr i} {
2354 set q [lindex $attr $i]
2355 set l [string first = $q]
2357 set t [string range $q 0 [expr $l - 1]]
2358 set v [string range $q [expr $l + 1] end]
2361 { set useTmpValue $v }
2363 { set relationTmpValue $v }
2365 { set positionTmpValue $v }
2367 { set structureTmpValue $v }
2369 { set truncationTmpValue $v }
2371 { set completenessTmpValue $v }
2375 if {[winfo exists $w]} {
2380 set n [lindex $attr 0]
2381 wm title $w "Index setup $n"
2385 frame $w.top.use -relief ridge -border 2
2386 frame $w.top.relation -relief ridge -border 2
2387 frame $w.top.position -relief ridge -border 2
2388 frame $w.top.structure -relief ridge -border 2
2389 frame $w.top.truncation -relief ridge -border 2
2390 frame $w.top.completeness -relief ridge -border 2
2396 pack $w.top.use -side left -pady 6 -padx 6 -fill y
2398 label $w.top.use.label -text "Use"
2399 listbox $w.top.use.list -geometry 26x10 \
2400 -yscrollcommand "$w.top.use.scroll set"
2401 scrollbar $w.top.use.scroll -orient vertical -border 1
2402 pack $w.top.use.label -side top -fill x \
2404 pack $w.top.use.list -side left -fill both -expand yes \
2406 pack $w.top.use.scroll -side right -fill y \
2408 $w.top.use.scroll config -command "$w.top.use.list yview"
2412 # Relation Attributes
2414 pack $w.top.relation -pady 6 -padx 6 -side top
2415 label $w.top.relation.label -text "Relation" -width 18
2417 pack $w.top.relation.label $w.top.relation.b -fill x
2419 # Position Attributes
2421 pack $w.top.position -pady 6 -padx 6 -side top
2422 label $w.top.position.label -text "Position" -width 18
2424 pack $w.top.position.label $w.top.position.b -fill x
2426 # Structure Attributes
2428 pack $w.top.structure -pady 6 -padx 6 -side top
2429 label $w.top.structure.label -text "Structure" -width 18
2431 pack $w.top.structure.label $w.top.structure.b -fill x
2433 # Truncation Attributes
2435 pack $w.top.truncation -pady 6 -padx 6 -side top
2436 label $w.top.truncation.label -text "Truncation" -width 18
2438 pack $w.top.truncation.label $w.top.truncation.b -fill x
2440 # Completeness Attributes
2442 pack $w.top.completeness -pady 6 -padx 6 -side top
2443 label $w.top.completeness.label -text "Completeness" -width 18
2445 pack $w.top.completeness.label $w.top.completeness.b -fill x
2448 bottom-buttons $w [list \
2449 {Ok} [list index-setup-action $attr $queryNo $indexNo] \
2450 {Cancel} [list destroy $w]] 0
2454 proc query-edit-index {queryNo} {
2458 set i [lindex [$w.top.index.list curselection] 0]
2462 set attr [lindex $queryInfoTmp $i]
2463 dputs "Editing no $i $attr"
2464 index-setup $attr $queryNo $i
2467 proc query-delete-index {queryNo} {
2469 global queryButtonsTmp
2472 set i [lindex [$w.top.index.list curselection] 0]
2476 set queryInfoTmp [lreplace $queryInfoTmp $i $i]
2477 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2478 $w.top.index.list delete $i
2481 proc query-setup {queryNo} {
2487 global queryButtonsTmp
2489 global queryIndexTmp
2492 set queryName [lindex $queryTypes $queryNo]
2493 set queryInfoTmp [lindex $queryInfo $queryNo]
2494 set queryButtonsTmp [lindex $queryButtons $queryNo]
2499 wm title $w "Query setup $queryName"
2503 frame $w.top.lines -relief ridge -border 2
2505 pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2509 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2511 button $w.top.lines.add -text "Add" \
2512 -command [list query-add-line $queryNo]
2513 button $w.top.lines.del -text "Remove" \
2514 -command [list query-del-line $queryNo]
2516 pack $w.top.lines.del -fill x -side bottom
2517 pack $w.top.lines.add -fill x -pady 10 -side bottom
2521 frame $w.top.index -relief ridge -border 2
2522 pack $w.top.index -pady 6 -padx 6 -side right -fill y
2524 listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
2525 scrollbar $w.top.index.scroll -orient vertical -border 1 \
2526 -command [list $w.top.index.list yview]
2527 bind $w.top.index.list <2> [list query-edit-index $queryNo]
2529 pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
2530 pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
2532 $w.top.index.list select from 0
2533 $w.top.index.list select to 0
2535 foreach x $queryInfoTmp {
2536 $w.top.index.list insert end [lindex $x 0]
2539 bottom-buttons $w [list \
2540 {Ok} [list query-setup-action $queryNo] \
2541 {Add index} [list query-add-index $queryNo] \
2542 {Edit index} [list query-edit-index $queryNo] \
2543 {Delete index} [list query-delete-index $queryNo] \
2544 {Cancel} [list destroy $w]] 0
2547 proc index-clear {} {
2548 global queryButtonsFind
2551 foreach b $queryButtonsFind {
2552 .lines.$i.e delete 0 end
2557 proc index-query {} {
2558 global queryButtonsFind
2559 global queryInfoFind
2564 foreach b $queryButtonsFind {
2565 set term [string trim [.lines.$i.e get]]
2567 set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
2569 set len [string length $term]
2573 if {[string index $term $len] == "?"} {
2575 set term [string range $term 0 [expr $len - 1]]
2577 if {[string index $term 0] == "?"} {
2579 set term [string range $term 1 end]
2581 set term "\{${term}\}"
2582 if {$right && $left} {
2583 set term "@attr 5=3 ${term}"
2585 set term "@attr 5=1 ${term}"
2587 set term "@attr 5=2 ${term}"
2590 set term "@attr $a ${term}"
2593 set qs "@and ${qs} ${term}"
2604 proc index-focus-in {w i} {
2605 global curIndexEntry
2607 $w.$i configure -background red
2608 set curIndexEntry $i
2611 proc index-lines {w realOp buttonInfo queryInfo handle} {
2613 foreach b $buttonInfo {
2614 if {! [winfo exists $w.$i]} {
2615 frame $w.$i -background white -border 1
2617 listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
2620 if {! [winfo exists $w.$i.e]} {
2621 entry $w.$i.e -width 32 -relief sunken -border 1
2622 bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
2623 bind $w.$i.e <FocusOut> [list $w.$i configure \
2625 pack $w.$i.l -side left
2626 pack $w.$i.e -side left -fill x -expand yes
2627 pack $w.$i -side top -fill x -padx 2 -pady 2
2628 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
2629 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
2630 bind $w.$i.e <Return> {search-request 0}
2633 pack $w.$i.l -side left
2634 pack $w.$i -side top -fill x -padx 2 -pady 2
2639 while {[winfo exists $w.$j]} {
2650 bind $w.$j.e <Tab> "focus $w.$k.e"
2654 bind $w.$i.e <Tab> "focus $w.0.e"
2659 proc search-fields {w buttondefs} {
2661 foreach buttondef $buttondefs {
2662 frame $w.$i -background white
2664 listbutton $w.$i.l 0 $buttondef
2665 entry $w.$i.e -width 32 -relief sunken
2667 pack $w.$i.l -side left
2668 pack $w.$i.e -side left -fill x -expand yes
2670 pack $w.$i -side top -fill x -padx 2 -pady 2
2672 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
2673 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
2681 bind $w.$j.e <Tab> "focus $w.$k.e \n
2682 $w.$k configure -background red \n
2683 $w.$j configure -background white"
2686 bind $w.$i.e <Tab> "focus $w.0.e \n
2687 $w.0 configure -background red \n
2688 $w.$i configure -background white"
2690 $w.0 configure -background red
2693 if {[info exists windowGeometry(.)]} {
2694 set g $windowGeometry(.)
2702 frame .top -border 1 -relief raised
2703 frame .lines -border 1 -relief raised
2704 frame .mid -border 1 -relief raised
2705 frame .data -border 1 -relief raised
2706 frame .bot -border 1 -relief raised
2707 pack .top .lines .mid -side top -fill x
2708 pack .data -side top -fill both -expand yes
2711 menubutton .top.file -text "File" -menu .top.file.m
2713 .top.file.m add command -label "Save settings" -command {save-settings}
2714 .top.file.m add separator
2715 .top.file.m add command -label "Exit" -command {exit-action}
2717 menubutton .top.target -text "Target" -menu .top.target.m
2719 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
2720 .top.target.m add command -label "Disconnect" -command {close-target}
2721 .top.target.m add command -label "About" -command {about-target}
2722 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
2723 .top.target.m add command -label "Setup new" -command {define-target-dialog}
2724 .top.target.m add separator
2727 .top.target.m disable 1
2728 .top.target.m disable 2
2730 menu .top.target.m.clist
2731 menu .top.target.m.slist
2734 menubutton .top.service -text "Service" -menu .top.service.m
2736 .top.service.m add command -label "Database" -command {database-select}
2737 .top.service.m add cascade -label "Present" -menu .top.service.m.present
2738 menu .top.service.m.present
2739 .top.service.m.present add command -label "10 More" \
2740 -command [list present-more 10]
2741 .top.service.m.present add command -label "All" \
2742 -command [list present-more {}]
2743 .top.service.m add command -label "Search" -command {search-request 0}
2744 .top.service.m add command -label "Scan" -command {scan-request}
2746 .top.service configure -state disabled
2748 menubutton .top.rset -text "Set" -menu .top.rset.m
2750 .top.rset.m add command -label "Load" -command {load-set}
2751 .top.rset.m add separator
2753 menubutton .top.options -text "Options" -menu .top.options.m
2755 .top.options.m add cascade -label "Query" -menu .top.options.m.query
2756 .top.options.m add cascade -label "Format" -menu .top.options.m.formats
2757 .top.options.m add cascade -label "Wrap" -menu .top.options.m.wrap
2759 menu .top.options.m.query
2760 .top.options.m.query add cascade -label "Select" \
2761 -menu .top.options.m.query.clist
2762 .top.options.m.query add cascade -label "Edit" \
2763 -menu .top.options.m.query.slist
2764 .top.options.m.query add command -label "New" \
2765 -command {query-new}
2766 .top.options.m.query add cascade -label "Delete" \
2767 -menu .top.options.m.query.dlist
2769 menu .top.options.m.query.slist
2770 menu .top.options.m.query.clist
2771 menu .top.options.m.query.dlist
2774 menu .top.options.m.formats
2776 foreach f $displayFormats {
2777 .top.options.m.formats add radiobutton -label $f -value $i \
2778 -command [list set-display-format $i] -variable displayFormat
2782 menu .top.options.m.wrap
2783 .top.options.m.wrap add radiobutton -label "Character" \
2784 -value char -variable textWrap -command {set-wrap char}
2785 .top.options.m.wrap add radiobutton -label "Word" \
2786 -value word -variable textWrap -command {set-wrap word}
2787 .top.options.m.wrap add radiobutton -label "None" \
2788 -value none -variable textWrap -command {set-wrap none}
2790 menubutton .top.help -text "Help" -menu .top.help.m
2793 .top.help.m add command -label "Help on help" \
2794 -command {tkerror "Help on help not available. Sorry"}
2795 .top.help.m add command -label "About" -command {about-origin}
2797 pack .top.file .top.target .top.service .top.rset .top.options -side left
2798 pack .top.help -side right
2800 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
2802 button .mid.search -width 7 -text {Search} -command {search-request 0} \
2804 button .mid.scan -width 7 -text {Scan} \
2805 -command scan-request -state disabled
2806 button .mid.present -width 7 -text {Present} -command [list present-more 10] \
2809 button .mid.clear -width 7 -text {Clear} -command index-clear
2810 pack .mid.search .mid.scan .mid.present .mid.clear -side left \
2811 -fill y -padx 5 -pady 3
2813 text .data.record -height 2 -width 20 -wrap none \
2814 -yscrollcommand [list .data.scroll set] -wrap $textWrap
2815 scrollbar .data.scroll -command [list .data.record yview]
2816 pack .data.scroll -side right -fill y
2817 pack .data.record -expand yes -fill both
2820 if {[tk colormodel .] == "color"} {
2821 .data.record tag configure marc-tag -foreground blue
2822 .data.record tag configure marc-id -foreground red
2824 .data.record tag configure marc-tag -foreground black
2825 .data.record tag configure marc-id -foreground black
2827 .data.record tag configure marc-data -foreground black
2829 button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
2831 pack .bot.a -side left -fill x
2832 pack .bot.logo -side right -padx 2 -pady 2
2834 message .bot.a.target -text "" -aspect 1000 -border 1
2836 label .bot.a.status -text "Not connected" -width 15 -relief \
2837 sunken -anchor w -border 1
2838 label .bot.a.set -text "" -width 5 -relief \
2839 sunken -anchor w -border 1
2840 label .bot.a.message -text "" -width 15 -relief \
2841 sunken -anchor w -border 1
2843 pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
2844 pack .bot.a.status .bot.a.set .bot.a.message \
2845 -side left -padx 2 -pady 2