1 # IR toolkit for tcl/tk
3 # See the file LICENSE for details.
4 # Sebastian Hammer, Adam Dickmeiss
7 # Revision 1.53 1995-06-26 12:40:09 adam
8 # Client defines its own tkerror.
9 # User may specify 'no preferredRecordSyntax'.
11 # Revision 1.52 1995/06/22 13:14:59 adam
12 # Feature: SUTRS. Setting getSutrs implemented.
13 # Work on display formats.
14 # Preferred record syntax can be set by the user.
16 # Revision 1.51 1995/06/21 11:11:00 adam
17 # Bug fix: libdir undefined in about-origin.
19 # Revision 1.50 1995/06/21 11:04:48 adam
20 # Uses GNU autoconf 2.3.
21 # Install procedure implemented.
22 # boook bitmaps moved to sub directory bitmaps.
24 # Revision 1.49 1995/06/20 14:16:42 adam
25 # More work on cancel mechanism.
27 # Revision 1.48 1995/06/20 08:07:23 adam
28 # New setting: failInfo.
29 # Working on better cancel mechanism.
31 # Revision 1.47 1995/06/19 14:05:29 adam
32 # Bug fix: asked for SUTRS.
34 # Revision 1.46 1995/06/19 13:06:06 adam
35 # New define: IR_TCL_VERSION.
37 # Revision 1.45 1995/06/19 08:08:44 adam
38 # client.tcl: hotTargets now contain both database and target name.
39 # ir-tcl.c: setting protocol edited. Errors in callbacks are logged
40 # by logf(LOG_WARN, ...) calls.
42 # Revision 1.44 1995/06/16 14:55:18 adam
45 # Revision 1.43 1995/06/16 14:41:05 adam
46 # Scan line entries can be copied to a search entry.
48 # Revision 1.42 1995/06/16 12:28:13 adam
49 # Implemented preferredRecordSyntax.
50 # Minor changes in diagnostic handling.
51 # Record list deleted when connection closes.
53 # Revision 1.41 1995/06/14 15:07:59 adam
54 # Bug fix in cascade-target-list. Uses yaz-version.h.
56 # Revision 1.40 1995/06/14 13:37:17 adam
57 # Setting recordType implemented.
58 # Setting implementationVersion implemented.
59 # Settings implementationId / implementationName edited.
61 # Revision 1.39 1995/06/14 12:16:22 adam
62 # hotTargets, textWrap and displayFormat saved in clientg.tcl.
64 # Revision 1.38 1995/06/14 07:22:45 adam
65 # Target definitions can be deleted.
66 # Listbox used in the query definition dialog.
68 # Revision 1.37 1995/06/13 14:37:59 adam
69 # Work on query setup.
70 # Better about origin/target.
71 # Better presentation formats.
73 # Revision 1.36 1995/06/13 07:42:14 adam
74 # Bindings removed from text widgets.
76 # Revision 1.35 1995/06/12 15:17:31 adam
77 # Text widget used in main window (instead of listbox) to support
78 # better presentation formats.
80 # Revision 1.34 1995/06/12 07:59:07 adam
81 # More work on geometry handling.
83 # Revision 1.33 1995/06/09 11:17:35 adam
84 # Start work on geometry management.
86 # Revision 1.32 1995/06/07 09:16:37 adam
87 # New presentation format.
89 # Revision 1.31 1995/06/06 16:31:09 adam
90 # Bug fix: target names couldn't contain blanks.
93 # Revision 1.30 1995/06/06 11:35:41 adam
94 # Work on scan. Display of old sets.
96 # Revision 1.29 1995/06/05 14:11:18 adam
97 # Bug fix in present-more.
99 # Revision 1.28 1995/06/02 14:52:13 adam
100 # Minor changes really.
102 # Revision 1.27 1995/06/02 14:29:42 adam
103 # Work on scan interface - up/down buttons.
105 # Revision 1.26 1995/06/01 16:36:46 adam
106 # About buttons. Minor bug fixes.
108 # Revision 1.25 1995/05/31 13:09:57 adam
109 # Client searches/presents may be interrupted.
110 # New moving book-logo.
112 # Revision 1.24 1995/05/31 08:36:24 adam
113 # Bug fix in client.tcl: didn't save options on clientrc.tcl.
114 # New method: referenceId. More work on scan.
116 # Revision 1.23 1995/05/29 10:33:41 adam
117 # README and rename of startup script.
119 # Revision 1.22 1995/05/26 11:44:09 adam
120 # Bugs fixed. More work on MARC utilities and queries. Test
121 # client is up-to-date again.
123 # Revision 1.21 1995/05/11 15:34:46 adam
124 # Scan request changed a bit. This version works with RLG.
126 # Revision 1.20 1995/04/21 16:31:57 adam
127 # New radiobutton: protocol (z39v2/SR).
129 # Revision 1.19 1995/04/18 16:11:50 adam
130 # First version of graphical Scan. Some work on query-by-form.
132 # Revision 1.18 1995/04/10 10:50:22 adam
133 # Result-set name defaults to suffix of ir-set name.
134 # Started working on scan. Not finished at this point.
136 # Revision 1.17 1995/03/31 09:34:57 adam
137 # Search-button disabled when there is no connection.
139 # Revision 1.16 1995/03/31 08:56:36 adam
140 # New button "Search".
142 # Revision 1.15 1995/03/28 12:45:22 adam
143 # New ir method failback: called on disconnect/protocol error.
144 # New ir set/get method: protocol: SR / Z3950.
145 # Simple popup and disconnect when failback is invoked.
147 # Revision 1.14 1995/03/22 16:07:55 adam
150 # Revision 1.13 1995/03/21 17:27:26 adam
151 # Short-hand keys in setup.
153 # Revision 1.12 1995/03/21 13:41:03 adam
154 # Comstack cs_create not used too often. Non-blocking connect.
156 # Revision 1.11 1995/03/21 10:39:06 adam
157 # Diagnostic error message displayed with tkerror.
159 # Revision 1.10 1995/03/20 15:24:06 adam
160 # Diagnostic records saved on searchResponse.
162 # Revision 1.9 1995/03/17 18:26:16 adam
163 # Non-blocking i/o used now. Database names popup as cascade items.
165 # Revision 1.8 1995/03/17 15:45:00 adam
166 # Improved target/database setup.
168 # Revision 1.7 1995/03/16 17:54:03 adam
169 # Minor changes really.
171 # Revision 1.6 1995/03/15 19:10:20 adam
172 # Database setup in protocol-setup (rather target setup).
174 # Revision 1.5 1995/03/15 13:59:23 adam
177 # Revision 1.4 1995/03/14 17:32:29 adam
178 # Presentation of full Marc record in popup window.
180 # Revision 1.3 1995/03/12 19:31:52 adam
181 # Pattern matching implemented when retrieving MARC records. More
182 # diagnostic functions.
184 # Revision 1.2 1995/03/10 18:00:15 adam
185 # Actual presentation in line-by-line format. RPN query support.
187 # Revision 1.1 1995/03/09 16:15:07 adam
188 # First presentRequest attempts. Hot-target list.
193 if {[file readable clientrc.tcl]} {
200 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {} 1 {} {} Z39}
202 set settingsChanged 0
211 set recordSyntax None
214 set queryTypes {Simple}
215 set queryButtons { { {I 0} {I 1} {I 2} } }
216 set queryInfo { { {Title {1=4 4=1}} {Author {1=1}} \
217 {Subject {1=21}} {Any {1=1016}} } }
226 if {[winfo exists $w]} {
235 label $w.top.b -bitmap error
236 message $w.top.t -aspect 300 -text "Error: $err" \
237 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
238 pack $w.top.b $w.top.t -side left -padx 10 -pady 10
240 bottom-buttons $w [list {Close} [list destroy $w]] 0
243 proc read-formats {} {
244 global displayFormats
246 set formats [glob -nocomplain ${libdir}/formats/*.tcl]
248 if {[file readable $f]} {
250 set l [string length $f]
251 set f [string range $f [string length "${libdir}/formats/"] \
253 lappend displayFormats $f
262 .data.record configure -wrap $m
269 proc set-display-format {f} {
279 .bot.a.status configure -text "Reformatting"
282 add-title-lines -1 10000 1
284 .bot.a.status configure -text "Ready"
288 proc initBindings {} {
291 bind $w <Double-1> {}
292 bind $w <Triple-1> {}
293 bind $w <B1-Motion> {}
295 bind $w <Shift-B1-Motion> {}
297 bind $w <B2-Motion> {}
298 bind $w <Any-KeyPress> {}
300 bind $w <BackSpace> {}
302 bind $w <Control-h> {}
303 bind $w <Control-d> {}
304 bind $w <Control-v> {}
307 bind $w <B1-Motion> {}
308 bind $w <Shift-B1-Motion> {}
313 proc post-menu {wbutton wmenu} {
316 $wmenu post [winfo rootx $wbutton] \
317 [expr [winfo rooty $wbutton]+[winfo height $wbutton]]
322 global windowGeometry
323 set windowGeometry($w) [wm geometry $w]
326 global windowGeometry
329 if {[info exists windowGeometry($w)]} {
330 set g $windowGeometry($w)
335 bind $w <Destroy> [list destroyGW $w]
338 if {[file readable "${libdir}/clientrc.tcl"]} {
339 source "${libdir}/clientrc.tcl"
342 if {[file readable "~/.clientrc.tcl"]} {
343 source "~/.clientrc.tcl"
346 set queryButtonsFind [lindex $queryButtons 0]
347 set queryInfoFind [lindex $queryInfo 0]
349 proc top-down-window {w} {
350 frame $w.top -relief raised -border 1
351 frame $w.bot -relief raised -border 1
353 pack $w.top -side top -fill both -expand yes
354 pack $w.bot -fill both
357 proc top-down-ok-cancel {w ok-action g} {
358 frame $w.bot.left -relief sunken -border 1
359 pack $w.bot.left -side left -expand yes -ipadx 2 -ipady 2 -padx 5 -pady 5
360 button $w.bot.left.ok -width 6 -text {Ok} \
361 -command ${ok-action}
362 pack $w.bot.left.ok -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3
363 button $w.bot.cancel -width 6 -text {Cancel} \
364 -command [list destroy $w]
365 pack $w.bot.cancel -side left -expand yes
373 proc bottom-buttons {w buttonList g} {
375 set l [llength $buttonList]
377 frame $w.bot.$i -relief sunken -border 1
378 pack $w.bot.$i -side left -expand yes -padx 5 -pady 5
379 button $w.bot.$i.ok -text [lindex $buttonList $i] \
380 -command [lindex $buttonList [expr $i+1]]
381 pack $w.bot.$i.ok -expand yes -ipadx 3 -ipady 2 -padx 3 -pady 3 -side left
385 button $w.bot.$i -text [lindex $buttonList $i] \
386 -command [lindex $buttonList [expr $i+1]]
387 pack $w.bot.$i -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3 -side left
397 proc cancel-operation {} {
405 show-status Cancel 0 1
409 proc show-target {target base} {
413 .bot.a.target configure -text ""
417 .bot.a.target configure -text "$target"
419 .bot.a.target configure -text "$target - $base"
423 proc show-logo {v1} {
432 .bot.logo configure -bitmap @${libdir}/bitmaps/book${v1}
433 after 140 [list show-logo $v1]
437 .bot.logo configure -bitmap @${libdir}/bitmaps/book1
446 proc show-status {status b sb} {
453 .bot.a.status configure -text "$status"
455 if {$busy == 0} {set busy 1}
463 .top.service configure -state normal
464 .mid.search configure -state normal
466 .mid.scan configure -state normal
469 .top.service.m disable 1
470 } elseif {$setOffset > 0 && $setOffset <= [z39.$setNo resultCount]} {
471 .top.service.m enable 1
472 .mid.present configure -state normal
474 .top.service.m disable 1
476 if {[winfo exists .scan-window]} {
477 .scan-window.bot.2 configure -state normal
478 .scan-window.bot.4 configure -state normal
481 .top.service configure -state disabled
482 .mid.search configure -state disabled
483 .mid.scan configure -state disabled
484 .mid.present configure -state disabled
486 if {[winfo exists .scan-window]} {
487 .scan-window.bot.2 configure -state disabled
488 .scan-window.bot.4 configure -state disabled
493 proc show-message {msg} {
494 .bot.a.message configure -text "$msg"
497 proc insertWithTags {w text args} {
498 set start [$w index insert]
499 $w insert insert $text
500 foreach tag [$w tag names $start] {
501 $w tag remove $tag $start insert
504 $w tag add $i $start insert
508 proc popup-license {} {
513 wm title $w "License"
519 text $w.top.t -width 80 -height 10 -wrap word \
520 -yscrollcommand [list $w.top.s set]
521 scrollbar $w.top.s -command [list $w.top.t yview]
523 pack $w.top.s -side right -fill y
524 pack $w.top.t -expand yes -fill both
526 if {[file readable "${libdir}/LICENSE"]} {
527 set f [open "${libdir}/LICENSE" r]
528 while {[gets $f buf] != -1} {
529 $w.top.t insert end $buf
530 $w.top.t insert end "\n"
534 bottom-buttons $w [list {Close} [list destroy $w]] 1
537 proc about-target {} {
538 set w .about-target-w
543 wm title $w "About target"
546 frame $w.top.a -relief ridge -border 2
547 frame $w.top.p -relief ridge -border 2
549 pack $w.top.a $w.top.p -side top -fill x
551 label $w.top.a.about -text "About"
552 label $w.top.a.irtcl -text $hostid \
553 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
554 pack $w.top.a.about $w.top.a.irtcl -side top
556 set i [z39 targetImplementationName]
557 label $w.top.p.in -text "Implementation name: $i"
558 set i [z39 targetImplementationId]
559 label $w.top.p.ii -text "Implementation id: $i"
560 set i [z39 targetImplementationVersion]
561 label $w.top.p.iv -text "Implementation version: $i"
563 label $w.top.p.op -text "Protocol options: $i"
565 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.op -side top -anchor nw
567 bottom-buttons $w [list {Close} [list destroy $w]] 1
570 proc about-origin-logo {n} {
572 set w .about-origin-w
573 if {![winfo exists $w]} {
580 $w.top.a.logo configure -bitmap @${libdir}/bitmaps/book$n
581 after 140 [list about-origin-logo $n]
584 proc about-origin {} {
585 set w .about-origin-w
588 if {[winfo exists $w]} {
593 wm title $w "About IrTcl"
597 frame $w.top.a -relief ridge -border 2
598 frame $w.top.p -relief ridge -border 2
600 pack $w.top.a $w.top.p -side top -fill x
602 label $w.top.a.irtcl -text "IrTcl" \
603 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
604 label $w.top.a.logo -bitmap @${libdir}/bitmaps/book1
605 pack $w.top.a.irtcl $w.top.a.logo -side left -expand yes
607 set i [z39 implementationName]
608 label $w.top.p.in -text "Implementation name: $i"
609 set i [z39 implementationId]
610 label $w.top.p.ii -text "Implementation id: $i"
611 set i [z39 implementationVersion]
612 label $w.top.p.iv -text "Implementation version: $i"
614 pack $w.top.p.in $w.top.p.ii $w.top.p.iv -side top -anchor nw
617 bottom-buttons $w [list {Close} [list destroy $w] \
618 {License} [list popup-license]] 0
621 proc popup-marc {sno no b df} {
623 global displayFormats
626 if {[z39.$sno type $no] != "DB"} {
630 set w .full-marc-$fullMarcSeq
637 if {[winfo exists $w]} {
645 frame $w.top -relief raised -border 1
646 frame $w.bot -relief raised -border 1
648 pack $w.top -side top -fill both -expand yes
649 pack $w.bot -fill both
651 text $w.top.record -width 60 -height 5 -wrap word \
652 -yscrollcommand [list $w.top.s set]
653 scrollbar $w.top.s -command [list $w.top.record yview]
655 if {[tk colormodel .] == "color"} {
656 $w.top.record tag configure marc-tag -foreground blue
657 $w.top.record tag configure marc-id -foreground red
659 $w.top.record tag configure marc-tag -foreground black
660 $w.top.record tag configure marc-id -foreground black
662 $w.top.record tag configure marc-data -foreground black
665 $w.top.record delete 0.0 end
666 set recordType [z39.$sno recordType $no]
667 wm title $w "$recordType record #$no"
670 bind $w.top.record <Return> {destroy .full-marc}
672 pack $w.top.s -side right -fill y
673 pack $w.top.record -expand yes -fill both
676 bottom-buttons $w [list \
677 {Close} [list destroy $w]] 0
679 bottom-buttons $w [list \
680 {Close} [list destroy $w] \
681 {Duplicate} [list popup-marc $sno $no 1 0]] 0
682 menubutton $w.bot.formats -text "Format" -menu $w.bot.formats.m
683 menu $w.bot.formats.m
685 foreach f $displayFormats {
686 $w.bot.formats.m add radiobutton -label $f \
687 -variable popupMarcdf -value $i \
688 -command [list display-$f $sno $no $w.top.record 0]
691 pack $w.bot.formats -expand yes -ipadx 2 -ipady 2 \
692 -padx 3 -pady 3 -side left
696 foreach f $displayFormats {
697 $w.bot.formats.m entryconfigure $i \
698 -command [list display-$f $sno $no $w.top.record 0]
702 set ffunc [lindex $displayFormats $df]
703 set ffunc "display-$ffunc"
705 $ffunc $sno $no $w.top.record 0
708 proc update-target-hotlist {target base} {
711 set len [llength $hotTargets]
713 .top.target.m delete 6 [expr 6+[llength $hotTargets]]
716 foreach e $hotTargets {
717 if {$target == [lindex $e 0] && $base == [lindex $e 1]} {
718 set hotTargets [lreplace $hotTargets $i $i]
723 set hotTargets [linsert $hotTargets 0 [list $target $base]]
727 proc set-target-hotlist {} {
731 foreach e $hotTargets {
732 set target [lindex $e 0]
733 set base [lindex $e 1]
735 .top.target.m add command -label "$i $target" -command \
736 [list reopen-target $target {}]
738 .top.target.m add command -label "$i $target - $base" -command \
739 [list reopen-target $target $base]
748 proc reopen-target {target base} {
750 open-target $target $base
751 update-target-hotlist $target $base
754 proc define-target-action {} {
757 set target [.target-define.top.target.entry get]
761 foreach n [array names profile] {
767 set seq [lindex $profile(Default) 12]
769 set profile($target) $profile(Default)
770 set profile(Default) [lreplace $profile(Default) 12 12 [incr seq]]
772 protocol-setup $target
773 destroy .target-define
776 proc fail-response {target} {
777 set c [lindex [z39 failInfo] 0]
778 set m [lindex [z39 failInfo] 1]
783 proc connect-response {target base} {
784 dputs "connect-response"
785 show-target $target $base
789 proc open-target {target base} {
794 z39 comstack [lindex $profile($target) 6]
795 z39 protocol [lindex $profile($target) 11]
796 z39 idAuthentication [lindex $profile($target) 3]
797 z39 maximumRecordSize [lindex $profile($target) 4]
798 z39 preferredMessageSize [lindex $profile($target) 5]
799 dputs "maximumRecordSize="
800 dputs [z39 maximumRecordSize]
801 dputs "preferredMessageSize="
802 dputs [z39 preferredMessageSize]
803 show-status {Connecting} 1 0
805 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
807 z39 databaseNames $base
809 z39 failback [list fail-response $target]
810 z39 callback [list connect-response $target $base]
813 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
816 tkerror $errorMessage
817 show-status Ready 0 {}
821 .top.target.m disable 0
822 .top.target.m enable 1
823 .top.target.m enable 2
826 proc close-target {} {
833 .bot.a.set configure -text ""
837 show-status {Not connected} 0 0
840 .top.target.m disable 1
841 .top.target.m disable 2
842 .top.target.m enable 0
845 proc load-set-action {} {
849 ir-set z39.$setNo z39
851 set fname [.load-set.top.filename.entry get]
854 show-status {Loading} 1 {}
856 z39.$setNo loadFile $fname
858 set no [z39.$setNo numberOfRecordsReturned]
859 add-title-lines $setNo $no 1
861 set l [format "%-4d %7d" $setNo $no]
862 .top.rset.m add command -label $l \
863 -command [list add-title-lines $setNo 10000 1]
864 show-status {Ready} 0 {}
876 frame $w.top.filename
877 pack $w.top.filename -side top -anchor e -pady 2
879 entry-fields $w.top {filename} \
881 {load-set-action} {destroy .load-set}
883 top-down-ok-cancel $w {load-set-action} 1
887 proc init-request {} {
895 z39 callback {init-response}
896 show-status {Initializing} 1 {}
897 set err [catch {z39 init} errorMessage]
899 tkerror $errorMessage
900 show-status Ready 0 {}
904 proc init-response {} {
912 if {![z39 initResult]} {
913 show-status {Ready} 0 1
914 set u [z39 userInformationField]
916 tkerror "Connection rejected by target: $u"
918 if {[lsearch [z39 options] scan] >= 0} {
923 show-status {Ready} 0 1
927 proc search-request {bflag} {
938 dputs "search-request"
940 if {!$bflag && $busy} {
941 dputs "busy: search-request ignored"
946 show-status {Searching} 1 0
947 set delayRequest {search-request 1}
952 set query [index-query]
957 ir-set z39.$setNo z39
959 if {[lindex $profile($target) 10] == 1} {
960 z39.$setNo setName $setNo
961 dputs "setName=${setNo}"
963 z39.$setNo setName Default
964 dputs "setName=Default"
966 if {[lindex $profile($target) 8] == 1} {
967 z39.$setNo queryType rpn
969 if {[lindex $profile($target) 9] == 1} {
970 z39.$setNo queryType ccl
974 if {$recordSyntax == "None" } {
975 z39.$setNo preferredRecordSyntax {}
977 z39.$setNo preferredRecordSyntax $recordSyntax
979 z39 callback {search-response}
980 z39.$setNo search $query
981 show-status {Searching} 1 0
984 proc scan-copy {y entry} {
986 set no [$w.top.list nearest $y]
988 .lines.$entry.e delete 0 end
989 .lines.$entry.e insert 0 [string range [$w.top.list get $no] 8 end]
992 proc scan-request {} {
1000 global queryButtonsFind
1001 global queryInfoFind
1005 dputs "scan-request"
1008 show-status {Scanning} 1 0
1009 set delayRequest scan-request
1018 set b [lindex $queryButtonsFind $curIndexEntry]
1020 foreach a [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end] {
1021 set attr "@attr $a $attr"
1023 set title [lindex [lindex $queryInfoFind [lindex $b 1]] 0]
1024 ir-scan z39.scan z39
1026 if {![winfo exists $w]} {
1033 entry $w.top.entry -relief sunken
1034 pack $w.top.entry -fill x -padx 4 -pady 2
1035 bind $w.top.entry <KeyRelease> [list scan-term-h $attr]
1037 listbox $w.top.list -yscrollcommand [list $w.top.scroll set] \
1039 scrollbar $w.top.scroll -orient vertical -border 1
1040 pack $w.top.list -side left -fill both -expand yes
1041 pack $w.top.scroll -side right -fill y
1042 $w.top.scroll config -command [list $w.top.list yview]
1044 listbox $w.top.list -font fixed -geometry 60x14
1045 pack $w.top.list -side left -fill both -expand yes
1048 bottom-buttons $w [list {Close} [list destroy $w] \
1049 {Up} [list scan-up $attr] \
1050 {Down} [list scan-down $attr]] 0
1051 bind $w.top.list <Up> [list scan-up $attr]
1052 bind $w.top.list <Down> [list scan-down $attr]
1054 bind $w.top.list <Double-Button-1> [list scan-copy %y $curIndexEntry]
1055 wm title $w "Scan $title"
1057 z39 callback [list scan-response $attr 0 35]
1058 z39.scan numberOfTermsRequested 5
1059 z39.scan preferredPositionInResponse 1
1060 z39.scan scan "${attr} 0"
1062 show-status {Scanning} 1 0
1065 proc scan-term-h {attr} {
1073 set nScanTerm [$w.top.entry get]
1074 if {$nScanTerm == $scanTerm} {
1077 set scanTerm $nScanTerm
1078 z39 callback [list scan-response $attr 0 35]
1079 z39.scan numberOfTermsRequested 5
1080 z39.scan preferredPositionInResponse 1
1081 dputs "${attr} \{${scanTerm}\}"
1082 if {$scanTerm == ""} {
1083 z39.scan scan "${attr} 0"
1085 z39.scan scan "${attr} \{${scanTerm}\}"
1087 show-status {Scanning} 1 0
1090 proc scan-response {attr start toget} {
1097 dputs "In scan-response"
1098 set m [z39.scan numberOfEntriesReturned]
1104 if {![winfo exists .scan-window]} {
1107 dputs "Handling cancel"
1108 if {$delayRequest != ""} {
1113 show-status {Ready} 0 1
1116 set nScanTerm [$w.top.entry get]
1117 if {$nScanTerm != $scanTerm} {
1118 z39 callback [list scan-response $attr 0 35]
1119 z39.scan numberOfTermsRequested 5
1120 z39.scan preferredPositionInResponse 1
1121 set scanTerm $nScanTerm
1122 dputs "${attr} \{${scanTerm}\}"
1123 if {$scanTerm == ""} {
1124 z39.scan scan "${attr} 0"
1126 z39.scan scan "${attr} \{${scanTerm}\}"
1128 show-status {Scanning} 1 0
1131 set status [z39.scan scanStatus]
1134 show-status {Ready} 0 1
1139 for {set i 0} {$i < $m} {incr i} {
1140 set term [lindex [z39.scan scanLine $i] 1]
1141 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1142 $w.top.list insert $i "$nostr $term"
1145 $w.top.list yview $scanView
1147 $w.top.list delete $start end
1148 for {set i 0} {$i < $m} {incr i} {
1149 set term [lindex [z39.scan scanLine $i] 1]
1150 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1151 $w.top.list insert end "$nostr $term"
1155 dputs "Handling cancel"
1157 if {$delayRequest != ""} {
1163 if {$toget > 0 && $m > 1 && $m < $toget} {
1164 set ntoget [expr $toget - $m + 1]
1165 dputs ntoget=$ntoget
1166 z39 callback [list scan-response $attr [expr $start + $m - 1] $ntoget]
1168 dputs "down continue: $q"
1170 z39.scan numberOfTermsRequested 10
1172 z39.scan numberOfTermsRequested $ntoget
1174 z39.scan preferredPositionInResponse 1
1175 dputs "${attr} \{$q\}"
1176 z39.scan scan "${attr} \{$q\}"
1179 if {$toget < 0 && $m > 1 && $m < [expr - $toget]} {
1180 set ntoget [expr - $toget - $m]
1181 dputs ntoget=$ntoget
1182 z39 callback [list scan-response $attr 0 -$ntoget]
1183 set q [string range [$w.top.list get 0] 8 end]
1184 dputs "up continue: $q"
1186 z39.scan numberOfTermsRequested 10
1187 z39.scan preferredPositionInResponse 11
1189 z39.scan numberOfTermsRequested $ntoget
1190 z39.scan preferredPositionInResponse [incr ntoget]
1192 dputs "${attr} \{$q\}"
1193 z39.scan scan "${attr} \{$q\}"
1196 show-status {Ready} 0 1
1199 proc scan-down {attr} {
1207 show-status {Scanning down} 1 0
1208 set delayRequest [list scan-down $attr]
1214 set scanView [expr $scanView + 5]
1215 set s [$w.top.list size]
1216 if {$scanView > $s} {
1217 z39 callback [list scan-response $attr [expr $s - 1] 25]
1218 set q [string range [$w.top.list get [expr $s - 1]] 8 end]
1220 z39.scan numberOfTermsRequested 10
1221 z39.scan preferredPositionInResponse 1
1222 show-status {Scanning} 1 0
1223 dputs "${attr} \{$q\}"
1224 z39.scan scan "${attr} \{$q\}"
1227 $w.top.list yview $scanView
1230 proc scan-up {attr} {
1238 show-status {Scanning up} 1 0
1239 set delayRequest [list scan-up $attr]
1245 set scanView [expr $scanView - 5]
1246 if {$scanView < 0} {
1247 z39 callback [list scan-response $attr 0 -25]
1248 set q [string range [$w.top.list get 0] 8 end]
1250 z39.scan numberOfTermsRequested 10
1251 z39.scan preferredPositionInResponse 11
1252 show-status {Scanning} 1 0
1253 z39.scan scan "${attr} \{$q\}"
1256 $w.top.list yview $scanView
1259 proc search-response {} {
1267 dputs "In search-response"
1269 dputs "Handling cancel"
1271 if {$delayRequest != ""} {
1278 set setMax [z39.$setNo resultCount]
1279 show-message "${setMax} hits"
1280 set l [format "%-4d %7d" $setNo $setMax]
1281 .top.rset.m add command -label $l \
1282 -command [list add-title-lines $setNo 10000 1]
1284 show-status {Ready} 0 1
1285 set status [z39.$setNo responseStatus]
1286 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"
1298 show-status {Ready} 0 1
1299 z39 callback {present-response}
1300 z39.$setNo present $setOffset 1
1301 show-status {Retrieving} 1 0
1304 proc present-more {number} {
1312 dputs "present-more"
1314 show-status {Retrieving} 1 0
1315 set delayRequest "present-more $number"
1321 dputs "setNo=$setNo"
1324 set max [z39.$setNo resultCount]
1325 if {$max <= $setOffset} {
1327 dputs "setOffset=$setOffset"
1330 if {$number == ""} {
1334 if {$setMax > $max} {
1338 z39 callback {present-response}
1340 set toGet [expr $setMax - $setOffset + 1]
1347 z39.$setNo present $setOffset $toGet
1348 show-status {Retrieving} 1 0
1351 proc init-title-lines {} {
1352 .data.record delete 0.0 end
1355 proc title-press {y setno} {
1356 show-full-marc $setno [expr 1 + [.data.list nearest $y]] 0
1359 proc add-title-lines {setno no offset} {
1360 global displayFormats
1361 global displayFormat
1365 set setno $lastSetNo
1367 set lastSetNo $setno
1370 .bot.a.set configure -text $setno
1371 .data.record delete 0.0 end
1373 set ffunc [lindex $displayFormats $displayFormat]
1374 dputs "ffunc=$ffunc"
1375 set ffunc "display-$ffunc"
1376 for {set i 0} {$i < $no} {incr i} {
1377 set o [expr $i + $offset]
1378 set type [z39.$setno type $o]
1382 .data.record tag bind r$o <Any-Enter> {}
1383 .data.record tag bind r$o <Any-Leave> {}
1384 set insert0 [.data.record index insert]
1385 $ffunc $setno $o .data.record 1
1386 .data.record tag add r$o $insert0 insert
1387 .data.record tag bind r$o <1> \
1388 [list popup-marc $setno $o 0 0]
1393 proc present-response {} {
1400 dputs "In present-response"
1401 set no [z39.$setNo numberOfRecordsReturned]
1402 dputs "Returned $no records, setOffset $setOffset"
1403 add-title-lines $setNo $no $setOffset
1404 set setOffset [expr $setOffset + $no]
1406 dputs "Handling cancel"
1408 if {$delayRequest != ""} {
1413 set status [z39.$setNo responseStatus]
1414 if {[lindex $status 0] == "NSD"} {
1415 show-status {Ready} 0 1
1416 set code [lindex $status 1]
1417 set msg [lindex $status 2]
1418 set addinfo [lindex $status 3]
1419 tkerror "NSD$code: $msg: $addinfo"
1422 if {$no > 0 && $setOffset <= $setMax} {
1423 dputs "present-request from ${setOffset}"
1424 set toGet [expr $setMax - $setOffset + 1]
1428 z39.$setNo present $setOffset $toGet
1430 show-status {Ready} 0 1
1434 proc left-cursor {w} {
1435 set i [$w index insert]
1442 proc right-cursor {w} {
1443 set i [$w index insert]
1448 proc bind-fields {list returnAction escapeAction} {
1449 set max [expr [llength $list]-1]
1450 for {set i 0} {$i < $max} {incr i} {
1451 bind [lindex $list $i] <Return> $returnAction
1452 bind [lindex $list $i] <Escape> $escapeAction
1453 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
1454 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1455 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1457 bind [lindex $list $i] <Return> $returnAction
1458 bind [lindex $list $i] <Escape> $escapeAction
1459 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
1460 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1461 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1462 focus [lindex $list 0]
1465 proc entry-fields {parent list tlist returnAction escapeAction} {
1468 foreach field $list {
1469 set label ${parent}.${field}.label
1470 set entry ${parent}.${field}.entry
1471 label $label -text [lindex $tlist $i] -anchor e
1472 entry $entry -width 32 -relief sunken
1473 pack $label -side left
1474 pack $entry -side right
1475 lappend alist $entry
1478 bind-fields $alist $returnAction $escapeAction
1481 proc define-target-dialog {} {
1482 set w .target-define
1488 pack $w.top.target \
1489 -side top -anchor e -pady 2
1490 entry-fields $w.top {target} \
1492 {define-target-action} {destroy .target-define}
1493 top-down-ok-cancel $w {define-target-action} 1
1496 proc protocol-setup-delete {target} {
1498 global settingsChanged
1500 set a [alert "Are you sure you want to delete the target \
1501 definition $target ?"]
1503 set wno [lindex $profile($target) 12]
1506 unset profile($target)
1507 set settingsChanged 1
1512 proc protocol-setup-action {target} {
1515 global protocolRadioType
1516 global settingsChanged
1519 global ResultSetCheck
1521 set wno [lindex $profile($target) 12]
1525 set settingsChanged 1
1526 set len [$w.top.databases.list size]
1527 for {set i 0} {$i < $len} {incr i} {
1528 lappend b [$w.top.databases.list get $i]
1530 set profile($target) [list [$w.top.description.entry get] \
1531 [$w.top.host.entry get] \
1532 [$w.top.port.entry get] \
1533 [$w.top.idAuthentication.entry get] \
1534 [$w.top.maximumRecordSize.entry get] \
1535 [$w.top.preferredMessageSize.entry get] \
1541 $protocolRadioType \
1545 dputs $profile($target)
1549 proc place-force {window parent} {
1550 set g [wm geometry $parent]
1552 set p1 [string first + $g]
1553 set p2 [string last + $g]
1555 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
1556 set y [expr 60+[string range $g [expr $p2 +1] end]]
1557 wm geometry $window +${x}+${y}
1560 proc add-database-action {target} {
1563 set wno [lindex $profile($target) 12]
1566 $w.top.databases.list insert end \
1567 [.database-select.top.database.entry get]
1568 destroy .database-select
1571 proc add-database {target} {
1574 set w .database-select
1576 set oldFocus [focus]
1579 set wno [lindex $profile($target) 12]
1580 place-force $w .setup-${wno}
1584 frame $w.top.database
1586 pack $w.top.database -side top -anchor e -pady 2
1588 entry-fields $w.top {database} \
1589 {{Database to add:}} \
1590 [list add-database-action $target] {destroy .database-select}
1592 top-down-ok-cancel $w [list add-database-action $target] 1
1596 proc delete-database {target} {
1599 set wno [lindex $profile($target) 12]
1602 foreach i [$w.top.databases.list curselection] {
1603 set b [$w.top.databases.list get $i]
1606 set a [alert "Are you sure you want to remove the database(s)${l}?"]
1608 foreach i [lsort -decreasing \
1609 [$w.top.databases.list curselection]] {
1610 $w.top.databases.list delete $i
1615 proc protocol-setup {target} {
1618 global protocolRadioType
1621 global ResultSetCheck
1623 set wno [lindex $profile($target) 12]
1628 wm title $w "Setup $target"
1632 if {$target == ""} {
1636 dputs $profile($target)
1640 frame $w.top.description
1641 frame $w.top.idAuthentication
1642 frame $w.top.maximumRecordSize
1643 frame $w.top.preferredMessageSize
1644 frame $w.top.cs-type -relief ridge -border 2
1645 frame $w.top.protocol -relief ridge -border 2
1646 frame $w.top.query -relief ridge -border 2
1647 frame $w.top.databases -relief ridge -border 2
1649 # Maximum/preferred/idAuth ...
1650 pack $w.top.description $w.top.host $w.top.port \
1651 $w.top.idAuthentication $w.top.maximumRecordSize \
1652 $w.top.preferredMessageSize -side top -anchor e -pady 2
1654 entry-fields $w.top {description host port idAuthentication \
1655 maximumRecordSize preferredMessageSize} \
1656 {{Description:} {Host:} {Port:} {Id Authentication:} \
1657 {Maximum Record Size:} {Preferred Message Size:}} \
1658 [list protocol-setup-action $target] [list destroy $w]
1660 foreach sub {description host port idAuthentication \
1661 maximumRecordSize preferredMessageSize} {
1663 bind $w.top.$sub.entry <Control-a> [list add-database $target]
1664 bind $w.top.$sub.entry <Control-d> [list delete-database $target]
1666 $w.top.description.entry insert 0 [lindex $profile($target) 0]
1667 $w.top.host.entry insert 0 [lindex $profile($target) 1]
1668 $w.top.port.entry insert 0 [lindex $profile($target) 2]
1669 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
1670 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
1671 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
1672 set csRadioType [lindex $profile($target) 6]
1673 set RPNCheck [lindex $profile($target) 8]
1674 set CCLCheck [lindex $profile($target) 9]
1675 set ResultSetCheck [lindex $profile($target) 10]
1676 set protocolRadioType [lindex $profile($target) 11]
1677 if {$protocolRadioType == ""} {
1678 set protocolRadioType Z39
1682 pack $w.top.databases -side left -pady 4 -padx 4 -expand yes -fill both
1684 label $w.top.databases.label -text "Databases"
1685 button $w.top.databases.add -text "Add" \
1686 -command [list add-database $target]
1687 button $w.top.databases.delete -text "Delete" \
1688 -command [list delete-database $target]
1689 listbox $w.top.databases.list -geometry 20x6 \
1690 -yscrollcommand "$w.top.databases.scroll set"
1691 scrollbar $w.top.databases.scroll -orient vertical -border 1
1692 pack $w.top.databases.label -side top -fill x \
1694 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
1696 pack $w.top.databases.list -side left -fill both -expand yes \
1698 pack $w.top.databases.scroll -side right -fill y \
1700 $w.top.databases.scroll config -command "$w.top.databases.list yview"
1702 foreach b [lindex $profile($target) 7] {
1703 $w.top.databases.list insert end $b
1707 pack $w.top.cs-type -pady 4 -padx 4 -side top -fill x
1709 label $w.top.cs-type.label -text "Transport"
1710 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" -anchor w \
1711 -variable csRadioType -value tcpip
1712 radiobutton $w.top.cs-type.mosi -text "MOSI" -anchor w\
1713 -variable csRadioType -value mosi
1715 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
1716 -padx 4 -side top -fill x
1719 pack $w.top.protocol -pady 4 -padx 4 -side top -fill x
1721 label $w.top.protocol.label -text "Protocol"
1722 radiobutton $w.top.protocol.z39v2 -text "Z39.50" -anchor w \
1723 -variable protocolRadioType -value Z39
1724 radiobutton $w.top.protocol.sr -text "SR" -anchor w \
1725 -variable protocolRadioType -value SR
1727 pack $w.top.protocol.label $w.top.protocol.z39v2 $w.top.protocol.sr \
1728 -padx 4 -side top -fill x
1731 pack $w.top.query -pady 4 -padx 4 -side top -fill x
1733 label $w.top.query.label -text "Query support"
1734 checkbutton $w.top.query.c1 -text "RPN query" -anchor w -variable RPNCheck
1735 checkbutton $w.top.query.c2 -text "CCL query" -anchor w -variable CCLCheck
1736 checkbutton $w.top.query.c3 -text "Result sets" -anchor w -variable ResultSetCheck
1738 pack $w.top.query.label -side top
1739 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
1740 -padx 4 -side top -fill x
1743 bottom-buttons $w [list {Ok} [list protocol-setup-action $target] \
1744 {Delete} [list protocol-setup-delete $target] \
1745 {Cancel} [list destroy $w]] 0
1748 proc database-select-action {} {
1749 set w .database-select.top
1751 foreach indx [$w.databases.list curselection] {
1752 lappend b [$w.databases.list get $indx]
1755 z39 databaseNames $b
1757 destroy .database-select
1760 proc database-select {} {
1761 set w .database-select
1771 frame $w.top.databases -relief ridge -border 2
1773 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
1775 label $w.top.databases.label -text "List"
1776 listbox $w.top.databases.list -geometry 20x6 \
1777 -yscrollcommand "$w.top.databases.scroll set"
1778 scrollbar $w.top.databases.scroll -orient vertical -border 1
1779 pack $w.top.databases.label -side top -fill x \
1781 pack $w.top.databases.list -side left -fill both -expand yes \
1783 pack $w.top.databases.scroll -side right -fill y \
1785 $w.top.databases.scroll config -command "$w.top.databases.list yview"
1787 foreach b [lindex $profile($hostid) 7] {
1788 $w.top.databases.list insert end $b
1790 top-down-ok-cancel $w {database-select-action} 1
1793 proc cascade-target-list {} {
1796 foreach sub [winfo children .top.target.m.clist] {
1799 .top.target.m.clist delete 0 last
1800 foreach n [array names profile] {
1801 if {$n != "Default"} {
1802 set nl [lindex $profile($n) 12]
1803 if {[llength [lindex $profile($n) 7]] > 1} {
1804 .top.target.m.clist add cascade -label $n \
1805 -menu .top.target.m.clist.$nl
1806 menu .top.target.m.clist.$nl
1807 foreach b [lindex $profile($n) 7] {
1808 .top.target.m.clist.$nl add command -label $b \
1809 -command [list reopen-target $n $b]
1812 .top.target.m.clist add command -label $n \
1813 -command [list reopen-target $n {}]
1817 .top.target.m.slist delete 0 last
1818 foreach n [array names profile] {
1819 if {$n != "Default"} {
1820 .top.target.m.slist add command -label $n \
1821 -command [list protocol-setup $n]
1826 proc query-select {i} {
1827 global queryButtonsFind
1828 global queryInfoFind
1832 set queryInfoFind [lindex $queryInfo $i]
1833 set queryButtonsFind [lindex $queryButtons $i]
1835 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
1838 proc query-new-action {} {
1842 global settingsChanged
1844 set settingsChanged 1
1845 lappend queryTypes [.query-new.top.index.entry get]
1846 lappend queryButtons {}
1847 lappend queryInfo {}
1861 -side top -anchor e -pady 2
1862 entry-fields $w.top index \
1864 query-new-action {destroy .query-new}
1865 top-down-ok-cancel $w query-new-action 1
1868 proc query-delete-action {queryNo} {
1872 global settingsChanged
1874 set settingsChanged 1
1876 set queryTypes [lreplace $queryTypes $queryNo $queryNo]
1877 set queryButtons [lreplace $queryButtons $queryNo $queryNo]
1878 set queryInfo [lreplace $queryInfo $queryNo $queryNo]
1879 destroy .query-delete
1883 proc query-delete {queryNo} {
1891 set n [lindex $queryTypes $queryNo]
1893 label $w.top.warning -bitmap warning
1894 message $w.top.quest -text "Are you sure you want to delete the \
1895 query type $n ?" -aspect 200
1896 pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
1897 bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
1898 {Cancel} [list destroy $w]] 1
1901 proc cascade-query-list {} {
1903 set w .top.options.m.query
1906 $w.slist delete 0 last
1907 foreach n $queryTypes {
1908 $w.slist add command -label $n -command [list query-setup $i]
1913 $w.clist delete 0 last
1914 foreach n $queryTypes {
1915 $w.clist add command -label $n -command [list query-select $i]
1919 $w.dlist delete 0 last
1920 foreach n $queryTypes {
1921 $w.dlist add command -label $n -command [list query-delete $i]
1926 proc save-geometry {} {
1927 global windowGeometry
1930 global displayFormat
1934 set windowGeometry(.) [wm geometry .]
1936 set f [open "~/.clientrc.tcl" w]
1938 puts $f "set hotTargets \{ $hotTargets \}"
1939 puts $f "set textWrap $textWrap"
1940 puts $f "set displayFormat $displayFormat"
1941 puts $f "set popupMarcdf $popupMarcdf"
1942 puts $f "set recordSyntax $recordSyntax"
1943 foreach n [array names windowGeometry] {
1944 puts -nonewline $f "set \{windowGeometry($n)\} \{"
1945 puts -nonewline $f $windowGeometry($n)
1951 proc save-settings {} {
1954 global settingsChanged
1959 if {![file writable "${libdir}/clientrc.tcl"]} {
1962 set f [open "${libdir}/clientrc.tcl" w]
1963 puts $f "# Setup file"
1965 foreach n [array names profile] {
1966 puts -nonewline $f "set \{profile($n)\} \{"
1967 puts -nonewline $f $profile($n)
1970 puts -nonewline $f "set queryTypes \{"
1971 puts -nonewline $f $queryTypes
1974 puts -nonewline $f "set queryButtons \{"
1975 puts -nonewline $f $queryButtons
1978 puts -nonewline $f "set queryInfo \{"
1979 puts -nonewline $f $queryInfo
1982 set settingsChanged 0
1994 label $w.top.warning -bitmap warning
1995 message $w.top.message -text $ask -aspect 200 \
1996 -font -Adobe-Times-Medium-R-Normal-*-180-*
1998 pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
2001 top-down-ok-cancel $w {alert-action} 1
2005 proc alert-action {} {
2011 proc exit-action {} {
2012 global settingsChanged
2014 if {$settingsChanged} {
2015 set a [alert "you haven't saved your settings. Do you wish to save?"]
2024 proc listbuttonaction {w name h user i} {
2025 $w configure -text [lindex $name 0]
2026 $h [lindex $name 1] $user $i
2029 proc listbuttonx {button no names handle user} {
2030 if {[winfo exists $button]} {
2031 $button configure -text [lindex [lindex $names $no] 0]
2032 ${button}.m delete 0 last
2034 menubutton $button -text [lindex [lindex $names $no] 0] \
2035 -width 10 -menu ${button}.m -relief raised -border 1
2039 foreach name $names {
2040 ${button}.m add command -label [lindex $name 0] \
2041 -command [list listbuttonaction ${button} $name \
2047 proc listbutton {button no names} {
2048 menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
2049 -relief raised -border 1
2051 foreach name $names {
2052 ${button}.m add command -label $name \
2053 -command [list ${button} configure -text $name]
2057 proc listbuttonv-action {button var names i} {
2060 set $var [lindex $names [expr $i+1]]
2061 $button configure -text [lindex $names $i]
2064 proc listbuttonv {button var names} {
2068 eval "set val $$var"
2069 set l [llength $names]
2070 for {set i 1} {$i < $l} {incr i 2} {
2071 if {$val == [lindex $names $i]} {
2073 set n [lindex $names $i]
2077 if {[winfo exists $button]} {
2078 $button configure -text $n
2081 menubutton $button -text $n -menu ${button}.m \
2082 -relief raised -border 1
2084 for {set i 0} {$i < $l} {incr i 2} {
2085 ${button}.m add command -label [lindex $names $i] \
2086 -command [list listbuttonv-action $button $var $names $i]
2090 proc query-add-index-action {queryNo} {
2094 global queryButtonsTmp
2096 set newI [.query-add-index.top.index.entry get]
2097 lappend queryInfoTmp [list $newI {}]
2098 $w.top.index.list insert end $newI
2099 destroy .query-add-index
2100 #destroy $w.top.lines
2101 #frame $w.top.lines -relief ridge -border 2
2102 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2103 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2106 proc query-add-line {queryNo} {
2110 global queryButtonsTmp
2112 lappend queryButtonsTmp {I 0}
2114 #destroy $w.top.lines
2115 #frame $w.top.lines -relief ridge -border 2
2116 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2117 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2120 proc query-del-line {queryNo} {
2124 global queryButtonsTmp
2126 set l [llength $queryButtonsTmp]
2131 set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
2132 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2135 proc query-add-index {queryNo} {
2136 set w .query-add-index
2139 place-force $w .query-setup
2143 -side top -anchor e -pady 2
2144 entry-fields $w.top {index} \
2146 [list query-add-index-action $queryNo] [list destroy $w]
2147 top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
2150 proc query-setup-action {queryNo} {
2153 global queryButtonsTmp
2155 global queryButtonsFind
2156 global queryInfoFind
2158 global settingsChanged
2160 set settingsChanged 1
2162 set queryInfo [lreplace $queryInfo $queryNo $queryNo \
2164 set queryButtons [lreplace $queryButtons $queryNo $queryNo \
2166 set queryInfoFind $queryInfoTmp
2167 set queryButtonsFind $queryButtonsTmp
2169 destroy .query-setup
2170 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2173 proc activate-e-index {value no i} {
2174 global queryButtonsTmp
2175 global queryIndexTmp
2177 set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
2178 dputs $queryButtonsTmp
2179 set queryIndexTmp $i
2182 proc activate-index {value no i} {
2183 global queryButtonsFind
2185 set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
2187 dputs "queryButtonsFind $queryButtonsFind"
2190 proc update-attr {} {
2192 listbuttonv $w.top.relation.b relationTmpValue\
2193 {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
2194 {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
2195 {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
2196 listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
2197 {First in field} 1 {First in subfield} 2 {Any position in field} 3}
2198 listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
2199 {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list} 6 \
2200 {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
2201 {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
2202 {local-number} 107 {string} 108 {numeric string} 109}
2203 listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
2204 {Left} 2 {Left and right} 3 {No truncation} 100 \
2205 {Process #} 101 {Re-1} 102 {Re-2} 103}
2206 listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
2207 {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
2210 proc use-attr {init} {
2222 {BNB card number} 10
2223 {BGF(sic) number} 11
2225 {Dewey classification} 13
2226 {UDC classification} 14
2227 {Bliss classification} 15
2229 {NLM call number} 17
2230 {NAL call number} 18
2231 {MOS call number} 19
2232 {Local classification} 20
2233 {Subject heading} 21
2235 {BDI-index-subject} 23
2239 {LC-subject-heading} 27
2240 {RVM-subject-heading} 28
2241 {Local subject index} 29
2243 {Date of publication} 31
2244 {Date of acquisition} 32
2246 {Title-collective} 34
2249 {Title-added-title-page} 37
2253 {Title-other-variant} 41
2255 {Title-abbreviated} 43
2259 {Subject-subdivision} 47
2260 {Number-natl-bibliography} 48
2261 {Number-legal-deposit} 49
2262 {Number-govt-publication} 50
2263 {Number-publisher-for-music} 51
2265 {Number-local-call} 53
2267 {Code-geographic-area} 55
2268 {Code-institution} 56
2270 {Name-geographic} 58
2271 {Place-publication} 59
2273 {Microform-generation} 61
2280 {Author-name-personal} 1004
2281 {Author-name-corporate} 1005
2282 {Author-name-conference} 1006
2283 {Identifier-standard} 1007
2284 {Subject-LC-children's} 1008
2285 {Subject-name-personal} 1009
2287 {Date/time added to database} 1011
2288 {Date/time last modified} 1012
2289 {Authority/format identifier} 1013
2291 {Concept-reference} 1015
2293 {Server choice} 1017
2295 {Record source} 1019
2298 {Geographic class} 1022
2302 {Related periodical} 1026
2303 {Report number} 1027
2305 {Thematic number} 1030
2306 {Material type} 1031
2314 set l [llength $attr]
2319 for {set i 0} {$i < $l} {incr i} {
2320 $w.top.use.list insert end [lindex $attr $i]
2322 if {$useTmpValue == [lindex $attr $i]} {
2327 $w.top.use.list select from $s
2328 $w.top.use.list select to $s
2333 $w.top.use.list yview $s
2335 set lno [lindex [$w.top.use.list curselection] 0]
2336 set i [expr $lno+$lno+1]
2337 set useTmpValue [lindex $attr $i]
2338 dputs "useTmpValue=$useTmpValue"
2342 proc index-setup-action {oldAttr queryNo indexNo} {
2343 set attr [lindex $oldAttr 0]
2346 global relationTmpValue
2347 global structureTmpValue
2348 global truncationTmpValue
2349 global completenessTmpValue
2350 global positionTmpValue
2355 dputs "index-setup-action"
2356 dputs "queryNo $queryNo"
2357 dputs "indexNo $indexNo"
2358 if {$useTmpValue > 0} {
2359 lappend attr "1=$useTmpValue"
2361 if {$relationTmpValue > 0} {
2362 lappend attr "2=$relationTmpValue"
2364 if {$positionTmpValue > 0} {
2365 lappend attr "3=$positionTmpValue"
2367 if {$structureTmpValue > 0} {
2368 lappend attr "4=$structureTmpValue"
2370 if {$truncationTmpValue > 0} {
2371 lappend attr "5=$truncationTmpValue"
2373 if {$completenessTmpValue > 0} {
2374 lappend attr "6=$completenessTmpValue"
2376 dputs "new attr $attr"
2377 set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
2378 destroy .index-setup
2381 proc index-setup {attr queryNo indexNo} {
2384 global relationTmpValue
2385 global structureTmpValue
2386 global truncationTmpValue
2387 global completenessTmpValue
2388 global positionTmpValue
2390 set relationTmpValue 0
2391 set truncationTmpValue 0
2392 set structureTmpValue 0
2393 set positionTmpValue 0
2394 set completenessTmpValue 0
2397 set len [llength $attr]
2398 for {set i 1} {$i < $len} {incr i} {
2399 set q [lindex $attr $i]
2400 set l [string first = $q]
2402 set t [string range $q 0 [expr $l - 1]]
2403 set v [string range $q [expr $l + 1] end]
2406 { set useTmpValue $v }
2408 { set relationTmpValue $v }
2410 { set positionTmpValue $v }
2412 { set structureTmpValue $v }
2414 { set truncationTmpValue $v }
2416 { set completenessTmpValue $v }
2420 if {[winfo exists $w]} {
2425 set n [lindex $attr 0]
2426 wm title $w "Index setup $n"
2430 frame $w.top.use -relief ridge -border 2
2431 frame $w.top.relation -relief ridge -border 2
2432 frame $w.top.position -relief ridge -border 2
2433 frame $w.top.structure -relief ridge -border 2
2434 frame $w.top.truncation -relief ridge -border 2
2435 frame $w.top.completeness -relief ridge -border 2
2441 pack $w.top.use -side left -pady 6 -padx 6 -fill y
2443 label $w.top.use.label -text "Use"
2444 listbox $w.top.use.list -geometry 26x10 \
2445 -yscrollcommand "$w.top.use.scroll set"
2446 scrollbar $w.top.use.scroll -orient vertical -border 1
2447 pack $w.top.use.label -side top -fill x \
2449 pack $w.top.use.list -side left -fill both -expand yes \
2451 pack $w.top.use.scroll -side right -fill y \
2453 $w.top.use.scroll config -command "$w.top.use.list yview"
2457 # Relation Attributes
2459 pack $w.top.relation -pady 6 -padx 6 -side top
2460 label $w.top.relation.label -text "Relation" -width 18
2462 pack $w.top.relation.label $w.top.relation.b -fill x
2464 # Position Attributes
2466 pack $w.top.position -pady 6 -padx 6 -side top
2467 label $w.top.position.label -text "Position" -width 18
2469 pack $w.top.position.label $w.top.position.b -fill x
2471 # Structure Attributes
2473 pack $w.top.structure -pady 6 -padx 6 -side top
2474 label $w.top.structure.label -text "Structure" -width 18
2476 pack $w.top.structure.label $w.top.structure.b -fill x
2478 # Truncation Attributes
2480 pack $w.top.truncation -pady 6 -padx 6 -side top
2481 label $w.top.truncation.label -text "Truncation" -width 18
2483 pack $w.top.truncation.label $w.top.truncation.b -fill x
2485 # Completeness Attributes
2487 pack $w.top.completeness -pady 6 -padx 6 -side top
2488 label $w.top.completeness.label -text "Completeness" -width 18
2490 pack $w.top.completeness.label $w.top.completeness.b -fill x
2493 bottom-buttons $w [list \
2494 {Ok} [list index-setup-action $attr $queryNo $indexNo] \
2495 {Cancel} [list destroy $w]] 0
2499 proc query-edit-index {queryNo} {
2503 set i [lindex [$w.top.index.list curselection] 0]
2507 set attr [lindex $queryInfoTmp $i]
2508 dputs "Editing no $i $attr"
2509 index-setup $attr $queryNo $i
2512 proc query-delete-index {queryNo} {
2514 global queryButtonsTmp
2517 set i [lindex [$w.top.index.list curselection] 0]
2521 set queryInfoTmp [lreplace $queryInfoTmp $i $i]
2522 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2523 $w.top.index.list delete $i
2526 proc query-setup {queryNo} {
2532 global queryButtonsTmp
2534 global queryIndexTmp
2537 set queryName [lindex $queryTypes $queryNo]
2538 set queryInfoTmp [lindex $queryInfo $queryNo]
2539 set queryButtonsTmp [lindex $queryButtons $queryNo]
2544 wm title $w "Query setup $queryName"
2548 frame $w.top.lines -relief ridge -border 2
2550 pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2554 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2556 button $w.top.lines.add -text "Add" \
2557 -command [list query-add-line $queryNo]
2558 button $w.top.lines.del -text "Remove" \
2559 -command [list query-del-line $queryNo]
2561 pack $w.top.lines.del -fill x -side bottom
2562 pack $w.top.lines.add -fill x -pady 10 -side bottom
2566 frame $w.top.index -relief ridge -border 2
2567 pack $w.top.index -pady 6 -padx 6 -side right -fill y
2569 listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
2570 scrollbar $w.top.index.scroll -orient vertical -border 1 \
2571 -command [list $w.top.index.list yview]
2572 bind $w.top.index.list <2> [list query-edit-index $queryNo]
2574 pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
2575 pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
2577 $w.top.index.list select from 0
2578 $w.top.index.list select to 0
2580 foreach x $queryInfoTmp {
2581 $w.top.index.list insert end [lindex $x 0]
2584 bottom-buttons $w [list \
2585 {Ok} [list query-setup-action $queryNo] \
2586 {Add index} [list query-add-index $queryNo] \
2587 {Edit index} [list query-edit-index $queryNo] \
2588 {Delete index} [list query-delete-index $queryNo] \
2589 {Cancel} [list destroy $w]] 0
2592 proc index-clear {} {
2593 global queryButtonsFind
2596 foreach b $queryButtonsFind {
2597 .lines.$i.e delete 0 end
2602 proc index-query {} {
2603 global queryButtonsFind
2604 global queryInfoFind
2609 foreach b $queryButtonsFind {
2610 set term [string trim [.lines.$i.e get]]
2612 set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
2614 set len [string length $term]
2618 if {[string index $term $len] == "?"} {
2620 set term [string range $term 0 [expr $len - 1]]
2622 if {[string index $term 0] == "?"} {
2624 set term [string range $term 1 end]
2626 set term "\{${term}\}"
2627 if {$right && $left} {
2628 set term "@attr 5=3 ${term}"
2630 set term "@attr 5=1 ${term}"
2632 set term "@attr 5=2 ${term}"
2635 set term "@attr $a ${term}"
2638 set qs "@and ${qs} ${term}"
2649 proc index-focus-in {w i} {
2650 global curIndexEntry
2652 $w.$i configure -background red
2653 set curIndexEntry $i
2656 proc index-lines {w realOp buttonInfo queryInfo handle} {
2658 foreach b $buttonInfo {
2659 if {! [winfo exists $w.$i]} {
2660 frame $w.$i -background white -border 1
2662 listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
2665 if {! [winfo exists $w.$i.e]} {
2666 entry $w.$i.e -width 32 -relief sunken -border 1
2667 bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
2668 bind $w.$i.e <FocusOut> [list $w.$i configure \
2670 pack $w.$i.l -side left
2671 pack $w.$i.e -side left -fill x -expand yes
2672 pack $w.$i -side top -fill x -padx 2 -pady 2
2673 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
2674 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
2675 bind $w.$i.e <Return> {search-request 0}
2678 pack $w.$i.l -side left
2679 pack $w.$i -side top -fill x -padx 2 -pady 2
2684 while {[winfo exists $w.$j]} {
2695 bind $w.$j.e <Tab> "focus $w.$k.e"
2699 bind $w.$i.e <Tab> "focus $w.0.e"
2704 proc search-fields {w buttondefs} {
2706 foreach buttondef $buttondefs {
2707 frame $w.$i -background white
2709 listbutton $w.$i.l 0 $buttondef
2710 entry $w.$i.e -width 32 -relief sunken
2712 pack $w.$i.l -side left
2713 pack $w.$i.e -side left -fill x -expand yes
2715 pack $w.$i -side top -fill x -padx 2 -pady 2
2717 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
2718 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
2726 bind $w.$j.e <Tab> "focus $w.$k.e \n
2727 $w.$k configure -background red \n
2728 $w.$j configure -background white"
2731 bind $w.$i.e <Tab> "focus $w.0.e \n
2732 $w.0 configure -background red \n
2733 $w.$i configure -background white"
2735 $w.0 configure -background red
2738 if {[info exists windowGeometry(.)]} {
2739 set g $windowGeometry(.)
2747 frame .top -border 1 -relief raised
2748 frame .lines -border 1 -relief raised
2749 frame .mid -border 1 -relief raised
2750 frame .data -border 1 -relief raised
2751 frame .bot -border 1 -relief raised
2752 pack .top .lines .mid -side top -fill x
2753 pack .data -side top -fill both -expand yes
2756 menubutton .top.file -text "File" -menu .top.file.m
2758 .top.file.m add command -label "Save settings" -command {save-settings}
2759 .top.file.m add separator
2760 .top.file.m add command -label "Exit" -command {exit-action}
2762 menubutton .top.target -text "Target" -menu .top.target.m
2764 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
2765 .top.target.m add command -label "Disconnect" -command {close-target}
2766 .top.target.m add command -label "About" -command {about-target}
2767 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
2768 .top.target.m add command -label "Setup new" -command {define-target-dialog}
2769 .top.target.m add separator
2772 .top.target.m disable 1
2773 .top.target.m disable 2
2775 menu .top.target.m.clist
2776 menu .top.target.m.slist
2779 menubutton .top.service -text "Service" -menu .top.service.m
2781 .top.service.m add command -label "Database" -command {database-select}
2782 .top.service.m add cascade -label "Present" -menu .top.service.m.present
2783 menu .top.service.m.present
2784 .top.service.m.present add command -label "10 More" \
2785 -command [list present-more 10]
2786 .top.service.m.present add command -label "All" \
2787 -command [list present-more {}]
2788 .top.service.m add command -label "Search" -command {search-request 0}
2789 .top.service.m add command -label "Scan" -command {scan-request}
2791 .top.service configure -state disabled
2793 menubutton .top.rset -text "Set" -menu .top.rset.m
2795 .top.rset.m add command -label "Load" -command {load-set}
2796 .top.rset.m add separator
2798 menubutton .top.options -text "Options" -menu .top.options.m
2800 .top.options.m add cascade -label "Query" -menu .top.options.m.query
2801 .top.options.m add cascade -label "Format" -menu .top.options.m.formats
2802 .top.options.m add cascade -label "Wrap" -menu .top.options.m.wrap
2803 .top.options.m add cascade -label "Syntax" -menu .top.options.m.syntax
2805 menu .top.options.m.query
2806 .top.options.m.query add cascade -label "Select" \
2807 -menu .top.options.m.query.clist
2808 .top.options.m.query add cascade -label "Edit" \
2809 -menu .top.options.m.query.slist
2810 .top.options.m.query add command -label "New" \
2811 -command {query-new}
2812 .top.options.m.query add cascade -label "Delete" \
2813 -menu .top.options.m.query.dlist
2815 menu .top.options.m.query.slist
2816 menu .top.options.m.query.clist
2817 menu .top.options.m.query.dlist
2820 menu .top.options.m.formats
2822 foreach f $displayFormats {
2823 .top.options.m.formats add radiobutton -label $f -value $i \
2824 -command [list set-display-format $i] -variable displayFormat
2828 menu .top.options.m.wrap
2829 .top.options.m.wrap add radiobutton -label "Character" \
2830 -value char -variable textWrap -command {set-wrap char}
2831 .top.options.m.wrap add radiobutton -label "Word" \
2832 -value word -variable textWrap -command {set-wrap word}
2833 .top.options.m.wrap add radiobutton -label "None" \
2834 -value none -variable textWrap -command {set-wrap none}
2836 menu .top.options.m.syntax
2837 .top.options.m.syntax add radiobutton -label "None" \
2838 -value None -variable recordSyntax
2839 .top.options.m.syntax add separator
2840 .top.options.m.syntax add radiobutton -label "USMARC" \
2841 -value USMARC -variable recordSyntax
2842 .top.options.m.syntax add radiobutton -label "UNIMARC" \
2843 -value UNIMARC -variable recordSyntax
2844 .top.options.m.syntax add radiobutton -label "UKMARC" \
2845 -value UKMARC -variable recordSyntax
2846 .top.options.m.syntax add radiobutton -label "DANMARC" \
2847 -value DANMARC -variable recordSyntax
2848 .top.options.m.syntax add radiobutton -label "FINMARC" \
2849 -value FINMARC -variable recordSyntax
2850 .top.options.m.syntax add radiobutton -label "NORMARC" \
2851 -value NORMARC -variable recordSyntax
2852 .top.options.m.syntax add radiobutton -label "PICAMARC" \
2853 -value PICAMARC -variable recordSyntax
2854 .top.options.m.syntax add separator
2855 .top.options.m.syntax add radiobutton -label "SUTRS" \
2856 -value SUTRS -variable recordSyntax
2858 menubutton .top.help -text "Help" -menu .top.help.m
2861 .top.help.m add command -label "Help on help" \
2862 -command {tkerror "Help on help not available. Sorry"}
2863 .top.help.m add command -label "About" -command {about-origin}
2865 pack .top.file .top.target .top.service .top.rset .top.options -side left
2866 pack .top.help -side right
2868 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
2870 button .mid.search -width 7 -text {Search} -command {search-request 0} \
2872 button .mid.scan -width 7 -text {Scan} \
2873 -command scan-request -state disabled
2874 button .mid.present -width 7 -text {Present} -command [list present-more 10] \
2877 button .mid.clear -width 7 -text {Clear} -command index-clear
2878 pack .mid.search .mid.scan .mid.present .mid.clear -side left \
2879 -fill y -padx 5 -pady 3
2881 text .data.record -height 2 -width 20 -wrap none \
2882 -yscrollcommand [list .data.scroll set] -wrap $textWrap
2883 scrollbar .data.scroll -command [list .data.record yview]
2884 pack .data.scroll -side right -fill y
2885 pack .data.record -expand yes -fill both
2888 if {[tk colormodel .] == "color"} {
2889 .data.record tag configure marc-tag -foreground blue
2890 .data.record tag configure marc-id -foreground red
2892 .data.record tag configure marc-tag -foreground black
2893 .data.record tag configure marc-id -foreground black
2895 .data.record tag configure marc-data -foreground black
2897 button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
2899 pack .bot.a -side left -fill x
2900 pack .bot.logo -side right -padx 2 -pady 2
2902 message .bot.a.target -text "" -aspect 1000 -border 1
2904 label .bot.a.status -text "Not connected" -width 15 -relief \
2905 sunken -anchor w -border 1
2906 label .bot.a.set -text "" -width 5 -relief \
2907 sunken -anchor w -border 1
2908 label .bot.a.message -text "" -width 15 -relief \
2909 sunken -anchor w -border 1
2911 pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
2912 pack .bot.a.status .bot.a.set .bot.a.message \
2913 -side left -padx 2 -pady 2