1 # IR toolkit for tcl/tk
3 # See the file LICENSE for details.
4 # Sebastian Hammer, Adam Dickmeiss
7 # Revision 1.52 1995-06-22 13:14:59 adam
8 # Feature: SUTRS. Setting getSutrs implemented.
9 # Work on display formats.
10 # Preferred record syntax can be set by the user.
12 # Revision 1.51 1995/06/21 11:11:00 adam
13 # Bug fix: libdir undefined in about-origin.
15 # Revision 1.50 1995/06/21 11:04:48 adam
16 # Uses GNU autoconf 2.3.
17 # Install procedure implemented.
18 # boook bitmaps moved to sub directory bitmaps.
20 # Revision 1.49 1995/06/20 14:16:42 adam
21 # More work on cancel mechanism.
23 # Revision 1.48 1995/06/20 08:07:23 adam
24 # New setting: failInfo.
25 # Working on better cancel mechanism.
27 # Revision 1.47 1995/06/19 14:05:29 adam
28 # Bug fix: asked for SUTRS.
30 # Revision 1.46 1995/06/19 13:06:06 adam
31 # New define: IR_TCL_VERSION.
33 # Revision 1.45 1995/06/19 08:08:44 adam
34 # client.tcl: hotTargets now contain both database and target name.
35 # ir-tcl.c: setting protocol edited. Errors in callbacks are logged
36 # by logf(LOG_WARN, ...) calls.
38 # Revision 1.44 1995/06/16 14:55:18 adam
41 # Revision 1.43 1995/06/16 14:41:05 adam
42 # Scan line entries can be copied to a search entry.
44 # Revision 1.42 1995/06/16 12:28:13 adam
45 # Implemented preferredRecordSyntax.
46 # Minor changes in diagnostic handling.
47 # Record list deleted when connection closes.
49 # Revision 1.41 1995/06/14 15:07:59 adam
50 # Bug fix in cascade-target-list. Uses yaz-version.h.
52 # Revision 1.40 1995/06/14 13:37:17 adam
53 # Setting recordType implemented.
54 # Setting implementationVersion implemented.
55 # Settings implementationId / implementationName edited.
57 # Revision 1.39 1995/06/14 12:16:22 adam
58 # hotTargets, textWrap and displayFormat saved in clientg.tcl.
60 # Revision 1.38 1995/06/14 07:22:45 adam
61 # Target definitions can be deleted.
62 # Listbox used in the query definition dialog.
64 # Revision 1.37 1995/06/13 14:37:59 adam
65 # Work on query setup.
66 # Better about origin/target.
67 # Better presentation formats.
69 # Revision 1.36 1995/06/13 07:42:14 adam
70 # Bindings removed from text widgets.
72 # Revision 1.35 1995/06/12 15:17:31 adam
73 # Text widget used in main window (instead of listbox) to support
74 # better presentation formats.
76 # Revision 1.34 1995/06/12 07:59:07 adam
77 # More work on geometry handling.
79 # Revision 1.33 1995/06/09 11:17:35 adam
80 # Start work on geometry management.
82 # Revision 1.32 1995/06/07 09:16:37 adam
83 # New presentation format.
85 # Revision 1.31 1995/06/06 16:31:09 adam
86 # Bug fix: target names couldn't contain blanks.
89 # Revision 1.30 1995/06/06 11:35:41 adam
90 # Work on scan. Display of old sets.
92 # Revision 1.29 1995/06/05 14:11:18 adam
93 # Bug fix in present-more.
95 # Revision 1.28 1995/06/02 14:52:13 adam
96 # Minor changes really.
98 # Revision 1.27 1995/06/02 14:29:42 adam
99 # Work on scan interface - up/down buttons.
101 # Revision 1.26 1995/06/01 16:36:46 adam
102 # About buttons. Minor bug fixes.
104 # Revision 1.25 1995/05/31 13:09:57 adam
105 # Client searches/presents may be interrupted.
106 # New moving book-logo.
108 # Revision 1.24 1995/05/31 08:36:24 adam
109 # Bug fix in client.tcl: didn't save options on clientrc.tcl.
110 # New method: referenceId. More work on scan.
112 # Revision 1.23 1995/05/29 10:33:41 adam
113 # README and rename of startup script.
115 # Revision 1.22 1995/05/26 11:44:09 adam
116 # Bugs fixed. More work on MARC utilities and queries. Test
117 # client is up-to-date again.
119 # Revision 1.21 1995/05/11 15:34:46 adam
120 # Scan request changed a bit. This version works with RLG.
122 # Revision 1.20 1995/04/21 16:31:57 adam
123 # New radiobutton: protocol (z39v2/SR).
125 # Revision 1.19 1995/04/18 16:11:50 adam
126 # First version of graphical Scan. Some work on query-by-form.
128 # Revision 1.18 1995/04/10 10:50:22 adam
129 # Result-set name defaults to suffix of ir-set name.
130 # Started working on scan. Not finished at this point.
132 # Revision 1.17 1995/03/31 09:34:57 adam
133 # Search-button disabled when there is no connection.
135 # Revision 1.16 1995/03/31 08:56:36 adam
136 # New button "Search".
138 # Revision 1.15 1995/03/28 12:45:22 adam
139 # New ir method failback: called on disconnect/protocol error.
140 # New ir set/get method: protocol: SR / Z3950.
141 # Simple popup and disconnect when failback is invoked.
143 # Revision 1.14 1995/03/22 16:07:55 adam
146 # Revision 1.13 1995/03/21 17:27:26 adam
147 # Short-hand keys in setup.
149 # Revision 1.12 1995/03/21 13:41:03 adam
150 # Comstack cs_create not used too often. Non-blocking connect.
152 # Revision 1.11 1995/03/21 10:39:06 adam
153 # Diagnostic error message displayed with tkerror.
155 # Revision 1.10 1995/03/20 15:24:06 adam
156 # Diagnostic records saved on searchResponse.
158 # Revision 1.9 1995/03/17 18:26:16 adam
159 # Non-blocking i/o used now. Database names popup as cascade items.
161 # Revision 1.8 1995/03/17 15:45:00 adam
162 # Improved target/database setup.
164 # Revision 1.7 1995/03/16 17:54:03 adam
165 # Minor changes really.
167 # Revision 1.6 1995/03/15 19:10:20 adam
168 # Database setup in protocol-setup (rather target setup).
170 # Revision 1.5 1995/03/15 13:59:23 adam
173 # Revision 1.4 1995/03/14 17:32:29 adam
174 # Presentation of full Marc record in popup window.
176 # Revision 1.3 1995/03/12 19:31:52 adam
177 # Pattern matching implemented when retrieving MARC records. More
178 # diagnostic functions.
180 # Revision 1.2 1995/03/10 18:00:15 adam
181 # Actual presentation in line-by-line format. RPN query support.
183 # Revision 1.1 1995/03/09 16:15:07 adam
184 # First presentRequest attempts. Hot-target list.
189 if {[file readable clientrc.tcl]} {
196 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {} 1 {} {} Z39}
198 set settingsChanged 0
207 set recordSyntax USMARC
210 set queryTypes {Simple}
211 set queryButtons { { {I 0} {I 1} {I 2} } }
212 set queryInfo { { {Title {1=4 4=1}} {Author {1=1}} \
213 {Subject {1=21}} {Any {1=1016}} } }
219 proc read-formats {} {
220 global displayFormats
222 set formats [glob -nocomplain ${libdir}/formats/*.tcl]
224 if {[file readable $f]} {
226 set l [string length $f]
227 set f [string range $f [string length "${libdir}/formats/"] \
229 lappend displayFormats $f
238 .data.record configure -wrap $m
245 proc set-display-format {f} {
255 .bot.a.status configure -text "Reformatting"
258 add-title-lines -1 10000 1
260 .bot.a.status configure -text "Ready"
264 proc initBindings {} {
267 bind $w <Double-1> {}
268 bind $w <Triple-1> {}
269 bind $w <B1-Motion> {}
271 bind $w <Shift-B1-Motion> {}
273 bind $w <B2-Motion> {}
274 bind $w <Any-KeyPress> {}
276 bind $w <BackSpace> {}
278 bind $w <Control-h> {}
279 bind $w <Control-d> {}
280 bind $w <Control-v> {}
283 bind $w <B1-Motion> {}
284 bind $w <Shift-B1-Motion> {}
289 proc post-menu {wbutton wmenu} {
292 $wmenu post [winfo rootx $wbutton] \
293 [expr [winfo rooty $wbutton]+[winfo height $wbutton]]
298 global windowGeometry
299 set windowGeometry($w) [wm geometry $w]
302 global windowGeometry
305 if {[info exists windowGeometry($w)]} {
306 set g $windowGeometry($w)
311 bind $w <Destroy> [list destroyGW $w]
314 if {[file readable "${libdir}/clientrc.tcl"]} {
315 source "${libdir}/clientrc.tcl"
318 if {[file readable "~/.clientrc.tcl"]} {
319 source "~/.clientrc.tcl"
322 set queryButtonsFind [lindex $queryButtons 0]
323 set queryInfoFind [lindex $queryInfo 0]
325 proc top-down-window {w} {
326 frame $w.top -relief raised -border 1
327 frame $w.bot -relief raised -border 1
329 pack $w.top -side top -fill both -expand yes
330 pack $w.bot -fill both
333 proc top-down-ok-cancel {w ok-action g} {
334 frame $w.bot.left -relief sunken -border 1
335 pack $w.bot.left -side left -expand yes -ipadx 2 -ipady 2 -padx 5 -pady 5
336 button $w.bot.left.ok -width 6 -text {Ok} \
337 -command ${ok-action}
338 pack $w.bot.left.ok -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3
339 button $w.bot.cancel -width 6 -text {Cancel} \
340 -command [list destroy $w]
341 pack $w.bot.cancel -side left -expand yes
349 proc bottom-buttons {w buttonList g} {
351 set l [llength $buttonList]
353 frame $w.bot.$i -relief sunken -border 1
354 pack $w.bot.$i -side left -expand yes -padx 5 -pady 5
355 button $w.bot.$i.ok -text [lindex $buttonList $i] \
356 -command [lindex $buttonList [expr $i+1]]
357 pack $w.bot.$i.ok -expand yes -ipadx 3 -ipady 2 -padx 3 -pady 3 -side left
361 button $w.bot.$i -text [lindex $buttonList $i] \
362 -command [lindex $buttonList [expr $i+1]]
363 pack $w.bot.$i -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3 -side left
373 proc cancel-operation {} {
381 show-status Cancel 0 1
385 proc show-target {target base} {
389 .bot.a.target configure -text ""
393 .bot.a.target configure -text "$target"
395 .bot.a.target configure -text "$target - $base"
399 proc show-logo {v1} {
408 .bot.logo configure -bitmap @${libdir}/bitmaps/book${v1}
409 after 140 [list show-logo $v1]
413 .bot.logo configure -bitmap @${libdir}/bitmaps/book1
422 proc show-status {status b sb} {
429 .bot.a.status configure -text "$status"
431 if {$busy == 0} {set busy 1}
439 .top.service configure -state normal
440 .mid.search configure -state normal
442 .mid.scan configure -state normal
445 .top.service.m disable 1
446 } elseif {$setOffset > 0 && $setOffset <= [z39.$setNo resultCount]} {
447 .top.service.m enable 1
448 .mid.present configure -state normal
450 .top.service.m disable 1
452 if {[winfo exists .scan-window]} {
453 .scan-window.bot.2 configure -state normal
454 .scan-window.bot.4 configure -state normal
457 .top.service configure -state disabled
458 .mid.search configure -state disabled
459 .mid.scan configure -state disabled
460 .mid.present configure -state disabled
462 if {[winfo exists .scan-window]} {
463 .scan-window.bot.2 configure -state disabled
464 .scan-window.bot.4 configure -state disabled
469 proc show-message {msg} {
470 .bot.a.message configure -text "$msg"
473 proc insertWithTags {w text args} {
474 set start [$w index insert]
475 $w insert insert $text
476 foreach tag [$w tag names $start] {
477 $w tag remove $tag $start insert
480 $w tag add $i $start insert
484 proc popup-license {} {
489 wm title $w "License"
495 text $w.top.t -width 80 -height 10 -wrap word \
496 -yscrollcommand [list $w.top.s set]
497 scrollbar $w.top.s -command [list $w.top.t yview]
499 pack $w.top.s -side right -fill y
500 pack $w.top.t -expand yes -fill both
502 if {[file readable "${libdir}/LICENSE"]} {
503 set f [open "${libdir}/LICENSE" r]
504 while {[gets $f buf] != -1} {
505 $w.top.t insert end $buf
506 $w.top.t insert end "\n"
510 bottom-buttons $w [list {Close} [list destroy $w]] 1
513 proc about-target {} {
514 set w .about-target-w
519 wm title $w "About target"
522 frame $w.top.a -relief ridge -border 2
523 frame $w.top.p -relief ridge -border 2
525 pack $w.top.a $w.top.p -side top -fill x
527 label $w.top.a.about -text "About"
528 label $w.top.a.irtcl -text $hostid \
529 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
530 pack $w.top.a.about $w.top.a.irtcl -side top
532 set i [z39 targetImplementationName]
533 label $w.top.p.in -text "Implementation name: $i"
534 set i [z39 targetImplementationId]
535 label $w.top.p.ii -text "Implementation id: $i"
536 set i [z39 targetImplementationVersion]
537 label $w.top.p.iv -text "Implementation version: $i"
539 label $w.top.p.op -text "Protocol options: $i"
541 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.op -side top -anchor nw
543 bottom-buttons $w [list {Close} [list destroy $w]] 1
546 proc about-origin-logo {n} {
548 set w .about-origin-w
549 if {![winfo exists $w]} {
556 $w.top.a.logo configure -bitmap @${libdir}/bitmaps/book$n
557 after 140 [list about-origin-logo $n]
560 proc about-origin {} {
561 set w .about-origin-w
564 if {[winfo exists $w]} {
569 wm title $w "About IrTcl"
573 frame $w.top.a -relief ridge -border 2
574 frame $w.top.p -relief ridge -border 2
576 pack $w.top.a $w.top.p -side top -fill x
578 label $w.top.a.irtcl -text "IrTcl" \
579 -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
580 label $w.top.a.logo -bitmap @${libdir}/bitmaps/book1
581 pack $w.top.a.irtcl $w.top.a.logo -side left -expand yes
583 set i [z39 implementationName]
584 label $w.top.p.in -text "Implementation name: $i"
585 set i [z39 implementationId]
586 label $w.top.p.ii -text "Implementation id: $i"
587 set i [z39 implementationVersion]
588 label $w.top.p.iv -text "Implementation version: $i"
590 pack $w.top.p.in $w.top.p.ii $w.top.p.iv -side top -anchor nw
593 bottom-buttons $w [list {Close} [list destroy $w] \
594 {License} [list popup-license]] 0
597 proc popup-marc {sno no b df} {
599 global displayFormats
602 if {[z39.$sno type $no] != "DB"} {
606 set w .full-marc-$fullMarcSeq
613 if {[winfo exists $w]} {
621 frame $w.top -relief raised -border 1
622 frame $w.bot -relief raised -border 1
624 pack $w.top -side top -fill both -expand yes
625 pack $w.bot -fill both
627 text $w.top.record -width 60 -height 5 -wrap word \
628 -yscrollcommand [list $w.top.s set]
629 scrollbar $w.top.s -command [list $w.top.record yview]
631 if {[tk colormodel .] == "color"} {
632 $w.top.record tag configure marc-tag -foreground blue
633 $w.top.record tag configure marc-id -foreground red
635 $w.top.record tag configure marc-tag -foreground black
636 $w.top.record tag configure marc-id -foreground black
638 $w.top.record tag configure marc-data -foreground black
641 $w.top.record delete 0.0 end
642 set recordType [z39.$sno recordType $no]
643 wm title $w "$recordType record #$no"
646 bind $w.top.record <Return> {destroy .full-marc}
648 pack $w.top.s -side right -fill y
649 pack $w.top.record -expand yes -fill both
652 bottom-buttons $w [list \
653 {Close} [list destroy $w]] 0
655 bottom-buttons $w [list \
656 {Close} [list destroy $w] \
657 {Duplicate} [list popup-marc $sno $no 1 0]] 0
658 menubutton $w.bot.formats -text "Format" -menu $w.bot.formats.m
659 menu $w.bot.formats.m
661 foreach f $displayFormats {
662 $w.bot.formats.m add radiobutton -label $f \
663 -variable popupMarcdf -value $i \
664 -command [list display-$f $sno $no $w.top.record 0]
667 pack $w.bot.formats -expand yes -ipadx 2 -ipady 2 \
668 -padx 3 -pady 3 -side left
672 foreach f $displayFormats {
673 $w.bot.formats.m entryconfigure $i \
674 -command [list display-$f $sno $no $w.top.record 0]
678 set ffunc [lindex $displayFormats $df]
679 set ffunc "display-$ffunc"
681 $ffunc $sno $no $w.top.record 0
684 proc update-target-hotlist {target base} {
687 set len [llength $hotTargets]
689 .top.target.m delete 6 [expr 6+[llength $hotTargets]]
692 foreach e $hotTargets {
693 if {$target == [lindex $e 0] && $base == [lindex $e 1]} {
694 set hotTargets [lreplace $hotTargets $i $i]
699 set hotTargets [linsert $hotTargets 0 [list $target $base]]
703 proc set-target-hotlist {} {
707 foreach e $hotTargets {
708 set target [lindex $e 0]
709 set base [lindex $e 1]
711 .top.target.m add command -label "$i $target" -command \
712 [list reopen-target $target {}]
714 .top.target.m add command -label "$i $target - $base" -command \
715 [list reopen-target $target $base]
724 proc reopen-target {target base} {
726 open-target $target $base
727 update-target-hotlist $target $base
730 proc define-target-action {} {
733 set target [.target-define.top.target.entry get]
737 foreach n [array names profile] {
743 set seq [lindex $profile(Default) 12]
745 set profile($target) $profile(Default)
746 set profile(Default) [lreplace $profile(Default) 12 12 [incr seq]]
748 protocol-setup $target
749 destroy .target-define
752 proc fail-response {target} {
753 set c [lindex [z39 failInfo] 0]
754 set m [lindex [z39 failInfo] 1]
759 proc connect-response {target base} {
760 dputs "connect-response"
761 show-target $target $base
765 proc open-target {target base} {
770 z39 comstack [lindex $profile($target) 6]
771 z39 protocol [lindex $profile($target) 11]
772 z39 idAuthentication [lindex $profile($target) 3]
773 z39 maximumRecordSize [lindex $profile($target) 4]
774 z39 preferredMessageSize [lindex $profile($target) 5]
775 dputs "maximumRecordSize="
776 dputs [z39 maximumRecordSize]
777 dputs "preferredMessageSize="
778 dputs [z39 preferredMessageSize]
779 show-status {Connecting} 1 0
781 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
783 z39 databaseNames $base
785 z39 failback [list fail-response $target]
786 z39 callback [list connect-response $target $base]
789 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
792 tkerror $errorMessage
793 show-status Ready 0 {}
797 .top.target.m disable 0
798 .top.target.m enable 1
799 .top.target.m enable 2
802 proc close-target {} {
809 .bot.a.set configure -text ""
813 show-status {Not connected} 0 0
816 .top.target.m disable 1
817 .top.target.m disable 2
818 .top.target.m enable 0
821 proc load-set-action {} {
825 ir-set z39.$setNo z39
827 set fname [.load-set.top.filename.entry get]
830 show-status {Loading} 1 {}
832 z39.$setNo loadFile $fname
834 set no [z39.$setNo numberOfRecordsReturned]
835 add-title-lines $setNo $no 1
837 set l [format "%-4d %7d" $setNo $no]
838 .top.rset.m add command -label $l \
839 -command [list add-title-lines $setNo 10000 1]
840 show-status {Ready} 0 {}
852 frame $w.top.filename
853 pack $w.top.filename -side top -anchor e -pady 2
855 entry-fields $w.top {filename} \
857 {load-set-action} {destroy .load-set}
859 top-down-ok-cancel $w {load-set-action} 1
863 proc init-request {} {
871 z39 callback {init-response}
872 show-status {Initializing} 1 {}
873 set err [catch {z39 init} errorMessage]
875 tkerror $errorMessage
876 show-status Ready 0 {}
880 proc init-response {} {
888 if {![z39 initResult]} {
889 show-status {Ready} 0 1
890 set u [z39 userInformationField]
892 tkerror "Connection rejected by target: $u"
894 if {[lsearch [z39 options] scan] >= 0} {
899 show-status {Ready} 0 1
903 proc search-request {bflag} {
914 dputs "search-request"
916 if {!$bflag && $busy} {
917 dputs "busy: search-request ignored"
922 show-status {Searching} 1 0
923 set delayRequest {search-request 1}
928 set query [index-query]
933 ir-set z39.$setNo z39
935 if {[lindex $profile($target) 10] == 1} {
936 z39.$setNo setName $setNo
937 dputs "setName=${setNo}"
939 z39.$setNo setName Default
940 dputs "setName=Default"
942 if {[lindex $profile($target) 8] == 1} {
943 z39.$setNo queryType rpn
945 if {[lindex $profile($target) 9] == 1} {
946 z39.$setNo queryType ccl
950 z39.$setNo preferredRecordSyntax $recordSyntax
951 z39 callback {search-response}
952 z39.$setNo search $query
953 show-status {Searching} 1 0
956 proc scan-copy {y entry} {
958 set no [$w.top.list nearest $y]
960 .lines.$entry.e delete 0 end
961 .lines.$entry.e insert 0 [string range [$w.top.list get $no] 8 end]
964 proc scan-request {} {
972 global queryButtonsFind
980 show-status {Scanning} 1 0
981 set delayRequest scan-request
990 set b [lindex $queryButtonsFind $curIndexEntry]
992 foreach a [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end] {
993 set attr "@attr $a $attr"
995 set title [lindex [lindex $queryInfoFind [lindex $b 1]] 0]
998 if {![winfo exists $w]} {
1005 entry $w.top.entry -relief sunken
1006 pack $w.top.entry -fill x -padx 4 -pady 2
1007 bind $w.top.entry <KeyRelease> [list scan-term-h $attr]
1009 listbox $w.top.list -yscrollcommand [list $w.top.scroll set] \
1011 scrollbar $w.top.scroll -orient vertical -border 1
1012 pack $w.top.list -side left -fill both -expand yes
1013 pack $w.top.scroll -side right -fill y
1014 $w.top.scroll config -command [list $w.top.list yview]
1016 listbox $w.top.list -font fixed -geometry 60x14
1017 pack $w.top.list -side left -fill both -expand yes
1020 bottom-buttons $w [list {Close} [list destroy $w] \
1021 {Up} [list scan-up $attr] \
1022 {Down} [list scan-down $attr]] 0
1023 bind $w.top.list <Up> [list scan-up $attr]
1024 bind $w.top.list <Down> [list scan-down $attr]
1026 bind $w.top.list <Double-Button-1> [list scan-copy %y $curIndexEntry]
1027 wm title $w "Scan $title"
1029 z39 callback [list scan-response $attr 0 35]
1030 z39.scan numberOfTermsRequested 5
1031 z39.scan preferredPositionInResponse 1
1032 z39.scan scan "${attr} 0"
1034 show-status {Scanning} 1 0
1037 proc scan-term-h {attr} {
1045 set nScanTerm [$w.top.entry get]
1046 if {$nScanTerm == $scanTerm} {
1049 set scanTerm $nScanTerm
1050 z39 callback [list scan-response $attr 0 35]
1051 z39.scan numberOfTermsRequested 5
1052 z39.scan preferredPositionInResponse 1
1053 dputs "${attr} \{${scanTerm}\}"
1054 if {$scanTerm == ""} {
1055 z39.scan scan "${attr} 0"
1057 z39.scan scan "${attr} \{${scanTerm}\}"
1059 show-status {Scanning} 1 0
1062 proc scan-response {attr start toget} {
1069 dputs "In scan-response"
1070 set m [z39.scan numberOfEntriesReturned]
1076 if {![winfo exists .scan-window]} {
1079 dputs "Handling cancel"
1080 if {$delayRequest != ""} {
1085 show-status {Ready} 0 1
1088 set nScanTerm [$w.top.entry get]
1089 if {$nScanTerm != $scanTerm} {
1090 z39 callback [list scan-response $attr 0 35]
1091 z39.scan numberOfTermsRequested 5
1092 z39.scan preferredPositionInResponse 1
1093 set scanTerm $nScanTerm
1094 dputs "${attr} \{${scanTerm}\}"
1095 if {$scanTerm == ""} {
1096 z39.scan scan "${attr} 0"
1098 z39.scan scan "${attr} \{${scanTerm}\}"
1100 show-status {Scanning} 1 0
1103 set status [z39.scan scanStatus]
1106 show-status {Ready} 0 1
1111 for {set i 0} {$i < $m} {incr i} {
1112 set term [lindex [z39.scan scanLine $i] 1]
1113 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1114 $w.top.list insert $i "$nostr $term"
1117 $w.top.list yview $scanView
1119 $w.top.list delete $start end
1120 for {set i 0} {$i < $m} {incr i} {
1121 set term [lindex [z39.scan scanLine $i] 1]
1122 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1123 $w.top.list insert end "$nostr $term"
1127 dputs "Handling cancel"
1129 if {$delayRequest != ""} {
1135 if {$toget > 0 && $m > 1 && $m < $toget} {
1136 set ntoget [expr $toget - $m + 1]
1137 dputs ntoget=$ntoget
1138 z39 callback [list scan-response $attr [expr $start + $m - 1] $ntoget]
1140 dputs "down continue: $q"
1142 z39.scan numberOfTermsRequested 10
1144 z39.scan numberOfTermsRequested $ntoget
1146 z39.scan preferredPositionInResponse 1
1147 dputs "${attr} \{$q\}"
1148 z39.scan scan "${attr} \{$q\}"
1151 if {$toget < 0 && $m > 1 && $m < [expr - $toget]} {
1152 set ntoget [expr - $toget - $m]
1153 dputs ntoget=$ntoget
1154 z39 callback [list scan-response $attr 0 -$ntoget]
1155 set q [string range [$w.top.list get 0] 8 end]
1156 dputs "up continue: $q"
1158 z39.scan numberOfTermsRequested 10
1159 z39.scan preferredPositionInResponse 11
1161 z39.scan numberOfTermsRequested $ntoget
1162 z39.scan preferredPositionInResponse [incr ntoget]
1164 dputs "${attr} \{$q\}"
1165 z39.scan scan "${attr} \{$q\}"
1168 show-status {Ready} 0 1
1171 proc scan-down {attr} {
1179 show-status {Scanning down} 1 0
1180 set delayRequest [list scan-down $attr]
1186 set scanView [expr $scanView + 5]
1187 set s [$w.top.list size]
1188 if {$scanView > $s} {
1189 z39 callback [list scan-response $attr [expr $s - 1] 25]
1190 set q [string range [$w.top.list get [expr $s - 1]] 8 end]
1192 z39.scan numberOfTermsRequested 10
1193 z39.scan preferredPositionInResponse 1
1194 show-status {Scanning} 1 0
1195 dputs "${attr} \{$q\}"
1196 z39.scan scan "${attr} \{$q\}"
1199 $w.top.list yview $scanView
1202 proc scan-up {attr} {
1210 show-status {Scanning up} 1 0
1211 set delayRequest [list scan-up $attr]
1217 set scanView [expr $scanView - 5]
1218 if {$scanView < 0} {
1219 z39 callback [list scan-response $attr 0 -25]
1220 set q [string range [$w.top.list get 0] 8 end]
1222 z39.scan numberOfTermsRequested 10
1223 z39.scan preferredPositionInResponse 11
1224 show-status {Scanning} 1 0
1225 z39.scan scan "${attr} \{$q\}"
1228 $w.top.list yview $scanView
1231 proc search-response {} {
1239 dputs "In search-response"
1241 dputs "Handling cancel"
1243 if {$delayRequest != ""} {
1250 set setMax [z39.$setNo resultCount]
1251 show-message "${setMax} hits"
1252 set l [format "%-4d %7d" $setNo $setMax]
1253 .top.rset.m add command -label $l \
1254 -command [list add-title-lines $setNo 10000 1]
1256 show-status {Ready} 0 1
1257 set status [z39.$setNo responseStatus]
1258 if {[lindex $status 0] == "NSD"} {
1259 set code [lindex $status 1]
1260 set msg [lindex $status 2]
1261 set addinfo [lindex $status 3]
1262 tkerror "NSD$code: $msg: $addinfo"
1270 show-status {Ready} 0 1
1271 z39 callback {present-response}
1272 z39.$setNo present $setOffset 1
1273 show-status {Retrieving} 1 0
1276 proc present-more {number} {
1284 dputs "present-more"
1286 show-status {Retrieving} 1 0
1287 set delayRequest "present-more $number"
1293 dputs "setNo=$setNo"
1296 set max [z39.$setNo resultCount]
1297 if {$max <= $setOffset} {
1299 dputs "setOffset=$setOffset"
1302 if {$number == ""} {
1306 if {$setMax > $max} {
1310 z39 callback {present-response}
1312 set toGet [expr $setMax - $setOffset + 1]
1319 z39.$setNo present $setOffset $toGet
1320 show-status {Retrieving} 1 0
1323 proc init-title-lines {} {
1324 .data.record delete 0.0 end
1327 proc title-press {y setno} {
1328 show-full-marc $setno [expr 1 + [.data.list nearest $y]] 0
1331 proc add-title-lines {setno no offset} {
1332 global displayFormats
1333 global displayFormat
1337 set setno $lastSetNo
1339 set lastSetNo $setno
1342 .bot.a.set configure -text $setno
1343 .data.record delete 0.0 end
1345 set ffunc [lindex $displayFormats $displayFormat]
1346 dputs "ffunc=$ffunc"
1347 set ffunc "display-$ffunc"
1348 for {set i 0} {$i < $no} {incr i} {
1349 set o [expr $i + $offset]
1350 set type [z39.$setno type $o]
1354 .data.record tag bind r$o <Any-Enter> {}
1355 .data.record tag bind r$o <Any-Leave> {}
1356 set insert0 [.data.record index insert]
1357 $ffunc $setno $o .data.record 1
1358 .data.record tag add r$o $insert0 insert
1359 .data.record tag bind r$o <1> \
1360 [list popup-marc $setno $o 0 0]
1365 proc present-response {} {
1372 dputs "In present-response"
1373 set no [z39.$setNo numberOfRecordsReturned]
1374 dputs "Returned $no records, setOffset $setOffset"
1375 add-title-lines $setNo $no $setOffset
1376 set setOffset [expr $setOffset + $no]
1378 dputs "Handling cancel"
1380 if {$delayRequest != ""} {
1385 set status [z39.$setNo responseStatus]
1386 if {[lindex $status 0] == "NSD"} {
1387 show-status {Ready} 0 1
1388 set code [lindex $status 1]
1389 set msg [lindex $status 2]
1390 set addinfo [lindex $status 3]
1391 tkerror "NSD$code: $msg: $addinfo"
1394 if {$no > 0 && $setOffset <= $setMax} {
1395 dputs "present-request from ${setOffset}"
1396 set toGet [expr $setMax - $setOffset + 1]
1400 z39.$setNo present $setOffset $toGet
1402 show-status {Ready} 0 1
1406 proc left-cursor {w} {
1407 set i [$w index insert]
1414 proc right-cursor {w} {
1415 set i [$w index insert]
1420 proc bind-fields {list returnAction escapeAction} {
1421 set max [expr [llength $list]-1]
1422 for {set i 0} {$i < $max} {incr i} {
1423 bind [lindex $list $i] <Return> $returnAction
1424 bind [lindex $list $i] <Escape> $escapeAction
1425 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
1426 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1427 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1429 bind [lindex $list $i] <Return> $returnAction
1430 bind [lindex $list $i] <Escape> $escapeAction
1431 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
1432 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1433 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1434 focus [lindex $list 0]
1437 proc entry-fields {parent list tlist returnAction escapeAction} {
1440 foreach field $list {
1441 set label ${parent}.${field}.label
1442 set entry ${parent}.${field}.entry
1443 label $label -text [lindex $tlist $i] -anchor e
1444 entry $entry -width 32 -relief sunken
1445 pack $label -side left
1446 pack $entry -side right
1447 lappend alist $entry
1450 bind-fields $alist $returnAction $escapeAction
1453 proc define-target-dialog {} {
1454 set w .target-define
1460 pack $w.top.target \
1461 -side top -anchor e -pady 2
1462 entry-fields $w.top {target} \
1464 {define-target-action} {destroy .target-define}
1465 top-down-ok-cancel $w {define-target-action} 1
1468 proc protocol-setup-delete {target} {
1470 global settingsChanged
1472 set a [alert "Are you sure you want to delete the target \
1473 definition $target ?"]
1475 set wno [lindex $profile($target) 12]
1478 unset profile($target)
1479 set settingsChanged 1
1484 proc protocol-setup-action {target} {
1487 global protocolRadioType
1488 global settingsChanged
1491 global ResultSetCheck
1493 set wno [lindex $profile($target) 12]
1497 set settingsChanged 1
1498 set len [$w.top.databases.list size]
1499 for {set i 0} {$i < $len} {incr i} {
1500 lappend b [$w.top.databases.list get $i]
1502 set profile($target) [list [$w.top.description.entry get] \
1503 [$w.top.host.entry get] \
1504 [$w.top.port.entry get] \
1505 [$w.top.idAuthentication.entry get] \
1506 [$w.top.maximumRecordSize.entry get] \
1507 [$w.top.preferredMessageSize.entry get] \
1513 $protocolRadioType \
1517 dputs $profile($target)
1521 proc place-force {window parent} {
1522 set g [wm geometry $parent]
1524 set p1 [string first + $g]
1525 set p2 [string last + $g]
1527 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
1528 set y [expr 60+[string range $g [expr $p2 +1] end]]
1529 wm geometry $window +${x}+${y}
1532 proc add-database-action {target} {
1535 set wno [lindex $profile($target) 12]
1538 $w.top.databases.list insert end \
1539 [.database-select.top.database.entry get]
1540 destroy .database-select
1543 proc add-database {target} {
1546 set w .database-select
1548 set oldFocus [focus]
1551 set wno [lindex $profile($target) 12]
1552 place-force $w .setup-${wno}
1556 frame $w.top.database
1558 pack $w.top.database -side top -anchor e -pady 2
1560 entry-fields $w.top {database} \
1561 {{Database to add:}} \
1562 [list add-database-action $target] {destroy .database-select}
1564 top-down-ok-cancel $w [list add-database-action $target] 1
1568 proc delete-database {target} {
1571 set wno [lindex $profile($target) 12]
1574 foreach i [$w.top.databases.list curselection] {
1575 set b [$w.top.databases.list get $i]
1578 set a [alert "Are you sure you want to remove the database(s)${l}?"]
1580 foreach i [lsort -decreasing \
1581 [$w.top.databases.list curselection]] {
1582 $w.top.databases.list delete $i
1587 proc protocol-setup {target} {
1590 global protocolRadioType
1593 global ResultSetCheck
1595 set wno [lindex $profile($target) 12]
1600 wm title $w "Setup $target"
1604 if {$target == ""} {
1608 dputs $profile($target)
1612 frame $w.top.description
1613 frame $w.top.idAuthentication
1614 frame $w.top.maximumRecordSize
1615 frame $w.top.preferredMessageSize
1616 frame $w.top.cs-type -relief ridge -border 2
1617 frame $w.top.protocol -relief ridge -border 2
1618 frame $w.top.query -relief ridge -border 2
1619 frame $w.top.databases -relief ridge -border 2
1621 # Maximum/preferred/idAuth ...
1622 pack $w.top.description $w.top.host $w.top.port \
1623 $w.top.idAuthentication $w.top.maximumRecordSize \
1624 $w.top.preferredMessageSize -side top -anchor e -pady 2
1626 entry-fields $w.top {description host port idAuthentication \
1627 maximumRecordSize preferredMessageSize} \
1628 {{Description:} {Host:} {Port:} {Id Authentication:} \
1629 {Maximum Record Size:} {Preferred Message Size:}} \
1630 [list protocol-setup-action $target] [list destroy $w]
1632 foreach sub {description host port idAuthentication \
1633 maximumRecordSize preferredMessageSize} {
1635 bind $w.top.$sub.entry <Control-a> [list add-database $target]
1636 bind $w.top.$sub.entry <Control-d> [list delete-database $target]
1638 $w.top.description.entry insert 0 [lindex $profile($target) 0]
1639 $w.top.host.entry insert 0 [lindex $profile($target) 1]
1640 $w.top.port.entry insert 0 [lindex $profile($target) 2]
1641 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
1642 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
1643 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
1644 set csRadioType [lindex $profile($target) 6]
1645 set RPNCheck [lindex $profile($target) 8]
1646 set CCLCheck [lindex $profile($target) 9]
1647 set ResultSetCheck [lindex $profile($target) 10]
1648 set protocolRadioType [lindex $profile($target) 11]
1649 if {$protocolRadioType == ""} {
1650 set protocolRadioType Z39
1654 pack $w.top.databases -side left -pady 4 -padx 4 -expand yes -fill both
1656 label $w.top.databases.label -text "Databases"
1657 button $w.top.databases.add -text "Add" \
1658 -command [list add-database $target]
1659 button $w.top.databases.delete -text "Delete" \
1660 -command [list delete-database $target]
1661 listbox $w.top.databases.list -geometry 20x6 \
1662 -yscrollcommand "$w.top.databases.scroll set"
1663 scrollbar $w.top.databases.scroll -orient vertical -border 1
1664 pack $w.top.databases.label -side top -fill x \
1666 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
1668 pack $w.top.databases.list -side left -fill both -expand yes \
1670 pack $w.top.databases.scroll -side right -fill y \
1672 $w.top.databases.scroll config -command "$w.top.databases.list yview"
1674 foreach b [lindex $profile($target) 7] {
1675 $w.top.databases.list insert end $b
1679 pack $w.top.cs-type -pady 4 -padx 4 -side top -fill x
1681 label $w.top.cs-type.label -text "Transport"
1682 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" -anchor w \
1683 -variable csRadioType -value tcpip
1684 radiobutton $w.top.cs-type.mosi -text "MOSI" -anchor w\
1685 -variable csRadioType -value mosi
1687 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
1688 -padx 4 -side top -fill x
1691 pack $w.top.protocol -pady 4 -padx 4 -side top -fill x
1693 label $w.top.protocol.label -text "Protocol"
1694 radiobutton $w.top.protocol.z39v2 -text "Z39.50" -anchor w \
1695 -variable protocolRadioType -value Z39
1696 radiobutton $w.top.protocol.sr -text "SR" -anchor w \
1697 -variable protocolRadioType -value SR
1699 pack $w.top.protocol.label $w.top.protocol.z39v2 $w.top.protocol.sr \
1700 -padx 4 -side top -fill x
1703 pack $w.top.query -pady 4 -padx 4 -side top -fill x
1705 label $w.top.query.label -text "Query support"
1706 checkbutton $w.top.query.c1 -text "RPN query" -anchor w -variable RPNCheck
1707 checkbutton $w.top.query.c2 -text "CCL query" -anchor w -variable CCLCheck
1708 checkbutton $w.top.query.c3 -text "Result sets" -anchor w -variable ResultSetCheck
1710 pack $w.top.query.label -side top
1711 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
1712 -padx 4 -side top -fill x
1715 bottom-buttons $w [list {Ok} [list protocol-setup-action $target] \
1716 {Delete} [list protocol-setup-delete $target] \
1717 {Cancel} [list destroy $w]] 0
1720 proc database-select-action {} {
1721 set w .database-select.top
1723 foreach indx [$w.databases.list curselection] {
1724 lappend b [$w.databases.list get $indx]
1727 z39 databaseNames $b
1729 destroy .database-select
1732 proc database-select {} {
1733 set w .database-select
1743 frame $w.top.databases -relief ridge -border 2
1745 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
1747 label $w.top.databases.label -text "List"
1748 listbox $w.top.databases.list -geometry 20x6 \
1749 -yscrollcommand "$w.top.databases.scroll set"
1750 scrollbar $w.top.databases.scroll -orient vertical -border 1
1751 pack $w.top.databases.label -side top -fill x \
1753 pack $w.top.databases.list -side left -fill both -expand yes \
1755 pack $w.top.databases.scroll -side right -fill y \
1757 $w.top.databases.scroll config -command "$w.top.databases.list yview"
1759 foreach b [lindex $profile($hostid) 7] {
1760 $w.top.databases.list insert end $b
1762 top-down-ok-cancel $w {database-select-action} 1
1765 proc cascade-target-list {} {
1768 foreach sub [winfo children .top.target.m.clist] {
1771 .top.target.m.clist delete 0 last
1772 foreach n [array names profile] {
1773 if {$n != "Default"} {
1774 set nl [lindex $profile($n) 12]
1775 if {[llength [lindex $profile($n) 7]] > 1} {
1776 .top.target.m.clist add cascade -label $n \
1777 -menu .top.target.m.clist.$nl
1778 menu .top.target.m.clist.$nl
1779 foreach b [lindex $profile($n) 7] {
1780 .top.target.m.clist.$nl add command -label $b \
1781 -command [list reopen-target $n $b]
1784 .top.target.m.clist add command -label $n \
1785 -command [list reopen-target $n {}]
1789 .top.target.m.slist delete 0 last
1790 foreach n [array names profile] {
1791 if {$n != "Default"} {
1792 .top.target.m.slist add command -label $n \
1793 -command [list protocol-setup $n]
1798 proc query-select {i} {
1799 global queryButtonsFind
1800 global queryInfoFind
1804 set queryInfoFind [lindex $queryInfo $i]
1805 set queryButtonsFind [lindex $queryButtons $i]
1807 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
1810 proc query-new-action {} {
1814 global settingsChanged
1816 set settingsChanged 1
1817 lappend queryTypes [.query-new.top.index.entry get]
1818 lappend queryButtons {}
1819 lappend queryInfo {}
1833 -side top -anchor e -pady 2
1834 entry-fields $w.top index \
1836 query-new-action {destroy .query-new}
1837 top-down-ok-cancel $w query-new-action 1
1840 proc query-delete-action {queryNo} {
1844 global settingsChanged
1846 set settingsChanged 1
1848 set queryTypes [lreplace $queryTypes $queryNo $queryNo]
1849 set queryButtons [lreplace $queryButtons $queryNo $queryNo]
1850 set queryInfo [lreplace $queryInfo $queryNo $queryNo]
1851 destroy .query-delete
1855 proc query-delete {queryNo} {
1863 set n [lindex $queryTypes $queryNo]
1865 label $w.top.warning -bitmap warning
1866 message $w.top.quest -text "Are you sure you want to delete the \
1867 query type $n ?" -aspect 200
1868 pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
1869 bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
1870 {Cancel} [list destroy $w]] 1
1873 proc cascade-query-list {} {
1875 set w .top.options.m.query
1878 $w.slist delete 0 last
1879 foreach n $queryTypes {
1880 $w.slist add command -label $n -command [list query-setup $i]
1885 $w.clist delete 0 last
1886 foreach n $queryTypes {
1887 $w.clist add command -label $n -command [list query-select $i]
1891 $w.dlist delete 0 last
1892 foreach n $queryTypes {
1893 $w.dlist add command -label $n -command [list query-delete $i]
1898 proc save-geometry {} {
1899 global windowGeometry
1902 global displayFormat
1906 set windowGeometry(.) [wm geometry .]
1908 set f [open "~/.clientrc.tcl" w]
1910 puts $f "set hotTargets \{ $hotTargets \}"
1911 puts $f "set textWrap $textWrap"
1912 puts $f "set displayFormat $displayFormat"
1913 puts $f "set popupMarcdf $popupMarcdf"
1914 puts $f "set recordSyntax $recordSyntax"
1915 foreach n [array names windowGeometry] {
1916 puts -nonewline $f "set \{windowGeometry($n)\} \{"
1917 puts -nonewline $f $windowGeometry($n)
1923 proc save-settings {} {
1926 global settingsChanged
1931 if {![file writable "${libdir}/clientrc.tcl"]} {
1934 set f [open "${libdir}/clientrc.tcl" w]
1935 puts $f "# Setup file"
1937 foreach n [array names profile] {
1938 puts -nonewline $f "set \{profile($n)\} \{"
1939 puts -nonewline $f $profile($n)
1942 puts -nonewline $f "set queryTypes \{"
1943 puts -nonewline $f $queryTypes
1946 puts -nonewline $f "set queryButtons \{"
1947 puts -nonewline $f $queryButtons
1950 puts -nonewline $f "set queryInfo \{"
1951 puts -nonewline $f $queryInfo
1954 set settingsChanged 0
1966 label $w.top.warning -bitmap warning
1967 message $w.top.message -text $ask -aspect 200 \
1968 -font -Adobe-Times-Medium-R-Normal-*-180-*
1970 pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
1973 top-down-ok-cancel $w {alert-action} 1
1977 proc alert-action {} {
1983 proc exit-action {} {
1984 global settingsChanged
1986 if {$settingsChanged} {
1987 set a [alert "you haven't saved your settings. Do you wish to save?"]
1996 proc listbuttonaction {w name h user i} {
1997 $w configure -text [lindex $name 0]
1998 $h [lindex $name 1] $user $i
2001 proc listbuttonx {button no names handle user} {
2002 if {[winfo exists $button]} {
2003 $button configure -text [lindex [lindex $names $no] 0]
2004 ${button}.m delete 0 last
2006 menubutton $button -text [lindex [lindex $names $no] 0] \
2007 -width 10 -menu ${button}.m -relief raised -border 1
2011 foreach name $names {
2012 ${button}.m add command -label [lindex $name 0] \
2013 -command [list listbuttonaction ${button} $name \
2019 proc listbutton {button no names} {
2020 menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
2021 -relief raised -border 1
2023 foreach name $names {
2024 ${button}.m add command -label $name \
2025 -command [list ${button} configure -text $name]
2029 proc listbuttonv-action {button var names i} {
2032 set $var [lindex $names [expr $i+1]]
2033 $button configure -text [lindex $names $i]
2036 proc listbuttonv {button var names} {
2040 eval "set val $$var"
2041 set l [llength $names]
2042 for {set i 1} {$i < $l} {incr i 2} {
2043 if {$val == [lindex $names $i]} {
2045 set n [lindex $names $i]
2049 if {[winfo exists $button]} {
2050 $button configure -text $n
2053 menubutton $button -text $n -menu ${button}.m \
2054 -relief raised -border 1
2056 for {set i 0} {$i < $l} {incr i 2} {
2057 ${button}.m add command -label [lindex $names $i] \
2058 -command [list listbuttonv-action $button $var $names $i]
2062 proc query-add-index-action {queryNo} {
2066 global queryButtonsTmp
2068 set newI [.query-add-index.top.index.entry get]
2069 lappend queryInfoTmp [list $newI {}]
2070 $w.top.index.list insert end $newI
2071 destroy .query-add-index
2072 #destroy $w.top.lines
2073 #frame $w.top.lines -relief ridge -border 2
2074 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2075 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2078 proc query-add-line {queryNo} {
2082 global queryButtonsTmp
2084 lappend queryButtonsTmp {I 0}
2086 #destroy $w.top.lines
2087 #frame $w.top.lines -relief ridge -border 2
2088 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2089 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2092 proc query-del-line {queryNo} {
2096 global queryButtonsTmp
2098 set l [llength $queryButtonsTmp]
2103 set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
2104 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2107 proc query-add-index {queryNo} {
2108 set w .query-add-index
2111 place-force $w .query-setup
2115 -side top -anchor e -pady 2
2116 entry-fields $w.top {index} \
2118 [list query-add-index-action $queryNo] [list destroy $w]
2119 top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
2122 proc query-setup-action {queryNo} {
2125 global queryButtonsTmp
2127 global queryButtonsFind
2128 global queryInfoFind
2130 global settingsChanged
2132 set settingsChanged 1
2134 set queryInfo [lreplace $queryInfo $queryNo $queryNo \
2136 set queryButtons [lreplace $queryButtons $queryNo $queryNo \
2138 set queryInfoFind $queryInfoTmp
2139 set queryButtonsFind $queryButtonsTmp
2141 destroy .query-setup
2142 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2145 proc activate-e-index {value no i} {
2146 global queryButtonsTmp
2147 global queryIndexTmp
2149 set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
2150 dputs $queryButtonsTmp
2151 set queryIndexTmp $i
2154 proc activate-index {value no i} {
2155 global queryButtonsFind
2157 set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
2159 dputs "queryButtonsFind $queryButtonsFind"
2162 proc update-attr {} {
2164 listbuttonv $w.top.relation.b relationTmpValue\
2165 {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
2166 {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
2167 {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
2168 listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
2169 {First in field} 1 {First in subfield} 2 {Any position in field} 3}
2170 listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
2171 {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list} 6 \
2172 {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
2173 {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
2174 {local-number} 107 {string} 108 {numeric string} 109}
2175 listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
2176 {Left} 2 {Left and right} 3 {No truncation} 100 \
2177 {Process #} 101 {Re-1} 102 {Re-2} 103}
2178 listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
2179 {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
2182 proc use-attr {init} {
2194 {BNB card number} 10
2195 {BGF(sic) number} 11
2197 {Dewey classification} 13
2198 {UDC classification} 14
2199 {Bliss classification} 15
2201 {NLM call number} 17
2202 {NAL call number} 18
2203 {MOS call number} 19
2204 {Local classification} 20
2205 {Subject heading} 21
2207 {BDI-index-subject} 23
2211 {LC-subject-heading} 27
2212 {RVM-subject-heading} 28
2213 {Local subject index} 29
2215 {Date of publication} 31
2216 {Date of acquisition} 32
2218 {Title-collective} 34
2221 {Title-added-title-page} 37
2225 {Title-other-variant} 41
2227 {Title-abbreviated} 43
2231 {Subject-subdivision} 47
2232 {Number-natl-bibliography} 48
2233 {Number-legal-deposit} 49
2234 {Number-govt-publication} 50
2235 {Number-publisher-for-music} 51
2237 {Number-local-call} 53
2239 {Code-geographic-area} 55
2240 {Code-institution} 56
2242 {Name-geographic} 58
2243 {Place-publication} 59
2245 {Microform-generation} 61
2252 {Author-name-personal} 1004
2253 {Author-name-corporate} 1005
2254 {Author-name-conference} 1006
2255 {Identifier-standard} 1007
2256 {Subject-LC-children's} 1008
2257 {Subject-name-personal} 1009
2259 {Date/time added to database} 1011
2260 {Date/time last modified} 1012
2261 {Authority/format identifier} 1013
2263 {Concept-reference} 1015
2265 {Server choice} 1017
2267 {Record source} 1019
2270 {Geographic class} 1022
2274 {Related periodical} 1026
2275 {Report number} 1027
2277 {Thematic number} 1030
2278 {Material type} 1031
2286 set l [llength $attr]
2291 for {set i 0} {$i < $l} {incr i} {
2292 $w.top.use.list insert end [lindex $attr $i]
2294 if {$useTmpValue == [lindex $attr $i]} {
2299 $w.top.use.list select from $s
2300 $w.top.use.list select to $s
2305 $w.top.use.list yview $s
2307 set lno [lindex [$w.top.use.list curselection] 0]
2308 set i [expr $lno+$lno+1]
2309 set useTmpValue [lindex $attr $i]
2310 dputs "useTmpValue=$useTmpValue"
2314 proc index-setup-action {oldAttr queryNo indexNo} {
2315 set attr [lindex $oldAttr 0]
2318 global relationTmpValue
2319 global structureTmpValue
2320 global truncationTmpValue
2321 global completenessTmpValue
2322 global positionTmpValue
2327 dputs "index-setup-action"
2328 dputs "queryNo $queryNo"
2329 dputs "indexNo $indexNo"
2330 if {$useTmpValue > 0} {
2331 lappend attr "1=$useTmpValue"
2333 if {$relationTmpValue > 0} {
2334 lappend attr "2=$relationTmpValue"
2336 if {$positionTmpValue > 0} {
2337 lappend attr "3=$positionTmpValue"
2339 if {$structureTmpValue > 0} {
2340 lappend attr "4=$structureTmpValue"
2342 if {$truncationTmpValue > 0} {
2343 lappend attr "5=$truncationTmpValue"
2345 if {$completenessTmpValue > 0} {
2346 lappend attr "6=$completenessTmpValue"
2348 dputs "new attr $attr"
2349 set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
2350 destroy .index-setup
2353 proc index-setup {attr queryNo indexNo} {
2356 global relationTmpValue
2357 global structureTmpValue
2358 global truncationTmpValue
2359 global completenessTmpValue
2360 global positionTmpValue
2362 set relationTmpValue 0
2363 set truncationTmpValue 0
2364 set structureTmpValue 0
2365 set positionTmpValue 0
2366 set completenessTmpValue 0
2369 set len [llength $attr]
2370 for {set i 1} {$i < $len} {incr i} {
2371 set q [lindex $attr $i]
2372 set l [string first = $q]
2374 set t [string range $q 0 [expr $l - 1]]
2375 set v [string range $q [expr $l + 1] end]
2378 { set useTmpValue $v }
2380 { set relationTmpValue $v }
2382 { set positionTmpValue $v }
2384 { set structureTmpValue $v }
2386 { set truncationTmpValue $v }
2388 { set completenessTmpValue $v }
2392 if {[winfo exists $w]} {
2397 set n [lindex $attr 0]
2398 wm title $w "Index setup $n"
2402 frame $w.top.use -relief ridge -border 2
2403 frame $w.top.relation -relief ridge -border 2
2404 frame $w.top.position -relief ridge -border 2
2405 frame $w.top.structure -relief ridge -border 2
2406 frame $w.top.truncation -relief ridge -border 2
2407 frame $w.top.completeness -relief ridge -border 2
2413 pack $w.top.use -side left -pady 6 -padx 6 -fill y
2415 label $w.top.use.label -text "Use"
2416 listbox $w.top.use.list -geometry 26x10 \
2417 -yscrollcommand "$w.top.use.scroll set"
2418 scrollbar $w.top.use.scroll -orient vertical -border 1
2419 pack $w.top.use.label -side top -fill x \
2421 pack $w.top.use.list -side left -fill both -expand yes \
2423 pack $w.top.use.scroll -side right -fill y \
2425 $w.top.use.scroll config -command "$w.top.use.list yview"
2429 # Relation Attributes
2431 pack $w.top.relation -pady 6 -padx 6 -side top
2432 label $w.top.relation.label -text "Relation" -width 18
2434 pack $w.top.relation.label $w.top.relation.b -fill x
2436 # Position Attributes
2438 pack $w.top.position -pady 6 -padx 6 -side top
2439 label $w.top.position.label -text "Position" -width 18
2441 pack $w.top.position.label $w.top.position.b -fill x
2443 # Structure Attributes
2445 pack $w.top.structure -pady 6 -padx 6 -side top
2446 label $w.top.structure.label -text "Structure" -width 18
2448 pack $w.top.structure.label $w.top.structure.b -fill x
2450 # Truncation Attributes
2452 pack $w.top.truncation -pady 6 -padx 6 -side top
2453 label $w.top.truncation.label -text "Truncation" -width 18
2455 pack $w.top.truncation.label $w.top.truncation.b -fill x
2457 # Completeness Attributes
2459 pack $w.top.completeness -pady 6 -padx 6 -side top
2460 label $w.top.completeness.label -text "Completeness" -width 18
2462 pack $w.top.completeness.label $w.top.completeness.b -fill x
2465 bottom-buttons $w [list \
2466 {Ok} [list index-setup-action $attr $queryNo $indexNo] \
2467 {Cancel} [list destroy $w]] 0
2471 proc query-edit-index {queryNo} {
2475 set i [lindex [$w.top.index.list curselection] 0]
2479 set attr [lindex $queryInfoTmp $i]
2480 dputs "Editing no $i $attr"
2481 index-setup $attr $queryNo $i
2484 proc query-delete-index {queryNo} {
2486 global queryButtonsTmp
2489 set i [lindex [$w.top.index.list curselection] 0]
2493 set queryInfoTmp [lreplace $queryInfoTmp $i $i]
2494 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2495 $w.top.index.list delete $i
2498 proc query-setup {queryNo} {
2504 global queryButtonsTmp
2506 global queryIndexTmp
2509 set queryName [lindex $queryTypes $queryNo]
2510 set queryInfoTmp [lindex $queryInfo $queryNo]
2511 set queryButtonsTmp [lindex $queryButtons $queryNo]
2516 wm title $w "Query setup $queryName"
2520 frame $w.top.lines -relief ridge -border 2
2522 pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2526 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2528 button $w.top.lines.add -text "Add" \
2529 -command [list query-add-line $queryNo]
2530 button $w.top.lines.del -text "Remove" \
2531 -command [list query-del-line $queryNo]
2533 pack $w.top.lines.del -fill x -side bottom
2534 pack $w.top.lines.add -fill x -pady 10 -side bottom
2538 frame $w.top.index -relief ridge -border 2
2539 pack $w.top.index -pady 6 -padx 6 -side right -fill y
2541 listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
2542 scrollbar $w.top.index.scroll -orient vertical -border 1 \
2543 -command [list $w.top.index.list yview]
2544 bind $w.top.index.list <2> [list query-edit-index $queryNo]
2546 pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
2547 pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
2549 $w.top.index.list select from 0
2550 $w.top.index.list select to 0
2552 foreach x $queryInfoTmp {
2553 $w.top.index.list insert end [lindex $x 0]
2556 bottom-buttons $w [list \
2557 {Ok} [list query-setup-action $queryNo] \
2558 {Add index} [list query-add-index $queryNo] \
2559 {Edit index} [list query-edit-index $queryNo] \
2560 {Delete index} [list query-delete-index $queryNo] \
2561 {Cancel} [list destroy $w]] 0
2564 proc index-clear {} {
2565 global queryButtonsFind
2568 foreach b $queryButtonsFind {
2569 .lines.$i.e delete 0 end
2574 proc index-query {} {
2575 global queryButtonsFind
2576 global queryInfoFind
2581 foreach b $queryButtonsFind {
2582 set term [string trim [.lines.$i.e get]]
2584 set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
2586 set len [string length $term]
2590 if {[string index $term $len] == "?"} {
2592 set term [string range $term 0 [expr $len - 1]]
2594 if {[string index $term 0] == "?"} {
2596 set term [string range $term 1 end]
2598 set term "\{${term}\}"
2599 if {$right && $left} {
2600 set term "@attr 5=3 ${term}"
2602 set term "@attr 5=1 ${term}"
2604 set term "@attr 5=2 ${term}"
2607 set term "@attr $a ${term}"
2610 set qs "@and ${qs} ${term}"
2621 proc index-focus-in {w i} {
2622 global curIndexEntry
2624 $w.$i configure -background red
2625 set curIndexEntry $i
2628 proc index-lines {w realOp buttonInfo queryInfo handle} {
2630 foreach b $buttonInfo {
2631 if {! [winfo exists $w.$i]} {
2632 frame $w.$i -background white -border 1
2634 listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
2637 if {! [winfo exists $w.$i.e]} {
2638 entry $w.$i.e -width 32 -relief sunken -border 1
2639 bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
2640 bind $w.$i.e <FocusOut> [list $w.$i configure \
2642 pack $w.$i.l -side left
2643 pack $w.$i.e -side left -fill x -expand yes
2644 pack $w.$i -side top -fill x -padx 2 -pady 2
2645 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
2646 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
2647 bind $w.$i.e <Return> {search-request 0}
2650 pack $w.$i.l -side left
2651 pack $w.$i -side top -fill x -padx 2 -pady 2
2656 while {[winfo exists $w.$j]} {
2667 bind $w.$j.e <Tab> "focus $w.$k.e"
2671 bind $w.$i.e <Tab> "focus $w.0.e"
2676 proc search-fields {w buttondefs} {
2678 foreach buttondef $buttondefs {
2679 frame $w.$i -background white
2681 listbutton $w.$i.l 0 $buttondef
2682 entry $w.$i.e -width 32 -relief sunken
2684 pack $w.$i.l -side left
2685 pack $w.$i.e -side left -fill x -expand yes
2687 pack $w.$i -side top -fill x -padx 2 -pady 2
2689 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
2690 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
2698 bind $w.$j.e <Tab> "focus $w.$k.e \n
2699 $w.$k configure -background red \n
2700 $w.$j configure -background white"
2703 bind $w.$i.e <Tab> "focus $w.0.e \n
2704 $w.0 configure -background red \n
2705 $w.$i configure -background white"
2707 $w.0 configure -background red
2710 if {[info exists windowGeometry(.)]} {
2711 set g $windowGeometry(.)
2719 frame .top -border 1 -relief raised
2720 frame .lines -border 1 -relief raised
2721 frame .mid -border 1 -relief raised
2722 frame .data -border 1 -relief raised
2723 frame .bot -border 1 -relief raised
2724 pack .top .lines .mid -side top -fill x
2725 pack .data -side top -fill both -expand yes
2728 menubutton .top.file -text "File" -menu .top.file.m
2730 .top.file.m add command -label "Save settings" -command {save-settings}
2731 .top.file.m add separator
2732 .top.file.m add command -label "Exit" -command {exit-action}
2734 menubutton .top.target -text "Target" -menu .top.target.m
2736 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
2737 .top.target.m add command -label "Disconnect" -command {close-target}
2738 .top.target.m add command -label "About" -command {about-target}
2739 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
2740 .top.target.m add command -label "Setup new" -command {define-target-dialog}
2741 .top.target.m add separator
2744 .top.target.m disable 1
2745 .top.target.m disable 2
2747 menu .top.target.m.clist
2748 menu .top.target.m.slist
2751 menubutton .top.service -text "Service" -menu .top.service.m
2753 .top.service.m add command -label "Database" -command {database-select}
2754 .top.service.m add cascade -label "Present" -menu .top.service.m.present
2755 menu .top.service.m.present
2756 .top.service.m.present add command -label "10 More" \
2757 -command [list present-more 10]
2758 .top.service.m.present add command -label "All" \
2759 -command [list present-more {}]
2760 .top.service.m add command -label "Search" -command {search-request 0}
2761 .top.service.m add command -label "Scan" -command {scan-request}
2763 .top.service configure -state disabled
2765 menubutton .top.rset -text "Set" -menu .top.rset.m
2767 .top.rset.m add command -label "Load" -command {load-set}
2768 .top.rset.m add separator
2770 menubutton .top.options -text "Options" -menu .top.options.m
2772 .top.options.m add cascade -label "Query" -menu .top.options.m.query
2773 .top.options.m add cascade -label "Format" -menu .top.options.m.formats
2774 .top.options.m add cascade -label "Wrap" -menu .top.options.m.wrap
2775 .top.options.m add cascade -label "Syntax" -menu .top.options.m.syntax
2777 menu .top.options.m.query
2778 .top.options.m.query add cascade -label "Select" \
2779 -menu .top.options.m.query.clist
2780 .top.options.m.query add cascade -label "Edit" \
2781 -menu .top.options.m.query.slist
2782 .top.options.m.query add command -label "New" \
2783 -command {query-new}
2784 .top.options.m.query add cascade -label "Delete" \
2785 -menu .top.options.m.query.dlist
2787 menu .top.options.m.query.slist
2788 menu .top.options.m.query.clist
2789 menu .top.options.m.query.dlist
2792 menu .top.options.m.formats
2794 foreach f $displayFormats {
2795 .top.options.m.formats add radiobutton -label $f -value $i \
2796 -command [list set-display-format $i] -variable displayFormat
2800 menu .top.options.m.wrap
2801 .top.options.m.wrap add radiobutton -label "Character" \
2802 -value char -variable textWrap -command {set-wrap char}
2803 .top.options.m.wrap add radiobutton -label "Word" \
2804 -value word -variable textWrap -command {set-wrap word}
2805 .top.options.m.wrap add radiobutton -label "None" \
2806 -value none -variable textWrap -command {set-wrap none}
2808 menu .top.options.m.syntax
2809 .top.options.m.syntax add radiobutton -label "USMARC" \
2810 -value USMARC -variable recordSyntax
2811 .top.options.m.syntax add radiobutton -label "UNIMARC" \
2812 -value UNIMARC -variable recordSyntax
2813 .top.options.m.syntax add radiobutton -label "UKMARC" \
2814 -value UKMARC -variable recordSyntax
2815 .top.options.m.syntax add radiobutton -label "DANMARC" \
2816 -value DANMARC -variable recordSyntax
2817 .top.options.m.syntax add radiobutton -label "FINMARC" \
2818 -value FINMARC -variable recordSyntax
2819 .top.options.m.syntax add radiobutton -label "NORMARC" \
2820 -value NORMARC -variable recordSyntax
2821 .top.options.m.syntax add radiobutton -label "PICAMARC" \
2822 -value PICAMARC -variable recordSyntax
2823 .top.options.m.syntax add separator
2824 .top.options.m.syntax add radiobutton -label "SUTRS" \
2825 -value SUTRS -variable recordSyntax
2827 menubutton .top.help -text "Help" -menu .top.help.m
2830 .top.help.m add command -label "Help on help" \
2831 -command {tkerror "Help on help not available. Sorry"}
2832 .top.help.m add command -label "About" -command {about-origin}
2834 pack .top.file .top.target .top.service .top.rset .top.options -side left
2835 pack .top.help -side right
2837 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
2839 button .mid.search -width 7 -text {Search} -command {search-request 0} \
2841 button .mid.scan -width 7 -text {Scan} \
2842 -command scan-request -state disabled
2843 button .mid.present -width 7 -text {Present} -command [list present-more 10] \
2846 button .mid.clear -width 7 -text {Clear} -command index-clear
2847 pack .mid.search .mid.scan .mid.present .mid.clear -side left \
2848 -fill y -padx 5 -pady 3
2850 text .data.record -height 2 -width 20 -wrap none \
2851 -yscrollcommand [list .data.scroll set] -wrap $textWrap
2852 scrollbar .data.scroll -command [list .data.record yview]
2853 pack .data.scroll -side right -fill y
2854 pack .data.record -expand yes -fill both
2857 if {[tk colormodel .] == "color"} {
2858 .data.record tag configure marc-tag -foreground blue
2859 .data.record tag configure marc-id -foreground red
2861 .data.record tag configure marc-tag -foreground black
2862 .data.record tag configure marc-id -foreground black
2864 .data.record tag configure marc-data -foreground black
2866 button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
2868 pack .bot.a -side left -fill x
2869 pack .bot.logo -side right -padx 2 -pady 2
2871 message .bot.a.target -text "" -aspect 1000 -border 1
2873 label .bot.a.status -text "Not connected" -width 15 -relief \
2874 sunken -anchor w -border 1
2875 label .bot.a.set -text "" -width 5 -relief \
2876 sunken -anchor w -border 1
2877 label .bot.a.message -text "" -width 15 -relief \
2878 sunken -anchor w -border 1
2880 pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
2881 pack .bot.a.status .bot.a.set .bot.a.message \
2882 -side left -padx 2 -pady 2