1 wm title . "IrTcl Client"
2 wm iconname . "IrTcl Client"
11 # Procedure configure-enable-e {w n}
13 # n menu entry number (0 is first entry)
15 proc configure-enable-e {w n} {
16 $w entryconfigure $n -state normal
19 # Procedure configure-disable-e {w n}
21 # n menu entry number (0 is first entry)
23 proc configure-disable-e {w n} {
24 $w entryconfigure $n -state disabled
26 set noFocus [list -takefocus 0]
29 # Define dummy clock function if it is not there.
30 if {[catch {clock seconds}]} {
36 # Define libdir to the IrTcl configuration directory.
37 # In the line below LIBDIR will be modified during 'make install'.
40 # If the bitmaps sub directory is present with a bitmap we assume
41 # the client is run from the source directory in which case we
42 # set libdir the current directory.
43 if {[file readable bitmaps/book2]} {
47 # Make a final check to see if libdir was set ok.
48 if {! [file readable ${libdir}/bitmaps/book2]} {
49 puts "Cannot locate system files in ${libdir}. You must either run this"
50 puts "program from the source directory root of ir-tcl or you must assure"
51 puts "that it is installed - normally in /usr/local/lib/irtcl"
55 # Initialize a lot of globals.
60 set profile(Default,description) {}
61 set profile(Default,host) {}
62 set profile(Default,port) 210
63 set profile(Default,authentication) {}
64 set profile(Default,maximumRecordSize) 50000
65 set profile(Default,preferredMessageSize) 30000
66 set profile(Default,comstack) tcpip
67 set profile(Default,namedResultSets) 1
68 set profile(Default,queryRPN) 1
69 set profile(Default,queryCCL) 0
70 set profile(Default,protocol) Z39
71 set profile(Default,windowNumber) 1
72 set profile(Default,largeSetLowerBound) 2
73 set profile(Default,smallSetUpperBound) 0
74 set profile(Default,mediumSetPresentNumber) 0
75 set profile(Default,presentChunk) 4
76 set profile(Default,timeDefine) {}
77 set profile(Default,timeLastInit) {}
78 set profile(Default,timeLastExplain) {}
79 set profile(Default,targetInfoName) {}
80 set profile(Default,recentNews) {}
81 set profile(Default,maxResultSets) {}
82 set profile(Default,maxResultSize) {}
83 set profile(Default,maxTerms) {}
84 set profile(Default,multipleDatabases) 0
85 set profile(Default,welcomeMessage) {}
98 set elementSetNames None
103 set queryTypes {Simple}
104 set queryButtons { { {I 0} {I 1} {I 2} } }
105 set queryInfo { { {Title {1=4 4=1}} {Author {1=1}} \
106 {Subject {1=21}} {Any {1=1016}} } }
113 set syntaxList {None sep USMARC UNIMARC UKMARC DANMARC FINMARC NORMARC PICAMARC sep SUTRS sep GRS1}
116 set font(bb,normal) {Helvetica 24}
117 set font(bb,bold) {Helvetica 24 bold}
118 set font(b,normal) {Helvetica 24}
119 set font(b,bold) {Helvetica 18 bold}
120 set font(n,normal) {Helvetica 12}
121 set font(n,bold) {Helvetica 12 bold}
122 set font(s,bold) {Helvetica 10 bold}
123 set font(ss,bold) {Helvetica 8 bold}
125 # Procedure tkerror {err}
127 # Override the Tk error handler function.
133 if {[winfo exists $w]} {
142 label $w.top.b -bitmap error
143 message $w.top.t -aspect 300 -text "Error: $err" -font $font(b,bold)
144 pack $w.top.b $w.top.t -side left -padx 10 -pady 10
146 bottom-buttons $w [list {Close} [list destroy $w]] 1
150 # Read tag set file (if present)
151 if {[file readable "${libdir}/tagsets.tcl"]} {
152 source "${libdir}/tagsets.tcl"
155 # Read the global target configuration file.
156 if {[file readable "${libdir}/irtdb.tcl"]} {
157 source "${libdir}/irtdb.tcl"
159 # Read the local target configuration file.
160 if {[file readable "irtdb.tcl"]} {
164 # Read the user configuration file.
165 if {[file readable "${libdir}/.clientrc.tcl"]} {
166 source "${libdir}/.clientrc.tcl"
171 set queryAutoOld $queryAuto
173 # Convert old format to new format...
174 foreach target [array names profile] {
175 set timedef [clock seconds]
176 if {[string first , $target] == -1} {
177 if {![info exists profile($target,port)]} {
178 foreach n [array names profile Default,*] {
179 set profile($target,[string range $n 8 end]) $profile($n)
181 set profile($target,description) [lindex $profile($target) 0]
182 set profile($target,host) [lindex $profile($target) 1]
183 set profile($target,port) [lindex $profile($target) 2]
184 set profile($target,authentication) [lindex $profile($target) 3]
185 set profile($target,maximumRecordSize) \
186 [lindex $profile($target) 4]
187 set profile($target,preferredMessageSize) \
188 [lindex $profile($target) 5]
189 set profile($target,comstack) [lindex $profile($target) 6]
190 set profile($target,databases) [lindex $profile($target) 7]
191 set profile($target,timeDefine) $timedef
192 set profile($target,windowNumber) 1
194 unset profile($target)
198 # Assign unique ID's to each target's window number
200 foreach n [array names profile *,windowNumber] {
204 set profile(Default,windowNumber) $wno
206 # These globals describe the current query type. They are set to the
208 set queryButtonsFind [lindex $queryButtons 0]
209 set queryInfoFind [lindex $queryInfo 0]
211 # Procedure read-formats
212 # Read all Tcl source files in the subdirectory 'formats'.
213 # The name of each source will correspond to a display format.
214 proc read-formats {} {
215 global displayFormats
220 set formats [glob {*.[tT][cC][lL]}]
222 if {[file readable $f]} {
224 set l [string length $f]
225 set f [string tolower [string range $f 0 [expr $l - 5]]]
226 lappend displayFormats $f
232 # Procedure set-wrap {m}
233 # m boolean wrap mode
234 # Handler to enable/disable text wrap in the main record window
239 .data.record configure -wrap $m
242 # Procedure dputs {m}
243 # m string to be printed
244 # puts utility for debugging.
252 # Procedure apduDump {}
253 # Logs BER dump of last APDU in window if debugMode is true.
259 if {$debugMode == 0} return
262 set offset [lindex $x 1]
263 set length [lindex $x 0]
265 if {![winfo exists $w]} {
269 wm title $w "APDU information"
274 text $w.top.t -font fixed -width 60 -height 12 -wrap word \
275 -relief flat -borderwidth 0 \
276 -yscrollcommand [list $w.top.s set] -background grey85
277 scrollbar $w.top.s -command [list $w.top.t yview]
278 pack $w.top.s -side right -fill y
279 pack $w.top.t -expand yes -fill both
281 bottom-buttons $w [list {Close} [list destroy $w]] 0
283 $w.top.t insert end "Length: ${length}\n"
285 $w.top.t insert end "Offset: ${offset}\n"
287 $w.top.t insert end [lindex $x 2]
288 $w.top.t insert end "---------------------------------\n"
292 # Procedure set-display-format {f}
294 # Reformats main record window to use display format given by f
295 proc set-display-format {f} {
296 global displayFormat setNo busy
303 .bot.a.status configure -text "Reformatting"
306 add-title-lines -1 10000 1
309 # Procedure initBindings
310 # Disables various default bindings for Text and Listbox widgets.
311 proc initBindings {} {
314 foreach e [bind Text] {
315 set TextBinding($e) [bind Text $e]
319 bind $w <B1-Motion> {}
320 bind $w <Shift-B1-Motion> {}
325 # Procedure TextEditable
326 # Apply "standard" events to a text widget. It should be editable now.
327 proc TextEditable {w} {
330 foreach e [array names TextBinding] {
331 bind $w $e $TextBinding($e)
335 # Procedure post-menu {wbutton wmenu}
336 # wbutton button widget
338 # Post menu near button. Note: not used.
339 proc post-menu {wbutton wmenu} {
342 $wmenu post [winfo rootx $wbutton] \
343 [expr [winfo rooty $wbutton]+[winfo height $wbutton]]
347 # Procedure destroyGW {w}
349 # Saves geometry of widget w in windowGeometry array. This
350 # Procedure is used to save current geometry of a window before
352 # See also topLevelG.
354 global windowGeometry
355 catch {set windowGeometry($w) [wm geometry $w]}
358 # Procedure topLevelG
360 # Makes a new top level widget named w; sets geometry of window if it
361 # exists in windowGeometry array. The destroyGW procedure is set
362 # to be called when the Destroy event occurs.
364 global windowGeometry
367 if {[info exists windowGeometry($w)]} {
368 set g $windowGeometry($w)
373 bind $w <Destroy> [list destroyGW $w]
376 # Procedure top-down-window {w}
377 # w window (possibly top level)
378 # Makes two frames inside w called top and bot.
379 proc top-down-window {w} {
380 frame $w.top -relief raised -border 1
381 frame $w.bot -relief raised -border 1
382 pack $w.top -side top -fill both -expand yes
383 pack $w.bot -fill both
386 # Procedure top-down-ok-cancel {w ok-action g}
387 # w top level widget with $w.bot-frame
388 # ok-action ok script
390 # Makes two buttons in the bot frame called Ok and Cancel. The
391 # ok-action is executed if Ok is pressed. If Cancel is activated
392 # The window is destroyed. If g is true a grab is performed on the
393 # window and the procedure waits until the window is destroyed.
394 proc top-down-ok-cancel {w ok-action g} {
395 frame $w.bot.left -relief sunken -border 1
396 pack $w.bot.left -side left -expand yes -ipadx 2 -ipady 2 -padx 1 -pady 1
397 button $w.bot.left.ok -width 4 -text {Ok} -command ${ok-action}
398 pack $w.bot.left.ok -expand yes -ipadx 1 -ipady 1 -padx 2 -pady 2
399 button $w.bot.cancel -width 5 -text {Cancel} -command [list destroy $w]
400 pack $w.bot.cancel -side left -expand yes
408 # Procedure bottom-buttons {w buttonList g}
409 # w top level widget with $w.bot-frame
410 # buttonList button specifications
412 # Makes a list of buttons in the $w.bot frame. The buttonList is a list
413 # of button specifications. Each button specification consists of two
414 # items; the first item is button label name; the second item is a script
415 # of be executed when that button is executed. A grab is performed if g
416 # is true and it waits for the window to be destroyed.
417 proc bottom-buttons {w buttonList g} {
419 set l [llength $buttonList]
421 frame $w.bot.$i -relief sunken -border 1
422 pack $w.bot.$i -side left -expand yes -padx 2 -pady 2
423 button $w.bot.$i.ok -text [lindex $buttonList $i] \
424 -command [lindex $buttonList [expr $i+1]]
425 pack $w.bot.$i.ok -expand yes -padx 2 -pady 2 -side left
429 button $w.bot.$i -text [lindex $buttonList $i] \
430 -command [lindex $buttonList [expr $i+1]]
431 pack $w.bot.$i -expand yes -padx 2 -pady 2 -side left
441 # Procedure cancel-operation
442 # This handler is invoked when the user wishes to cancel an operation.
443 # If the system is currently busy a "Cancel" will be displayed in the
444 # status area and the cancelFlag is set to true indicating that future
445 # responses from the target should be ignored. The system is no longer
446 # busy when this procedure exists.
447 proc cancel-operation {} {
448 global cancelFlag busy delayRequest
453 show-status Cancel 0 1
457 # Procedure show-target {target base}
458 # target name of target
459 # base name of database
460 # Displays target name and database name in the target status area.
461 proc show-target {target base} {
462 if {![string length $target]} {
463 .bot.a.target configure -text {}
466 if {![string length $base]} {
467 .bot.a.target configure -text "$target"
469 .bot.a.target configure -text "$target - $base"
473 # Procedure show-logo {v1}
475 # This procedure maintains the book logo in the bottom of the screen.
476 # It is invoked only once during initialization of windows, etc., and
477 # by itself. The global 'busy' variable determines whether the logo is
479 proc show-logo {v1} {
487 .bot.logo configure -bitmap @${libdir}/bitmaps/book${v1}
488 after 140 [list show-logo $v1]
492 .bot.logo configure -bitmap @${libdir}/bitmaps/book1
501 # Procedure show-status {status b sb}
502 # status status message string
504 # sb search busy indicator
505 # Display status information according to 'status' and sets the global
506 # busy flag 'busy' to b if b is non-empty. If sb is non-empty it indicates
507 # whether service buttons should be enabled or disabled.
508 proc show-status {status b sb} {
509 global busy scanEnable setOffset setMax setNo
511 .bot.a.status configure -text "$status"
513 if {$busy == 0} {set busy 1}
521 .top.service configure -state normal
522 .mid.search configure -state normal
524 .mid.scan configure -state normal
526 configure-disable-e .top.service.m 3
529 configure-disable-e .top.service.m 1
530 } elseif {[z39.$setNo nextResultSetPosition] > 0 &&
531 [z39.$setNo nextResultSetPosition] <= [z39.$setNo resultCount]} {
532 configure-enable-e .top.service.m 1
533 .mid.present configure -state normal
535 configure-disable-e .top.service.m 1
536 .mid.present configure -state disabled
538 if {[winfo exists .scan-window]} {
539 .scan-window.bot.2 configure -state normal
540 .scan-window.bot.4 configure -state normal
543 .top.service configure -state disabled
544 .mid.search configure -state disabled
545 .mid.scan configure -state disabled
546 .mid.present configure -state disabled
548 if {[winfo exists .scan-window]} {
549 .scan-window.bot.2 configure -state disabled
550 .scan-window.bot.4 configure -state disabled
555 # Procedure show-message {msg}
557 # Sets message the bottom of the screen to msg.
558 proc show-message {msg} {
559 .bot.a.message configure -text "$msg"
562 # Procedure insertWithTags {w text args}
564 # text string to be inserted
566 # Inserts text at the insertion point in widget w. The text is tagged
567 # with the tags in args.
568 proc insertWithTags {w text args} {
569 set start [$w index insert]
570 $w insert insert $text
571 foreach tag [$w tag names $start] {
572 $w tag remove $tag $start insert
575 $w tag add $i $start insert
579 # Procedure popup-license and displays LICENSE information.
580 proc popup-license {} {
585 wm title $w "License"
590 text $w.top.t -width 80 -height 10 -wrap word -relief flat -borderwidth 0 \
591 -font fixed -yscrollcommand [list $w.top.s set]
592 scrollbar $w.top.s -command [list $w.top.t yview]
593 pack $w.top.s -side right -fill y
594 pack $w.top.t -expand yes -fill both
596 if {[file readable "${libdir}/LICENSE"]} {
597 set f [open "${libdir}/LICENSE" r]
598 while {[gets $f buf] != -1} {
599 $w.top.t insert end $buf
600 $w.top.t insert end "\n"
604 bottom-buttons $w [list {Close} [list destroy $w]] 1
607 # Procedure about-target
608 # Displays various information about the current target, such
609 # as implementation-name, implementation-id, etc.
610 proc about-target {} {
611 set w .about-target-w
616 wm title $w "About target"
620 frame $w.top.a -relief ridge -border 2
621 frame $w.top.p -relief ridge -border 2
622 pack $w.top.a $w.top.p -side top -fill x
624 label $w.top.a.about -text "About"
625 label $w.top.a.irtcl -text $hostid -font $font(bb,bold)
626 pack $w.top.a.about $w.top.a.irtcl -side top
628 set i [z39 targetImplementationName]
629 label $w.top.p.in -text "Implementation name: $i"
630 set i [z39 targetImplementationId]
631 label $w.top.p.ii -text "Implementation id: $i"
632 set i [z39 targetImplementationVersion]
633 label $w.top.p.iv -text "Implementation version: $i"
635 label $w.top.p.op -text "Protocol options: $i"
636 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.op -side top -anchor nw
638 bottom-buttons $w [list {Close} [list destroy $w]] 1
641 # Procedure about-origin-logo {n}
643 # Displays book logo in the .about-origin-w widget
644 proc about-origin-logo {n} {
646 set w .about-origin-w
647 if {![winfo exists $w]} {
654 $w.top.a.logo configure -bitmap @${libdir}/bitmaps/book$n
655 after 140 [list about-origin-logo $n]
658 # Procedure about-origin
659 # Display various information about origin (this client).
660 proc about-origin {} {
661 set w .about-origin-w
662 global libdir font tk_version
664 if {[winfo exists $w]} {
669 wm title $w "About IrTcl"
673 frame $w.top.a -relief ridge -border 2
674 frame $w.top.p -relief ridge -border 2
675 pack $w.top.a $w.top.p -side top -fill x
677 label $w.top.a.irtcl -text "IrTcl" -font $font(bb,bold)
678 label $w.top.a.logo -bitmap @${libdir}/bitmaps/book1
679 pack $w.top.a.irtcl $w.top.a.logo -side left -expand yes
682 catch {set i [z39 implementationName]}
683 label $w.top.p.in -text "Implementation name: $i"
684 catch {set i [z39 implementationId]}
685 label $w.top.p.ii -text "Implementation id: $i"
686 catch {set i [z39 implementationVersion]}
687 label $w.top.p.iv -text "Implementation version: $i"
689 label $w.top.p.tk -text "Tk version: $i"
690 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.tk -side top -anchor nw
693 bottom-buttons $w [list {Close} [list destroy $w] \
694 {License} [list popup-license]] 0
697 # Procedure popup-marc {sno no b df}
698 # sno result set number
699 # no record position number
700 # b popup window number
702 # Displays record in set $sno at position $no in window .full-marc$b.
703 # The global variable $popupMarcdf holds the current format method.
704 proc popup-marc {sno no b df} {
705 global font displayFormats popupMarcdf
707 if {[z39.$sno type $no] != "DB"} {
712 while {[winfo exists .full-marc$b]} {
718 if {![winfo exists $w]} {
723 frame $w.top -relief raised -border 1
724 frame $w.bot -relief raised -border 1
725 pack $w.top -side top -fill both -expand yes
726 pack $w.bot -fill both
728 text $w.top.record -width 60 -height 5 -wrap word -relief flat \
729 -borderwidth 0 -font fixed \
730 -yscrollcommand [list $w.top.s set] -background grey85
731 scrollbar $w.top.s -command [list $w.top.record yview]
732 $w.top.record tag configure marc-tag -foreground blue
733 $w.top.record tag configure marc-id -foreground red
734 $w.top.record tag configure marc-data -foreground black
735 $w.top.record tag configure marc-head -font $font(n,bold) \
736 -background black -foreground white
737 $w.top.record tag configure marc-pref -font $font(n,normal) -foreground blue
738 $w.top.record tag configure marc-text -font $font(n,normal) -foreground black
739 $w.top.record tag configure marc-it -font $font(n,normal) -foreground black
741 pack $w.top.s -side right -fill y
742 pack $w.top.record -expand yes -fill both
744 bottom-buttons $w [list \
745 {Close} [list destroy $w] \
749 menubutton $w.bot.formats -text "Format" -menu $w.bot.formats.m -relief raised
750 irmenu $w.bot.formats.m
751 pack $w.bot.formats -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3 -side left
753 $w.bot.formats.m delete 0 last
756 foreach f $displayFormats {
757 $w.bot.formats.m add radiobutton -label $f -variable popupMarcdf -value $i \
758 -command [list popup-marc $sno $no $b 0]
761 $w.top.record delete 0.0 end
762 set recordType [z39.$sno recordType $no]
763 wm title $w "$recordType record #$no"
765 $w.bot.2 configure -command [list popup-marc $sno [expr $no-1] $b $df]
766 $w.bot.4 configure -command [list popup-marc $sno [expr $no+1] $b $df]
768 $w.bot.2 configure -state disabled
770 $w.bot.2 configure -state normal
772 if {[z39.$sno type [expr $no+1]] != "DB"} {
773 $w.bot.4 configure -state disabled
775 $w.bot.4 configure -state normal
777 $w.bot.6 configure -command [list popup-marc $sno $no -1 0]
778 set ffunc [lindex $displayFormats $df]
779 set ffunc "display-$ffunc"
781 $ffunc $sno $no $w.top.record 0
784 # Procedure update-target-hotlist {target base}
785 # target current target name
786 # base current database name
787 # Updates the global $hotTargets so that $target and $base are
788 # moved to the front, i.e. they become the number 1 target/base.
789 # The target menu is updated by a call to set-target-hotlist.
790 proc update-target-hotlist {target base} {
793 set olen [llength $hotTargets]
795 foreach e $hotTargets {
796 if {$target == [lindex $e 0] && $base == [lindex $e 1]} {
797 set hotTargets [lreplace $hotTargets $i $i]
802 set hotTargets [linsert $hotTargets 0 [list $target $base]]
803 set-target-hotlist $olen
806 # Procedure delete-target-hotlist {target}
807 # target target to be deleted
808 # Updates the global $hotTargets so that $target is removed.
809 # The target menu is updated by a call to set-target-hotlist.
810 proc delete-target-hotlist {target} {
813 set olen [llength $hotTargets]
815 foreach e $hotTargets {
816 if {$target == [lindex $e 0]} {
817 set hotTargets [lreplace $hotTargets $i $i]
821 set-target-hotlist $olen
824 # Procedure set-target-hotlist {olen}
825 # olen number of hot target entries to be deleted from menu
826 # Updates the target menu with the targets with the first 8 entries
827 # in the $hotTargets global.
828 proc set-target-hotlist {olen} {
832 .top.target.m delete 6 [expr 6+$olen]
835 foreach e $hotTargets {
836 set target [lindex $e 0]
837 set base [lindex $e 1]
838 if {![string length $base]} {
839 .top.target.m add command -label "$i $target" -command \
840 [list reopen-target $target {}]
842 .top.target.m add command -label "$i $target - $base" -command \
843 [list reopen-target $target $base]
852 # Procedure reopen-target {target base}
853 # target target to be opened
854 # base base to be used
855 # Closes connection with current target and opens a new connection
856 # with $target and database $base.
857 proc reopen-target {target base} {
859 open-target $target $base
860 update-target-hotlist $target $base
863 # Procedure define-target-action
864 # Prepares the setup of a new target. The name of the target
865 # is read from the dialog .target-define dialog (procedure
866 # define-target-dialog) and the target definition window is displayed by
867 # a call to protocol-setup.
868 proc define-target-action {} {
871 set target [.target-define.top.target.entry get]
872 if {![string length $target]} {
875 foreach n [array names profile *,host] {
876 if {![string compare $n ${target},host]} {
877 destroy .target-define
882 foreach n [array names profile Default,*] {
883 set profile($target,[string range $n 8 end]) $profile($n)
886 incr profile(Default,windowNumber)
888 protocol-setup $target
889 destroy .target-define
892 # Procedure fail-response {target}
893 # target current target
894 # Error handler (IrTcl failback) that takes care of serious protocol
895 # errors, connection lost, etc.
896 proc fail-response {target} {
899 set c [lindex [z39 failInfo] 0]
900 set m [lindex [z39 failInfo] 1]
901 if {$c == 4 || $c == 5} {
909 # Procedure connect-response {target base}
910 # target current target
911 # base current database
912 # IrTcl connect response handler.
913 proc connect-response {target base} {
914 dputs "connect-response"
915 init-request $target $base
918 # Procedure open-target {target base}
919 # target target to be opened
920 # base database to be used
921 # Opens a new connection with $target/$base.
922 proc open-target {target base} {
923 global profile hostid presentChunk currentDb
926 z39 comstack $profile($target,comstack)
927 z39 protocol $profile($target,protocol)
928 eval z39 idAuthentication $profile($target,authentication)
929 z39 maximumRecordSize $profile($target,maximumRecordSize)
930 z39 preferredMessageSize $profile($target,preferredMessageSize)
931 dputs "maximumRecordSize=[z39 maximumRecordSize]"
932 dputs "preferredMessageSize=[z39 preferredMessageSize]"
933 show-status Connecting 1 0
934 set x $profile($target,largeSetLowerBound)
935 if {![string length $x]} {
938 z39 largeSetLowerBound $x
940 set x $profile($target,smallSetUpperBound)
941 if {![string length $x]} {
944 z39 smallSetUpperBound $x
946 set x $profile($target,mediumSetPresentNumber)
947 if {![string length $x]} {
950 z39 mediumSetPresentNumber $x
952 set presentChunk $profile($target,presentChunk)
953 if {![string length $presentChunk]} {
957 z39 failback [list fail-response $target]
958 z39 callback [list connect-response $target $base]
959 show-target $target $base
962 z39 connect $profile($target,host):$profile($target,port)
966 tkerror $errorMessage
967 show-status "Not connected" 0 {}
973 # changeQueryButtons $target $base
975 # .top.options.m.query.slist entryconfigure 2 -state normal
976 configure-disable-e .top.target.m 0
977 configure-enable-e .top.target.m 1
978 configure-enable-e .top.target.m 2
981 # Procedure close-target
982 # Shuts down the connection with current target.
983 proc close-target {} {
984 global hostid cancelFlag setNo setNoLast currentDb
989 .bot.a.set configure -text ""
991 set currentDb Default
994 show-status {Not connected} 0 0
995 .top.options.m.query.slist entryconfigure 2 -state disabled
998 configure-disable-e .top.target.m 1
999 configure-disable-e .top.target.m 2
1000 .top.rset.m delete 1 last
1001 .top.rset.m add separator
1002 configure-enable-e .top.target.m 0
1005 # Procedure load-set-action
1006 # Loads records from a file. The filename is read from the entry
1007 # .load-set.filename.entry (see function load-set)
1008 proc load-set-action {} {
1012 ir-set z39.$setNoLast z39
1014 set fname [.load-set.top.filename.entry get]
1017 show-status Loading 1 {}
1019 z39.$setNoLast loadFile $fname
1021 set no [z39.$setNoLast numberOfRecordsReturned]
1022 add-title-lines $setNoLast $no 1
1024 set l [format "%-4d %7d" $setNoLast $no]
1025 .top.rset.m add command -label $l \
1026 -command [list add-title-lines $setNoLast 10000 1]
1027 show-status Ready 0 {}
1030 # Procedure load-set
1031 # Dialog that asks for a filename with records to be loaded
1032 # into a result set.
1036 set oldFocus [focus]
1040 frame $w.top.filename
1041 pack $w.top.filename -side top -anchor e -pady 2
1043 entry-fields $w.top {filename} \
1045 {load-set-action} {destroy .load-set}
1047 top-down-ok-cancel $w {load-set-action} 1
1051 # Procedure init-request
1052 # Sends an initialize request to the target. This procedure is called
1053 # when a connect has been established.
1054 proc init-request {target base} {
1061 z39 callback [list init-response $target $base]
1062 show-status Initializing 1 {}
1063 set err [catch {z39 init} errorMessage]
1065 tkerror $errorMessage
1066 show-status Ready 0 {}
1070 # Procedure init-response
1071 # Handles and incoming init-response. The service buttons
1072 # are enabled. The global $scanEnable indicates whether the target
1074 proc init-response {target base} {
1075 global cancelFlag profile scanEnable settingsChanged
1077 dputs {init-response}
1083 if {![z39 initResult]} {
1084 set u [z39 userInformationField]
1086 tkerror "Connection rejected by target: $u"
1088 z39 failback [list explain-crash $target $base]
1089 explain-check $target [list ready-response $base] $base
1093 # Procedure explain-crash
1094 # Handles target that dies during explain.
1095 proc explain-crash {target base} {
1096 global profile settingsChanged
1098 set profile($target,timeLastInit) [clock seconds]
1099 set settingsChanged 1
1102 open-target $target $base
1105 # Procedure explain-check
1106 # Stub function to check explain. May be overwritten later.
1107 #proc explain-check {target response}
1108 # eval $response [list $target]
1111 # Procedure ready-response
1112 # Called after a target has been initialized and, possibly, explained
1113 proc ready-response {base target} {
1114 global profile settingsChanged scanEnable queryAuto
1116 z39 failback [list fail-response $target]
1117 if {[string length $base]} {
1118 set profile($target,timeLastInit) [clock seconds]
1119 set settingsChanged 1
1121 z39 databaseNames $base
1122 cascade-dblist $target $base
1123 show-target $target $base
1125 if {[lsearch [z39 options] scan] >= 0} {
1130 .data.record delete 1.0 end
1131 set desc [string trim $profile($target,description)]
1132 if {[string length $desc]} {
1133 .data.record insert end "$desc\n\n"
1135 .data.record insert end "$target\n\n"
1137 set data [string trim $profile($target,welcomeMessage)]
1138 if {[string length $data]} {
1139 .data.record insert end "Welcome Message:\n$data\n\n"
1141 set data [string trim $profile($target,recentNews)]
1142 if {[string length $data]} {
1143 .data.record insert end "News:\n$data\n"
1145 ready-response-actions $target $base
1147 show-status Ready 0 1
1150 #proc ready-response-actions {target base}
1151 #This procedure take care of all the actions that should start if connect is succesfull.
1152 proc ready-response-actions {target base} {
1153 global profile queryAuto
1154 get-attributeDetails $target $base
1155 changeQueryButtons $target $base
1156 configureOptionsSyntax $target $base
1157 if {[info exists profile($target,AttributeDetails,$base,Bib1Use)] && $queryAuto == 1} {
1158 changeQueryButtons $target $base
1159 change-queryInfo $target $base
1161 .top.options.m.query.slist entryconfigure 2 -state normal
1164 .top.options.m.query.slist entryconfigure 2 -state disabled
1168 # Procedure search-request
1169 # bflag flag to indicate if this procedure calls itself
1170 # Performs a search. If $busy is 1, the search-request is performed
1171 # at a later time (when another response arrives). This procedure
1172 # sets many search-related Z39-settings. The global $setNo is set
1173 # to the result set number (z39.$setNo).
1174 proc search-request {bflag} {
1175 global setNo setNoLast profile hostid busy cancelFlag delayRequest recordSyntax elementSetNames
1179 if {![string length [z39 connect]]} {
1182 dputs "search-request"
1184 if {!$bflag && $busy} {
1185 dputs "busy: search-request ignored"
1190 show-status Searching 1 0
1191 set delayRequest {search-request 1}
1196 set query [index-query]
1197 if {![string length $query]} {
1201 set setNo $setNoLast
1202 ir-set z39.$setNo z39
1204 if {$profile($target,namedResultSets)} {
1205 z39.$setNo setName $setNo
1206 dputs "setName=${setNo}"
1208 z39.$setNo setName default
1209 dputs "setName=default"
1211 if {$profile($target,queryRPN)} {
1212 z39.$setNo queryType rpn
1213 } elseif {$profile($target,queryCCL)} {
1214 z39.$setNo queryType ccl
1218 if {![string compare $recordSyntax None]} {
1219 z39.$setNo preferredRecordSyntax {}
1221 z39.$setNo preferredRecordSyntax $recordSyntax
1223 if {![string compare $elementSetNames None]} {
1224 z39.$setNo elementSetNames {}
1225 z39.$setNo smallSetElementSetNames {}
1226 z39.$setNo mediumSetElementSetNames {}
1228 z39.$setNo elementSetNames $elementSetNames
1229 z39.$setNo smallSetElementSetNames $elementSetNames
1230 z39.$setNo mediumSetElementSetNames $elementSetNames
1232 z39 callback {search-response}
1233 z39.$setNo search $query
1234 show-status Searching 1 0
1237 # Procedure scan-copy {y entry}
1238 # y y-position of mouse pointer
1239 # entry a search entry in the top
1240 # Copies the term in the list nearest $y to the query entry specified
1242 proc scan-copy {y entry} {
1244 set no [$w.top.list nearest $y]
1246 .lines.$entry.e delete 0 end
1247 .lines.$entry.e insert 0 [string range [$w.top.list get $no] 8 end]
1250 # Procedure scan-request
1251 # Performs a scan on term "0" with the current attributes in entry
1252 # specified by the global $curIndexEntry.
1253 proc scan-request {} {
1256 global profile hostid scanView scanTerm curIndexEntry queryButtonsFind \
1257 queryInfoFind cancelFlag delayRequest
1259 dputs "scan-request"
1262 show-status Scanning 1 0
1263 set delayRequest scan-request
1270 set b [lindex $queryButtonsFind $curIndexEntry]
1272 foreach a [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end] {
1273 set attr "@attr $a $attr"
1275 set title [lindex [lindex $queryInfoFind [lindex $b 1]] 0]
1276 ir-scan z39.scan z39
1278 if {![winfo exists $w]} {
1285 entry $w.top.entry -relief sunken
1286 pack $w.top.entry -fill x -padx 4 -pady 2
1287 bind $w.top.entry <KeyRelease> [list scan-term-h $attr]
1288 listbox $w.top.list -yscrollcommand [list $w.top.scroll set] -font fixed
1289 scrollbar $w.top.scroll -orient vertical -border 1
1290 pack $w.top.list -side left -fill both -expand yes
1291 pack $w.top.scroll -side right -fill y
1292 $w.top.scroll config -command [list $w.top.list yview]
1294 bottom-buttons $w [list {Close} [list destroy $w] \
1295 {Up} [list scan-up $attr] \
1296 {Down} [list scan-down $attr]] 0
1297 bind $w.top.list <Up> [list scan-up $attr]
1298 bind $w.top.list <Down> [list scan-down $attr]
1301 bind $w.top.list <Double-Button-1> [list scan-copy %y $curIndexEntry]
1302 wm title $w "Scan $title"
1304 z39 callback [list scan-response $attr 0 35]
1305 z39.scan numberOfTermsRequested 5
1306 z39.scan preferredPositionInResponse 1
1307 z39.scan scan "${attr} 0"
1309 show-status Scanning 1 0
1312 # Procedure scan-term-h {attr}
1313 # attr attribute specification
1314 # This procedure is called whenever a key is released in the entry in the
1315 # scan window (.scan-window). A scan is then initiated with the new contents
1316 # of the entry as the starting term.
1317 proc scan-term-h {attr} {
1318 global busy scanTerm
1324 set nScanTerm [$w.top.entry get]
1325 if {$nScanTerm == $scanTerm} {
1328 set scanTerm $nScanTerm
1329 z39 callback [list scan-response $attr 0 35]
1330 z39.scan numberOfTermsRequested 5
1331 z39.scan preferredPositionInResponse 1
1332 dputs "${attr} \{${scanTerm}\}"
1333 if {![string length $scanTerm]} {
1334 z39.scan scan "${attr} 0"
1336 z39.scan scan "${attr} \{${scanTerm}\}"
1338 show-status Scanning 1 0
1341 # Procedure scan-response {attr start toget}
1342 # attr attribute specification
1343 # start position of first term in the response
1344 # toget number of total terms to get
1345 # This procedure handles all scan-responses. $start specifies the list
1346 # entry number of the first incoming term. The $toget indicates the total
1347 # number of terms to be retrieved from the target. The $toget may be
1348 # negative in which case, scan is performed 'backwards' (- $toget is
1349 # the total number of terms in this case). This procedure usually calls
1350 # itself several times in order to get small scan-term-list chunks.
1351 proc scan-response {attr start toget} {
1352 global cancelFlag delayRequest scanTerm scanView
1355 dputs "In scan-response"
1357 set m [z39.scan numberOfEntriesReturned]
1363 if {![winfo exists .scan-window]} {
1366 dputs "Handling cancel"
1367 if {$delayRequest != ""} {
1372 show-status Ready 0 1
1375 set nScanTerm [$w.top.entry get]
1376 if {$nScanTerm != $scanTerm} {
1377 z39 callback [list scan-response $attr 0 35]
1378 z39.scan numberOfTermsRequested 5
1379 z39.scan preferredPositionInResponse 1
1380 set scanTerm $nScanTerm
1381 dputs "${attr} \{${scanTerm}\}"
1382 if {![string length $scanTerm]} {
1383 z39.scan scan "${attr} 0"
1385 z39.scan scan "${attr} \{${scanTerm}\}"
1387 show-status Scanning 1 0
1390 set status [z39.scan scanStatus]
1393 show-status Ready 0 1
1398 for {set i 0} {$i < $m} {incr i} {
1399 set term [lindex [z39.scan scanLine $i] 1]
1400 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1401 $w.top.list insert $i "$nostr $term"
1404 $w.top.list yview $scanView
1406 $w.top.list delete $start end
1407 for {set i 0} {$i < $m} {incr i} {
1408 set term [lindex [z39.scan scanLine $i] 1]
1409 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1410 $w.top.list insert end "$nostr $term"
1414 dputs "Handling cancel"
1416 if {$delayRequest != ""} {
1422 if {$toget > 0 && $m > 1 && $m < $toget} {
1423 set ntoget [expr $toget - $m + 1]
1424 dputs ntoget=$ntoget
1425 z39 callback [list scan-response $attr [expr $start + $m - 1] $ntoget]
1427 dputs "down continue: $q"
1429 z39.scan numberOfTermsRequested 10
1431 z39.scan numberOfTermsRequested $ntoget
1433 z39.scan preferredPositionInResponse 1
1434 dputs "${attr} \{$q\}"
1435 z39.scan scan "${attr} \{$q\}"
1438 if {$toget < 0 && $m > 1 && $m < [expr - $toget]} {
1439 set ntoget [expr - $toget - $m]
1440 dputs ntoget=$ntoget
1441 z39 callback [list scan-response $attr 0 -$ntoget]
1442 set q [string range [$w.top.list get 0] 8 end]
1443 dputs "up continue: $q"
1445 z39.scan numberOfTermsRequested 10
1446 z39.scan preferredPositionInResponse 11
1448 z39.scan numberOfTermsRequested $ntoget
1449 z39.scan preferredPositionInResponse [incr ntoget]
1451 dputs "${attr} \{$q\}"
1452 z39.scan scan "${attr} \{$q\}"
1455 show-status Ready 0 1
1458 # Procedure scan-down {attr}
1459 # attr attribute specification
1460 # This procedure is called when the user hits the Down button the scan
1461 # window. A new scan is initiated with a positive $toget passed to the
1462 # scan-response handler.
1463 proc scan-down {attr} {
1464 global scanView cancelFlag delayRequest
1469 show-status {Scanning down} 1 0
1470 set delayRequest [list scan-down $attr]
1476 set scanView [expr $scanView + 5]
1477 set s [$w.top.list size]
1478 if {$scanView > $s} {
1479 z39 callback [list scan-response $attr [expr $s - 1] 25]
1480 set q [string range [$w.top.list get [expr $s - 1]] 8 end]
1482 z39.scan numberOfTermsRequested 10
1483 z39.scan preferredPositionInResponse 1
1484 show-status Scanning 1 0
1485 dputs "${attr} \{$q\}"
1486 z39.scan scan "${attr} \{$q\}"
1489 $w.top.list yview $scanView
1492 # Procedure scan-up {attr}
1493 # attr attribute specification
1494 # This procedure is called when the user hits the Up button the scan
1495 # window. A new scan is initiated with a negative $toget passed to the
1496 # scan-response handler.
1497 proc scan-up {attr} {
1498 global scanView cancelFlag delayRequest
1503 show-status Scanning 1 0
1504 set delayRequest [list scan-up $attr]
1510 set scanView [expr $scanView - 5]
1511 if {$scanView < 0} {
1512 z39 callback [list scan-response $attr 0 -25]
1513 set q [string range [$w.top.list get 0] 8 end]
1515 z39.scan numberOfTermsRequested 10
1516 z39.scan preferredPositionInResponse 11
1517 show-status Scanning 1 0
1518 z39.scan scan "${attr} \{$q\}"
1521 $w.top.list yview $scanView
1524 # Procedure search-response
1525 # This procedure handles search-responses. If the search is successful
1526 # this procedure will try to retrieve a total of 20 records from the target;
1527 # however not more than $presentChunk records at a time. This procedure
1528 # affects the following globals:
1529 # $setOffset current record position offset
1530 # $setMax total number of records to be retrieved
1531 proc search-response {} {
1532 global setNo setOffset setMax cancelFlag busy delayRequest presentChunk
1535 dputs "In search-response"
1537 dputs "Handling cancel"
1539 if {$delayRequest != ""} {
1547 set setMax [z39.$setNo resultCount]
1548 show-status Ready 0 1
1549 set status [z39.$setNo responseStatus]
1550 if {![string compare [lindex $status 0] NSD]} {
1551 z39.$setNo nextResultSetPosition 0
1552 set code [lindex $status 1]
1553 set msg [lindex $status 2]
1554 set addinfo [lindex $status 3]
1555 tkerror "NSD$code: $msg: $addinfo"
1558 show-message "${setMax} hits"
1563 show-status Ready 0 1
1564 set l [format "%-4d %7d" $setNo $setMax]
1565 .top.rset.m add command -label $l -command [list recall-set $setNo]
1569 set no [z39.$setNo numberOfRecordsReturned]
1570 dputs "Returned $no records, setOffset $setOffset"
1571 add-title-lines $setNo $no $setOffset
1572 set setOffset [expr $setOffset + $no]
1574 set toGet [expr $setMax - $setOffset + 1]
1576 if {$setOffset == 1} {
1578 } elseif {$toGet > $presentChunk} {
1579 set toGet $presentChunk
1581 z39 callback {present-response}
1582 z39.$setNo present $setOffset $toGet
1583 show-status Retrieving 1 0
1587 # Procedure present-more {number}
1588 # number number of records to be retrieved
1589 # This procedure starts a present-request. The $number variable indicates
1590 # the total number of records to be retrieved. The global $presentChunk
1591 # specifies the number of records to be retrieved at a time. If $number
1592 # is the empty string all remaining records in the result set are
1594 proc present-more {number} {
1595 global setNo setOffset setMax busy cancelFlag delayRequest presentChunk
1597 dputs "present-more"
1599 show-status Retrieving 1 0
1600 set delayRequest "present-more $number"
1606 dputs "setNo=$setNo"
1609 set setOffset [z39.$setNo nextResultSetPosition]
1610 dputs "setOffest=${setOffset}"
1611 dputs "setNo=${setNo}"
1612 set max [z39.$setNo resultCount]
1613 if {$max < $setOffset} {
1615 dputs "setOffset=$setOffset"
1616 show-status Ready 0 1
1619 if {![string length $number]} {
1623 if {$setMax > $max} {
1627 z39 callback {present-response}
1629 set toGet [expr $setMax - $setOffset + 1]
1633 if {$toGet > $presentChunk} {
1634 set toGet $presentChunk
1636 z39.$setNo present $setOffset $toGet
1637 show-status Retrieving 1 0
1640 # Procedure init-title-lines
1641 # Utility that cleans the main record window.
1642 proc init-title-lines {} {
1643 .data.record delete 1.0 end
1646 # Procedure recall-set {setno}
1647 # setno Set number to recall
1648 proc recall-set {setno} {
1649 add-title-lines $setno 10000 1
1652 # Procedure add-title-lines {setno no offset}
1654 # no Number of records
1655 # offset Starting offset
1656 # This procedure displays the records $offset .. $offset+$no-1 in result
1657 # set $setno in the main record window by using the display format in the
1658 # global $displayFormat
1659 proc add-title-lines {setno no offset} {
1660 global displayFormats displayFormat setNo busy
1662 dputs "add-title-lines offset=${offset} no=${no}"
1669 .bot.a.set configure -text $setno
1670 .data.record delete 1.0 end
1672 set ffunc [lindex $displayFormats $displayFormat]
1673 dputs "ffunc=$ffunc"
1674 set ffunc "display-$ffunc"
1675 for {set i 0} {$i < $no} {incr i} {
1676 set o [expr $i + $offset]
1677 set type [z39.$setno type $o]
1678 if {![string length $type]} {
1679 dputs "no more at $o"
1682 .data.record tag bind r$o <Any-Enter> {}
1683 .data.record tag bind r$o <Any-Leave> {}
1684 set insert0 [.data.record index insert]
1685 $ffunc $setno $o .data.record 1
1686 .data.record tag add r$o $insert0 insert
1687 .data.record tag bind r$o <1> [list popup-marc $setno $o 0 0]
1691 show-status Ready 0 1
1695 # Procedure present-response
1696 # Present-response handler. The incoming records are displayed and a new
1697 # present request is performed until all records ($setMax) is returned
1699 proc present-response {} {
1700 global setNo setOffset setMax cancelFlag delayRequest presentChunk
1702 dputs "In present-response"
1704 set no [z39.$setNo numberOfRecordsReturned]
1705 dputs "Returned $no records, setOffset $setOffset"
1706 add-title-lines $setNo $no $setOffset
1707 set setOffset [expr $setOffset + $no]
1709 dputs "Handling cancel"
1711 if {$delayRequest != ""} {
1716 set status [z39.$setNo responseStatus]
1717 if {![string compare [lindex $status 0] NSD]} {
1718 show-status Ready 0 1
1719 set code [lindex $status 1]
1720 set msg [lindex $status 2]
1721 set addinfo [lindex $status 3]
1722 tkerror "NSD$code: $msg: $addinfo"
1725 if {$no > 0 && $setOffset <= $setMax} {
1726 dputs "present-request from ${setOffset}"
1727 set toGet [expr $setMax - $setOffset + 1]
1728 if {$toGet > $presentChunk} {
1729 set toGet $presentChunk
1731 z39.$setNo present $setOffset $toGet
1733 show-status Ready 0 1
1737 # Procedure left-cursor {w}
1739 # Tries to move the cursor left in entry window $w
1740 proc left-cursor {w} {
1741 set i [$w index insert]
1749 # Procedure right-cursor {w}
1751 # Tries to move the cursor right in entry window $w
1752 proc right-cursor {w} {
1753 set i [$w index insert]
1759 # Procedure bind-fields {list returnAction escapeAction}
1760 # list list of entry widgets
1761 # returnAction return script
1762 # escapeAction escape script
1763 # Each widget in list are assigned bindings for <Tab>, <Left>, <Right>,
1764 # <Return> and <Escape>.
1765 proc bind-fields {list returnAction escapeAction} {
1766 set max [expr [llength $list]-1]
1767 for {set i 0} {$i < $max} {incr i} {
1768 bind [lindex $list $i] <Return> $returnAction
1769 bind [lindex $list $i] <Escape> $escapeAction
1770 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
1771 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1772 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1774 bind [lindex $list $i] <Return> $returnAction
1775 bind [lindex $list $i] <Escape> $escapeAction
1776 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
1777 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1778 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1779 focus [lindex $list 0]
1782 # Procedure entry-fields {parent list tlist returnAction escapeAction}
1783 # list list of frame widgets
1784 # tlist list of text to be used as lead of each entry
1785 # returnAction return script
1786 # escapeAction escape script
1787 # Makes label and entry widgets in each widget in $list.
1788 proc entry-fields {parent list tlist returnAction escapeAction} {
1791 foreach field $list {
1792 set label ${parent}.${field}.label
1793 set entry ${parent}.${field}.entry
1794 label $label -text [lindex $tlist $i] -anchor e
1795 entry $entry -width 32 -relief sunken
1796 pack $label -side left
1797 pack $entry -side right
1798 lappend alist $entry
1801 bind-fields $alist $returnAction $escapeAction
1804 # Procedure define-target-dialog
1805 # Dialog that asks for new target to be defined.
1806 proc define-target-dialog {} {
1807 set w .target-define
1813 pack $w.top.target -side top -anchor e -pady 2
1814 entry-fields $w.top {target} {{Target:}} \
1815 {define-target-action} {destroy .target-define}
1816 top-down-ok-cancel $w {define-target-action} 1
1819 # Procedure place-force {window parent}
1820 # window new top level widget
1821 # parent parent widget used as base
1822 # Sets geometry of $window relative to $parent window.
1823 proc place-force {window parent} {
1824 set g [wm geometry $parent]
1825 set p1 [string first + $g]
1826 set p2 [string last + $g]
1827 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
1828 set y [expr 60+[string range $g [expr $p2 +1] end]]
1829 wm geometry $window +${x}+${y}
1832 # Procedure add-database-action {target w}
1833 # target target to be defined
1834 # w top level widget for the target definition
1835 # Adds the contents of .database-select.top.database.entry to list of
1837 proc add-database-action {target w} {
1840 $w.top.databases.list insert end [.database-select.top.database.entry get]
1841 destroy .database-select
1844 # Procedure add-database {target wp}
1845 # target target to be defined
1846 # wp top level widget for the target definition
1847 # Makes a dialog in which the user enters new database
1848 proc add-database {target wp} {
1851 set w .database-select
1853 set oldFocus [focus]
1856 frame $w.top.database
1857 pack $w.top.database -side top -anchor e -pady 2
1858 entry-fields $w.top {database} {{Database to add:}} \
1859 [list add-database-action $target $wp] {destroy .database-select}
1861 top-down-ok-cancel $w [list add-database-action $target $wp] 1
1866 # Procedure delete-database {target w}
1867 # target target to be defined
1868 # w top level widget for the target definition
1869 # Asks the user if he/she really wishes to delete a database and removes
1870 # the database from the database-list if requested.
1871 proc delete-database {target w} {
1875 foreach i [$w.top.databases.list curselection] {
1876 set b [$w.top.databases.list get $i]
1879 set a [alert "Are you sure you want to remove the database(s)${l}?"]
1881 foreach i [lsort -decreasing \
1882 [$w.top.databases.list curselection]] {
1883 $w.top.databases.list delete $i
1888 # Procedure advanced-setup {target b}
1889 # target target to be defined
1890 # b window number of target top level
1891 # Makes a dialog in which the user may modify/view advanced settings
1892 # of a target definition (profile).
1893 proc advanced-setup {target b} {
1894 global profile profileS
1896 set w .advanced-setup-$b
1898 wm title $w "Advanced setup $target"
1900 if {![string length $target]} {
1905 frame $w.top.largeSetLowerBound
1906 frame $w.top.smallSetUpperBound
1907 frame $w.top.mediumSetPresentNumber
1908 frame $w.top.presentChunk
1909 frame $w.top.maximumRecordSize
1910 frame $w.top.preferredMessageSize
1912 pack $w.top.largeSetLowerBound $w.top.smallSetUpperBound \
1913 $w.top.mediumSetPresentNumber $w.top.presentChunk \
1914 $w.top.maximumRecordSize $w.top.preferredMessageSize \
1915 -side top -anchor e -pady 2
1917 entry-fields $w.top {largeSetLowerBound smallSetUpperBound \
1918 mediumSetPresentNumber presentChunk maximumRecordSize \
1919 preferredMessageSize} \
1920 {{Large Set Lower Bound:} {Small Set Upper Bound:} \
1921 {Medium Set Present Number:} {Present Chunk:} \
1922 {Maximum Record Size:} {Preferred Message Size:}} \
1923 [list advanced-setup-action $target $b] [list destroy $w]
1925 $w.top.largeSetLowerBound.entry configure -textvariable \
1926 profileS($target,largeSetLowerBound)
1927 $w.top.smallSetUpperBound.entry configure -textvariable \
1928 profileS($target,smallSetUpperBound)
1929 $w.top.mediumSetPresentNumber.entry configure -textvariable \
1930 profileS($target,mediumSetPresentNumber)
1931 $w.top.presentChunk.entry configure -textvariable \
1932 profileS($target,presentChunk)
1933 $w.top.maximumRecordSize.entry configure -textvariable \
1934 profileS($target,maximumRecordSize)
1935 $w.top.preferredMessageSize.entry configure -textvariable \
1936 profileS($target,preferredMessageSize)
1938 bottom-buttons $w [list {Ok} [list advanced-setup-action $target $b] \
1939 {Cancel} [list destroy $w]] 0
1942 # Procedure advanced-setup-action {target b}
1943 # target target to be defined
1944 # b window number of target top level
1945 # This procedure is called when the user hits Ok in the advanced target
1946 # setup dialog. The temporary result is stored in the $profileS - array.
1947 proc advanced-setup-action {target b} {
1948 set w .advanced-setup-$b
1951 set profileS($target,LSLB) [$w.top.largeSetLowerBound.entry get]
1952 set profileS($target,SSUB) [$w.top.smallSetUpperBound.entry get]
1953 set profileS($target,MSPN) [$w.top.mediumSetPresentNumber.entry get]
1954 set profileS($target,presentChunk) [$w.top.presentChunk.entry get]
1955 set profileS($target,MRS) [$w.top.maximumRecordSize.entry get]
1956 set profileS($target,PMS) [$w.top.preferredMessageSize.entry get]
1958 dputs "advanced-setup-action"
1962 # Procedure database-select-action
1963 # Called when the user commits a database select change. See procedure
1965 proc database-select-action {} {
1966 set w .database-select.top
1968 foreach indx [$w.databases.list curselection] {
1969 lappend b [$w.databases.list get $indx]
1972 z39 databaseNames $b
1974 destroy .database-select
1977 # Procedure database-select
1978 # Makes a dialog in which the user may select a database
1979 proc database-select {} {
1980 set w .database-select
1981 global profile hostid
1984 set oldFocus [focus]
1988 frame $w.top.databases -relief ridge -border 2
1989 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
1991 label $w.top.databases.label -text "List"
1992 listbox $w.top.databases.list -width 20 -height 6 \
1993 -yscrollcommand "$w.top.databases.scroll set"
1994 scrollbar $w.top.databases.scroll -orient vertical -border 1
1995 pack $w.top.databases.label -side top -fill x -padx 2 -pady 2
1996 pack $w.top.databases.list -side left -fill both -expand yes -padx 2 -pady 2
1997 pack $w.top.databases.scroll -side right -fill y -padx 2 -pady 2
1998 $w.top.databases.scroll config -command "$w.top.databases.list yview"
2000 foreach b $profile($hostid,databases) {
2001 $w.top.databases.list insert end $b
2003 top-down-ok-cancel $w {database-select-action} 1
2007 # Procedure cascase-dblist-select
2008 proc cascade-dblist-select {target db} {
2009 show-target $target $db
2010 z39 databaseNames $db
2011 ready-response-actions $target $db
2014 # Procedure cascade-dblist
2015 # Makes the Service/database list with proper databases for the target
2016 proc cascade-dblist {target base} {
2019 set w .top.service.m.dblist
2021 if {[info exists profile($target,databases)]} {
2022 foreach db $profile($target,databases) {
2023 $w add command -label $db \
2024 -command [list cascade-dblist-select $target $db]
2029 # Procedure cascade-target-list
2030 # Makes all target/databases available in the Target|Connect
2031 # menu as well as all targets in the Target|Setup menu.
2032 # This procedure is called whenever target definitions occur.
2033 proc cascade-target-list {} {
2036 foreach sub [winfo children .top.target.m.clist] {
2039 .top.target.m.clist delete 0 last
2040 foreach nn [lsort [array names profile *,host]] {
2041 if {[string length $profile($nn)]} {
2042 set ll [expr [string length $nn] - 6]
2043 set n [string range $nn 0 $ll]
2045 set nl $profile($n,windowNumber)
2046 if {[info exists profile($n,databases)]} {
2047 set ndb [llength $profile($n,databases)]
2052 .top.target.m.clist add cascade -label $n \
2053 -menu .top.target.m.clist.$nl
2054 irmenu .top.target.m.clist.$nl
2055 foreach b $profile($n,databases) {
2056 .top.target.m.clist.$nl add command -label $b \
2057 -command [list reopen-target $n $b]
2059 } elseif {$ndb == 1} {
2060 .top.target.m.clist add command -label $n -command \
2061 [list reopen-target $n [lindex $profile($n,databases) 0]]
2063 .top.target.m.clist add command -label $n -command \
2064 [list reopen-target $n {}]
2068 .top.target.m.slist delete 0 last
2069 foreach nn [lsort [array names profile *,host]] {
2070 set ll [expr [string length $nn] - 6]
2071 set n [string range $nn 0 $ll]
2072 .top.target.m.slist add command -label $n -command [list protocol-setup $n]
2076 # Procedure query-select {i}
2077 # i Query type number (integer)
2078 # This procedure is called when the user selects a Query type. The current
2079 # query type information given by the globals $queryButtonsFind and
2080 # $queryInfoFind are affected by this operation.
2081 proc query-select {i} {
2082 global queryButtonsFind queryInfoFind queryButtons queryInfo queryAuto queryAutoOld hostid currentDb profile
2084 if {$queryAutoOld == 1 && $queryAuto == 0} {
2085 set queryAutoOld $queryAuto
2088 if {$queryAutoOld == 0 && $queryAuto == 1 && [info exists profile($hostid,AttributeDetails,$currentDb,Bib1Use)] == 0} {
2089 set queryAutoOld $queryAuto
2092 set queryInfoFind [lindex $queryInfo $i]
2093 set queryButtonsFind [lindex $queryButtons $i]
2094 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2097 # Procedure query-new-action
2098 # Commits a new query type definition by extending the globals
2099 # $queryTypes, $queryButtons and $queryInfo.
2100 proc query-new-action {} {
2101 global queryTypes queryButtons queryInfo settingsChanged
2103 set settingsChanged 1
2104 lappend queryTypes [.query-new.top.index.entry get]
2105 lappend queryButtons {}
2106 lappend queryInfo {}
2112 # Procedure query-new
2113 # Makes a dialog in which the user is requested to enter the name of a
2119 set oldFocus [focus]
2123 pack $w.top.index -side top -anchor e -pady 2
2124 entry-fields $w.top index {{Query Name:}} \
2125 query-new-action {destroy .query-new}
2126 top-down-ok-cancel $w query-new-action 1
2130 # Procedure query-delete-action {queryNo}
2131 # queryNo query type number (integer)
2132 # Procedure that deletes the query type specified by $queryNo.
2133 proc query-delete-action {queryNo} {
2134 global queryTypes queryButtons queryInfo settingsChanged
2136 set settingsChanged 1
2138 set queryTypes [lreplace $queryTypes $queryNo $queryNo]
2139 set queryButtons [lreplace $queryButtons $queryNo $queryNo]
2140 set queryInfo [lreplace $queryInfo $queryNo $queryNo]
2141 destroy .query-delete
2145 # Procedure query-delete {queryNo}
2146 # queryNo query type number (integer)
2147 # Asks if the user really want to delete a given query type; calls
2148 # query-delete-action if 'yes'.
2149 proc query-delete {queryNo} {
2157 set n [lindex $queryTypes $queryNo]
2159 label $w.top.warning -bitmap warning
2160 message $w.top.quest -text "Are you sure you want to delete the \
2161 query type $n ?" -aspect 300
2162 pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
2163 bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
2164 {Cancel} [list destroy $w]] 1
2167 # Procedure cascade-query-list
2168 # Updates the entries below Options|Query to list all query types.
2169 proc cascade-query-list {} {
2170 global queryTypes hostid queryAuto
2171 set w .top.options.m.query
2173 $w.clist delete 0 last
2174 foreach n $queryTypes {
2176 $w.clist add check -label $n -variable queryAuto -command [list query-select $i]
2178 $w.clist add command -label $n -command [list query-select $i]
2183 $w.slist delete 0 last
2184 foreach n $queryTypes {
2186 if {$hostid == "Default"} {
2187 $w.slist add command -label $n -state disabled -command [list query-setup $i]
2189 $w.slist add command -label $n -command [list query-setup $i]
2192 $w.slist add command -label $n -command [list query-setup $i]
2197 $w.dlist delete 0 last
2198 foreach n $queryTypes {
2199 $w.dlist add command -label $n -command [list query-delete $i]
2204 # Procedure save-geometry
2205 # This procedure saves the per-user related settings in ~/.clientrc.tcl.
2206 # The geometry information stored in the global array $windowGeometry is
2207 # saved. Also a few other user settings, such as current display format, are
2209 proc save-geometry {} {
2210 global windowGeometry hotTargets textWrap displayFormat popupMarcdf \
2211 recordSyntax elementSetNames hostid
2213 set windowGeometry(.) [wm geometry .]
2215 if {[catch {set f [open ~/.clientrc.tcl w]}]} {
2218 if {$hostid != "Default"} {
2219 puts $f "set hostid [list $hostid]"
2220 set b [z39 databaseNames]
2221 puts $f "set hostbase [list $b]"
2223 puts $f "set hotTargets [list $hotTargets]"
2224 puts $f "set textWrap $textWrap"
2225 puts $f "set displayFormat $displayFormat"
2226 puts $f "set popupMarcdf $popupMarcdf"
2227 puts $f "set recordSyntax $recordSyntax"
2228 puts $f "set elementSetNames $elementSetNames"
2229 foreach n [array names windowGeometry] {
2230 puts -nonewline $f "set [list windowGeometry($n)] "
2231 puts $f [list $windowGeometry($n)]
2236 # Procedure save-settings
2237 # This procedure saves the per-host related settings irtdb.tcl which
2238 # is normally kept in the directory /usr/local/lib/irtcl.
2239 # All query types and target defintion profiles are saved.
2240 proc save-settings {} {
2241 global profile libdir settingsChanged queryTypes queryButtons queryInfo queryAuto
2243 if {[file writable "${libdir}/irtdb.tcl"]} {
2244 set f [open "${libdir}/irtdb.tcl" w]
2246 set f [open "irtdb.tcl" w]
2248 puts $f "# Setup file"
2249 foreach n [lsort [array names profile]] {
2250 puts $f "set [list profile($n)] [list $profile($n)]"
2252 puts $f "set queryTypes [list $queryTypes]"
2253 puts $f "set queryButtons [list $queryButtons]"
2254 puts $f "set queryInfo [list $queryInfo]"
2255 puts $f "set queryAuto [list $queryAuto]"
2257 set settingsChanged 0
2260 # Procedure alert {ask}
2262 # Makes a grabbed dialog in which the user is requested to answer
2263 # "Ok" or "Cancel". This procedure returns 1 if the user hits "Ok"; 0
2268 global alertAnswer font
2271 set oldFocus [focus]
2275 label $w.top.warning -bitmap warning
2276 message $w.top.message -text $ask -aspect 300 -font $font(b,normal)
2277 pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
2280 top-down-ok-cancel $w {alert-action} 1
2285 # Procedure alert-action
2286 # Called when the user hits "Ok" in the .alert-window.
2287 proc alert-action {} {
2293 # Procedure exit-action
2294 # This procedure is called if the user exists the application
2295 proc exit-action {} {
2296 global settingsChanged
2298 if {$settingsChanged} {
2305 # Procedure listbuttonaction {w name h user i}
2306 # w menubutton widget
2307 # name name information
2308 # h handler to be invoked
2309 # user user information to be passed to handler $h
2310 # i index passed as second argument to handler $h
2311 # Utility function to emulate a listbutton. Called when the user
2312 # Modifies the listbutton. See procedure listbuttonx.
2313 proc listbuttonaction {w name h user i} {
2314 $w configure -text [lindex $name 0]
2315 $h [lindex $name 1] $user $i
2318 # Procedure listbuttonx {button no names handle user}
2319 # button menubutton widget
2320 # no initial value index (integer)
2321 # names list of name entries. The first entry in each name
2322 # entry is the actual name
2323 # handle user function to be called when the listbutton changes
2325 # user user argument to the $handle function
2326 # Makes an extended listbutton.
2327 proc listbuttonx {button no names handle user} {
2328 if {[winfo exists $button]} {
2329 $button configure -text [lindex [lindex $names $no] 0]
2330 ${button}.m delete 0 last
2332 menubutton $button -text [lindex [lindex $names $no] 0] \
2333 -width 10 -menu ${button}.m -relief raised -border 1
2335 ${button}.m configure -tearoff off
2338 foreach name $names {
2339 ${button}.m add command -label [lindex $name 0] \
2340 -command [list listbuttonaction ${button} $name $handle $user $i]
2345 # Procedure listbutton {button no names}
2346 # button menubutton widget
2347 # no initial value index (integer)
2348 # names list of possible values.
2349 # Makes a listbutton. The functionality is emulated by the use menubutton-
2351 proc listbutton {button no names} {
2352 menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
2353 -relief raised -border 1
2355 ${button}.m configure -tearoff off
2356 foreach name $names {
2357 ${button}.m add command -label $name \
2358 -command [list ${button} configure -text $name]
2362 # Procedure listbuttonv-action {button var names i}
2363 # button menubutton widget
2364 # var global variable to be affected
2365 # names list of possible names and values
2366 # This procedure is called when the user alters a menu created by the
2367 # listbuttonv procedure. The global variable $var is updated.
2368 proc listbuttonv-action {button var names i} {
2371 set $var [lindex $names [expr $i+1]]
2372 $button configure -text [lindex $names $i]
2375 # Procedure listbuttonv {button var names}
2376 # button menubutton widget
2377 # var global variable to be affected
2378 # names List of name/value pairs, i.e. {n1 v1 n2 v2 ...}.
2379 # This procedure emulates a listbutton by means of menu/menubutton widgets.
2380 # The global variable $var is automatically updated and set to one of the
2381 # values v1, v2, ...
2382 proc listbuttonv {button var names} {
2386 eval "set val $$var"
2387 set l [llength $names]
2388 for {set i 1} {$i < $l} {incr i 2} {
2389 if {$val == [lindex $names $i]} {
2391 set n [lindex $names $i]
2395 if {[winfo exists $button]} {
2396 $button configure -text $n
2399 menubutton $button -text $n -menu ${button}.m -relief raised -border 1
2401 ${button}.m configure -tearoff off
2402 for {set i 0} {$i < $l} {incr i 2} {
2403 ${button}.m add command -label [lindex $names $i] \
2404 -command [list listbuttonv-action $button $var $names $i]
2408 # Procedure query-add-index-action {queryNo}
2409 # queryNo query type number (integer)
2410 # Handler that makes a new query index.
2411 proc query-add-index-action {queryNo} {
2414 global queryInfoTmp queryButtonsTmp
2416 set newI [.query-add-index.top.index.entry get]
2417 lappend queryInfoTmp [list $newI {}]
2418 $w.top.index.list insert end $newI
2419 destroy .query-add-index
2420 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2423 # Procedure query-add-line
2424 # queryNo query type number (integer)
2425 # Handler that adds new query line.
2426 proc query-add-line {queryNo} {
2429 global queryInfoTmp queryButtonsTmp
2431 lappend queryButtonsTmp {I 0}
2433 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2436 # Procedure query-del-line
2437 # queryNo query type number (integer)
2438 # Handler that removes query line.
2439 proc query-del-line {queryNo} {
2442 global queryInfoTmp queryButtonsTmp
2444 set l [llength $queryButtonsTmp]
2449 set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
2450 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2453 # Procedure query-add-index
2454 # queryNo query type number (integer)
2455 # Handler that adds new query index.
2456 proc query-add-index {queryNo} {
2457 set w .query-add-index
2460 set oldFocus [focus]
2461 place-force $w .query-setup
2464 pack $w.top.index -side top -anchor e -pady 2
2465 entry-fields $w.top {index} {{Index Name:}} \
2466 [list query-add-index-action $queryNo] [list destroy $w]
2467 top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
2471 # Procedure query-setup-action
2472 # queryNo query type number (integer)
2473 # Handler that updates the query information database stored in the
2474 # globals $queryInfo and $queryButtons. This procedure is executed when
2475 # the user commits the query setup changes by pressing button "Ok".
2476 proc query-setup-action {queryNo} {
2477 global queryButtons queryInfo queryButtonsTmp queryInfoTmp queryButtonsFind \
2478 queryInfoFind settingsChanged hostid currentDb profile
2479 set settingsChanged 1
2480 set queryInfo [lreplace $queryInfo $queryNo $queryNo $queryInfoTmp]
2481 set queryButtons [lreplace $queryButtons $queryNo $queryNo $queryButtonsTmp]
2482 if {[info exists profile($hostid,AttributeDetails,$currentDb,Bib1Use)]} {
2483 set profile($hostid,queryButtons,$currentDb) $queryButtonsTmp
2485 set queryInfoFind $queryInfoTmp
2486 set queryButtonsFind $queryButtonsTmp
2487 destroy .query-setup
2488 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2491 #proc changeQueryButtons {target base}
2494 #Substitutes the third element (the Auto element) in queryButtons with
2495 #profile(target,queryButtons,base). The third element in queryInfo is also substituted with
2496 #profile(target,AttributeDetails,base,Bib1Use)
2497 proc changeQueryButtons {target base} {
2499 global profile queryButtons queryInfo
2500 if {[info exists profile($target,queryButtons,$base)]} {
2501 set queryButtons [lreplace $queryButtons 2 2 $profile($target,queryButtons,$base)]
2502 foreach tag $profile($target,AttributeDetails,$base,Bib1Use) {
2504 lappend tempList [list $bib1($tag) 1=$tag]
2507 set queryInfo [lreplace $queryInfo 2 2 $tempList]
2511 # Procedure activate-e-index {value no i}
2513 # no query index number
2514 # i menu index (integer)
2515 # Procedure called when listbutton is activated in the query type edit
2516 # window. The global $queryButtonsTmp is updated in this operation.
2517 proc activate-e-index {value no i} {
2518 global queryButtonsTmp queryIndexTmp
2519 set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
2520 dputs $queryButtonsTmp
2521 set queryIndexTmp $i
2524 # Procedure activate-index {value no i}
2526 # no query index number
2527 # i menu index (integer)
2528 # Procedure called when listbutton is activated in the main query
2529 # window. The global $queryButtonsFind is updated in this operation.
2530 proc activate-index {value no i} {
2531 global queryButtonsFind
2533 set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
2534 dputs "queryButtonsFind $queryButtonsFind"
2537 # Procedure update-attr
2538 # This procedure creates listbuttons for all bib-1 attributes except
2539 # the use-attribute in the .index-setup window.
2540 # The globals $relationTmpValue, $positionTmpValue, $structureTmpValue,
2541 # $truncationTmpValue and $completenessTmpValue are maintainted by the
2543 proc update-attr {} {
2545 listbuttonv $w.top.relation.b relationTmpValue\
2546 {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
2547 {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
2548 {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
2549 listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
2550 {First in field} 1 {First in subfield} 2 {Any position in field} 3}
2551 listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
2552 {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list} 6 \
2553 {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
2554 {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
2555 {local-number} 107 {string} 108 {numeric string} 109}
2556 listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
2557 {Left} 2 {Left and right} 3 {No truncation} 100 \
2558 {Process #} 101 {Re-1} 102 {Re-2} 103}
2559 listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
2560 {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
2563 # Procedure use-attr {init}
2565 # This procedure creates a listbox with several Bib-1 use attributes.
2566 # If $init is 1 the listbox is created with the attributes. If $init
2567 # is 0 the current selection of the listbox is read and the global
2568 # $useTmpValue is set to the current use-value.
2569 proc use-attr {init} {
2581 {BNB card number} 10
2582 {BGF(sic) number} 11
2584 {Dewey classification} 13
2585 {UDC classification} 14
2586 {Bliss classification} 15
2588 {NLM call number} 17
2589 {NAL call number} 18
2590 {MOS call number} 19
2591 {Local classification} 20
2592 {Subject heading} 21
2594 {BDI-index-subject} 23
2598 {LC-subject-heading} 27
2599 {RVM-subject-heading} 28
2600 {Local subject index} 29
2602 {Date of publication} 31
2603 {Date of acquisition} 32
2605 {Title-collective} 34
2608 {Title-added-title-page} 37
2612 {Title-other-variant} 41
2614 {Title-abbreviated} 43
2618 {Subject-subdivision} 47
2619 {Number-natl-bibliography} 48
2620 {Number-legal-deposit} 49
2621 {Number-govt-publication} 50
2622 {Number-publisher-for-music} 51
2624 {Number-local-call} 53
2626 {Code-geographic-area} 55
2627 {Code-institution} 56
2629 {Name-geographic} 58
2630 {Place-publication} 59
2632 {Microform-generation} 61
2639 {Author-name-personal} 1004
2640 {Author-name-corporate} 1005
2641 {Author-name-conference} 1006
2642 {Identifier-standard} 1007
2643 {Subject-LC-children's} 1008
2644 {Subject-name-personal} 1009
2646 {Date/time added to database} 1011
2647 {Date/time last modified} 1012
2648 {Authority/format identifier} 1013
2650 {Concept-reference} 1015
2652 {Server choice} 1017
2654 {Record source} 1019
2657 {Geographic class} 1022
2661 {Related periodical} 1026
2662 {Report number} 1027
2664 {Thematic number} 1030
2665 {Material type} 1031
2673 set l [llength $attr]
2678 for {set i 0} {$i < $l} {incr i} {
2679 $w.top.use.list insert end [lindex $attr $i]
2681 if {$useTmpValue == [lindex $attr $i]} {
2686 $w.top.use.list selection clear 0 end
2687 $w.top.use.list selection set $s $s
2692 $w.top.use.list yview $s
2694 set lno [lindex [$w.top.use.list curselection] 0]
2695 set i [expr $lno+$lno+1]
2696 set useTmpValue [lindex $attr $i]
2697 dputs "useTmpValue=$useTmpValue"
2701 # Procedure index-setup-action {oldAttr queryNo indexNo}
2702 # oldAttr original attributes (?)
2703 # queryNo query number
2704 # indexNo index number
2705 # Commits setup of a query index. The mapping from the index to
2706 # the Bib-1 attributes are handled by this function.
2707 proc index-setup-action {oldAttr queryNo indexNo} {
2708 set attr [lindex $oldAttr 0]
2710 global useTmpValue relationTmpValue structureTmpValue truncationTmpValue \
2711 completenessTmpValue positionTmpValue queryInfoTmp
2715 dputs "index-setup-action"
2716 dputs "queryNo $queryNo"
2717 dputs "indexNo $indexNo"
2718 if {$useTmpValue > 0} {
2719 lappend attr "1=$useTmpValue"
2721 if {$relationTmpValue > 0} {
2722 lappend attr "2=$relationTmpValue"
2724 if {$positionTmpValue > 0} {
2725 lappend attr "3=$positionTmpValue"
2727 if {$structureTmpValue > 0} {
2728 lappend attr "4=$structureTmpValue"
2730 if {$truncationTmpValue > 0} {
2731 lappend attr "5=$truncationTmpValue"
2733 if {$completenessTmpValue > 0} {
2734 lappend attr "6=$completenessTmpValue"
2736 dputs "new attr $attr"
2737 set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
2738 destroy .index-setup
2741 # Procedure index-setup {attr queryNo indexNo}
2742 # attr original attributes
2743 # queryNo query number
2744 # indexNo index number
2745 # Makes a window with settings of a given query index which the user
2746 # may inspect/modify.
2747 proc index-setup {attr queryNo indexNo} {
2750 global relationTmpValue structureTmpValue truncationTmpValue \
2751 completenessTmpValue positionTmpValue useTmpValue
2752 set relationTmpValue 0
2753 set truncationTmpValue 0
2754 set structureTmpValue 0
2755 set positionTmpValue 0
2756 set completenessTmpValue 0
2762 set n [lindex $attr 0]
2763 wm title $w "Index setup $n"
2767 set len [llength $attr]
2768 for {set i 1} {$i < $len} {incr i} {
2769 set q [lindex $attr $i]
2770 set l [string first = $q]
2772 set t [string range $q 0 [expr $l - 1]]
2773 set v [string range $q [expr $l + 1] end]
2776 { set useTmpValue $v }
2778 { set relationTmpValue $v }
2780 { set positionTmpValue $v }
2782 { set structureTmpValue $v }
2784 { set truncationTmpValue $v }
2786 { set completenessTmpValue $v }
2791 frame $w.top.use -relief ridge -border 2
2792 frame $w.top.relation -relief ridge -border 2
2793 frame $w.top.position -relief ridge -border 2
2794 frame $w.top.structure -relief ridge -border 2
2795 frame $w.top.truncation -relief ridge -border 2
2796 frame $w.top.completeness -relief ridge -border 2
2802 pack $w.top.use -side left -pady 6 -padx 6 -fill y
2804 label $w.top.use.label -text "Use"
2805 listbox $w.top.use.list -width 26 -yscrollcommand "$w.top.use.scroll set"
2806 scrollbar $w.top.use.scroll -orient vertical -border 1
2807 pack $w.top.use.label -side top -fill x -padx 2 -pady 2
2808 pack $w.top.use.list -side left -fill both -expand yes -padx 2 -pady 2
2809 pack $w.top.use.scroll -side right -fill y -padx 2 -pady 2
2810 $w.top.use.scroll config -command "$w.top.use.list yview"
2814 # Relation Attributes
2816 pack $w.top.relation -pady 6 -padx 6 -side top
2817 label $w.top.relation.label -text "Relation" -width 18
2819 pack $w.top.relation.label $w.top.relation.b -fill x
2821 # Position Attributes
2823 pack $w.top.position -pady 6 -padx 6 -side top
2824 label $w.top.position.label -text "Position" -width 18
2826 pack $w.top.position.label $w.top.position.b -fill x
2828 # Structure Attributes
2830 pack $w.top.structure -pady 6 -padx 6 -side top
2831 label $w.top.structure.label -text "Structure" -width 18
2833 pack $w.top.structure.label $w.top.structure.b -fill x
2835 # Truncation Attributes
2837 pack $w.top.truncation -pady 6 -padx 6 -side top
2838 label $w.top.truncation.label -text "Truncation" -width 18
2840 pack $w.top.truncation.label $w.top.truncation.b -fill x
2842 # Completeness Attributes
2844 pack $w.top.completeness -pady 6 -padx 6 -side top
2845 label $w.top.completeness.label -text "Completeness" -width 18
2847 pack $w.top.completeness.label $w.top.completeness.b -fill x
2850 bottom-buttons $w [list \
2851 {Ok} [list index-setup-action $attr $queryNo $indexNo] \
2852 {Cancel} [list destroy $w]] 0
2856 # Procedure query-edit-index {queryNo}
2857 # queryNo query number
2858 # Determines if a selection of an index is active. If one is selected
2859 # the index-setup dialog is started.
2860 proc query-edit-index {queryNo} {
2864 set i [lindex [$w.top.index.list curselection] 0]
2865 if {![string length $i]} {
2868 set attr [lindex $queryInfoTmp $i]
2869 dputs "Editing no $i $attr"
2870 index-setup $attr $queryNo $i
2873 # Procedure query-delete-index {queryNo}
2874 # queryNo query number
2875 # Determines if a selection of an index is active. If one is selected
2876 # the index is deleted.
2877 proc query-delete-index {queryNo} {
2878 global queryInfoTmp queryButtonsTmp
2881 set i [lindex [$w.top.index.list curselection] 0]
2882 if {![string length $i]} {
2885 set queryInfoTmp [lreplace $queryInfoTmp $i $i]
2886 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2887 $w.top.index.list delete $i
2890 # Procedure query-setup {queryNo}
2891 # queryNo query number
2892 # Makes a dialog in which a query type an be customized.
2893 proc query-setup {queryNo} {
2896 global queryTypes queryButtons queryInfo queryButtonsTmp queryInfoTmp queryIndexTmp
2899 set queryName [lindex $queryTypes $queryNo]
2900 set queryInfoTmp [lindex $queryInfo $queryNo]
2901 set queryButtonsTmp [lindex $queryButtons $queryNo]
2906 wm title $w "Query setup $queryName"
2910 frame $w.top.lines -relief ridge -border 2
2911 pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2915 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2917 button $w.top.lines.add -text "Add" -command [list query-add-line $queryNo]
2918 button $w.top.lines.del -text "Remove" -command [list query-del-line $queryNo]
2919 pack $w.top.lines.del -fill x -side bottom
2920 pack $w.top.lines.add -fill x -pady 10 -side bottom
2924 frame $w.top.index -relief ridge -border 2
2925 pack $w.top.index -pady 6 -padx 6 -side right -fill y
2927 listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
2928 scrollbar $w.top.index.scroll -orient vertical -border 1 \
2929 -command [list $w.top.index.list yview]
2930 bind $w.top.index.list <Double-1> [list query-edit-index $queryNo]
2932 pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
2933 pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
2935 $w.top.index.list selection clear 0 end
2936 $w.top.index.list selection set 0 0
2937 foreach x $queryInfoTmp {
2938 $w.top.index.list insert end [lindex $x 0]
2942 bottom-buttons $w [list \
2943 Ok [list query-setup-action $queryNo] \
2944 Add [list query-add-index $queryNo] \
2945 Edit [list query-edit-index $queryNo] \
2946 Delete [list query-delete-index $queryNo] \
2947 Cancel [list destroy $w]] 0
2950 # Procedure index-clear
2951 # Handler that clears the search entry fields.
2952 proc index-clear {} {
2953 global queryButtonsFind
2956 foreach b $queryButtonsFind {
2957 .lines.$i.e delete 0 end
2962 # Procedure index-query
2963 # The purpose of this function is to read the user's query and convert
2964 # it to the prefix query that IrTcl/YAZ uses to represent an RPN query.
2965 # Each entry in a search fields takes the form
2967 # Here, relOp is an optional relational operator and one of:
2969 # which sets the Bib-1 relation to greater-than, less-than, etc.
2970 # The ? (question-mark) is also optional. A (?) on left-side indicates
2971 # left truncation; (?) on right-side indicates right-truncation; (?)
2972 # on both sides indicates both-left-and-right truncation.
2973 proc index-query {} {
2974 global queryButtonsFind queryInfoFind
2979 foreach b $queryButtonsFind {
2980 set term [string trim [.lines.$i.e get]]
2982 set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
2985 set len [string length $term]
2989 if {[string index $term 0] == ">"} {
2990 if {[string index $term 1] == "=" } {
2991 set term [string trim [string range $term 2 $len]]
2994 set term [string trim [string range $term 1 $len]]
2997 } elseif {[string index $term 0] == "<"} {
2998 if {[string index $term 1] == "=" } {
2999 set term [string trim [string range $term 2 $len]]
3001 } elseif {[string index $term 1] == ">"} {
3002 set term [string trim [string range $term 2 $len]]
3005 set term [string trim [string range $term 1 $len]]
3010 set len [string length $term]
3014 if {[string index $term $len] == "?"} {
3016 set term [string range $term 0 [expr $len - 1]]
3018 if {[string index $term 0] == "?"} {
3020 set term [string range $term 1 end]
3022 set term "\{${term}\}"
3023 if {$right && $left} {
3024 set term "@attr 5=3 ${term}"
3026 set term "@attr 5=1 ${term}"
3028 set term "@attr 5=2 ${term}"
3030 if {$relation != ""} {
3031 set term "@attr 2=${relation} ${term}"
3034 set term "@attr $a ${term}"
3037 set qs "@and ${qs} ${term}"
3048 # Procedure index-focus-in {w i}
3051 # This procedure handles <FocusIn> events. A red border is drawed
3052 # around the active search entry field when tk3.6 is used (tk4.X
3053 # makes a black focus border itself).
3054 proc index-focus-in {w i} {
3055 global curIndexEntry
3056 $w.$i configure -background red
3057 set curIndexEntry $i
3060 # Procedure index-lines {w readOp buttonInfo queryInfo handle}
3061 # w search fields entry frame
3062 # realOp if true, search-request bindings are bound to the entries.
3063 # buttonInfo query type button information
3064 # queryInfo query type field information
3065 # handle handler called a when a 'listbutton' changes its value
3066 # Makes one or more search areas - with listbuttons on the left
3067 # and entries on the right.
3068 proc index-lines {w realOp buttonInfo queryInfo handle} {
3070 foreach b $buttonInfo {
3071 if {! [winfo exists $w.$i]} {
3072 frame $w.$i -border 0
3074 listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
3077 if {! [winfo exists $w.$i.e]} {
3078 entry $w.$i.e -width 32 -relief sunken -border 1
3079 bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
3080 bind $w.$i.e <FocusOut> [list $w.$i configure -background white]
3081 pack $w.$i.l -side left
3082 pack $w.$i.e -side left -fill x -expand yes
3083 pack $w.$i -side top -fill x -padx 2 -pady 2
3084 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
3085 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
3086 bind $w.$i.e <Return> {search-request 0}
3089 pack $w.$i.l -side left
3090 pack $w.$i -side top -fill x -padx 2 -pady 2
3095 while {[winfo exists $w.$j]} {
3106 bind $w.$j.e <Tab> "focus $w.$k.e"
3110 bind $w.$i.e <Tab> "focus $w.0.e"
3115 # Procedure search-fields {w buttondefs}
3116 # w search fields entry frame
3117 # buttondefs button definitions
3118 # Makes search entry fields and listbuttons.
3119 # Note: This procedure is not used elsewhere. The index-lines
3120 # procedure is used instead.
3121 proc search-fields {w buttondefs} {
3123 foreach buttondef $buttondefs {
3124 frame $w.$i -background white
3126 listbutton $w.$i.l 0 $buttondef
3127 entry $w.$i.e -width 32 -relief sunken
3129 pack $w.$i.l -side left
3130 pack $w.$i.e -side left -fill x -expand yes
3131 pack $w.$i -side top -fill x -padx 2 -pady 2
3133 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
3134 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
3142 bind $w.$j.e <Tab> "focus $w.$k.e \n
3143 $w.$k configure -background red \n
3144 $w.$j configure -background white"
3147 bind $w.$i.e <Tab> "focus $w.0.e \n
3148 $w.0 configure -background red \n
3149 $w.$i configure -background white"
3151 $w.0 configure -background red
3154 #Procedure configureOptionsSyntax {target base}
3157 #Changes the Options|Syntax menu acording to the information obtained via explain.
3158 proc configureOptionsSyntax {target base} {
3159 global profile syntaxList
3162 if {[info exists profile($target,RecordSyntaxes,$base)]} {
3163 foreach syntax $syntaxList {
3165 if {$syntax == "sep"} {continue}
3166 .top.options.m.syntax entryconfigure $i -variable 0
3167 if {[lsearch $profile($target,RecordSyntaxes,$base) $syntax] != -1} {
3168 configure-enable-e .top.options.m.syntax $i
3169 if {$activate == 0} {
3170 .top.options.m.syntax invoke $i
3174 configure-disable-e .top.options.m.syntax $i
3178 foreach syntax $syntaxList {
3180 if {$syntax == "sep"} {continue}
3181 configure-enable-e .top.options.m.syntax $i
3183 .top.options.m.syntax invoke 0
3187 # Init: The geometry information for the main window is set - either
3188 # to a default value or to the value in windowGeometry(.)
3189 if {[catch {set g $windowGeometry(.)}]} {
3190 wm geometry . 420x340
3195 # Init: Presentation formats are read.
3198 # Init: The main window is defined.
3199 frame .top -border 1 -relief raised
3200 frame .lines -border 1 -relief raised
3201 frame .mid -border 1 -relief raised
3202 frame .data -border 1 -relief raised
3203 frame .bot -border 1 -relief raised
3204 pack .top .lines .mid -side top -fill x
3205 pack .data -side top -fill both -expand yes
3208 # Init: Definition of File menu.
3209 menubutton .top.file -text File -menu .top.file.m
3211 .top.file.m add command -label {Save settings} -command {save-settings}
3212 .top.file.m add separator
3213 .top.file.m add command -label Exit -command {exit-action}
3215 # Init: Definition of Target menu.
3216 menubutton .top.target -text Target -menu .top.target.m
3217 irmenu .top.target.m
3218 .top.target.m add cascade -label Connect -menu .top.target.m.clist
3219 .top.target.m add command -label Disconnect -command {close-target}
3220 .top.target.m add command -label About -command {about-target}
3221 .top.target.m add cascade -label Setup -menu .top.target.m.slist
3222 .top.target.m add command -label {Setup new} -command {define-target-dialog}
3223 .top.target.m add separator
3224 set-target-hotlist 0
3226 configure-disable-e .top.target.m 1
3227 configure-disable-e .top.target.m 2
3229 irmenu .top.target.m.clist
3230 irmenu .top.target.m.slist
3233 # Init: Definition of Service menu.
3234 menubutton .top.service -text Service -menu .top.service.m
3235 irmenu .top.service.m
3236 .top.service.m add cascade -label Database -menu .top.service.m.dblist
3237 .top.service.m add cascade -label Present -menu .top.service.m.present
3238 irmenu .top.service.m.present
3239 .top.service.m.present add command -label {10 More} -command [list present-more 10]
3240 .top.service.m.present add command -label All -command [list present-more {}]
3241 .top.service.m add command -label Search -command {search-request 0}
3242 .top.service.m add command -label Scan -command {scan-request}
3243 .top.service.m add command -label Explain -command \
3244 {explain-refresh $hostid {ready-response {}} }
3246 .top.service configure -state disabled
3248 irmenu .top.service.m.dblist
3250 # Init: Definition of Set menu.
3251 menubutton .top.rset -text Set -menu .top.rset.m
3253 .top.rset.m add command -label Load -command {load-set}
3254 .top.rset.m add separator
3256 # Init: Definition of the Options menu.
3257 menubutton .top.options -text Options -menu .top.options.m
3258 irmenu .top.options.m
3259 .top.options.m add cascade -label Query -menu .top.options.m.query
3260 .top.options.m add cascade -label Format -menu .top.options.m.formats
3261 .top.options.m add cascade -label Wrap -menu .top.options.m.wrap
3262 .top.options.m add cascade -label Syntax -menu .top.options.m.syntax
3263 .top.options.m add cascade -label Elements -menu .top.options.m.elements
3264 .top.options.m add radiobutton -label Debug -variable debugMode -value 1
3266 # Init: Definition of the Options|Query menu.
3267 irmenu .top.options.m.query
3268 .top.options.m.query add cascade -label Select -menu .top.options.m.query.clist
3269 .top.options.m.query add cascade -label Edit -menu .top.options.m.query.slist
3270 .top.options.m.query add command -label New -command {query-new}
3271 .top.options.m.query add cascade -label Delete -menu .top.options.m.query.dlist
3273 irmenu .top.options.m.query.slist
3274 irmenu .top.options.m.query.clist
3275 irmenu .top.options.m.query.dlist
3278 # Init: Definition of the Options|Formats menu.
3279 irmenu .top.options.m.formats
3281 foreach f $displayFormats {
3282 .top.options.m.formats add radiobutton -label $f -value $i \
3283 -command [list set-display-format $i] -variable displayFormat
3287 # Init: Definition of the Options|Wrap menu.
3288 irmenu .top.options.m.wrap
3289 .top.options.m.wrap add radiobutton -label Character \
3290 -value char -variable textWrap -command {set-wrap char}
3291 .top.options.m.wrap add radiobutton -label Word \
3292 -value word -variable textWrap -command {set-wrap word}
3293 .top.options.m.wrap add radiobutton -label None \
3294 -value none -variable textWrap -command {set-wrap none}
3296 # Init: Definition of the Options|Syntax menu.
3297 proc initOptionsSyntax {} {
3299 set w .top.options.m.syntax
3301 foreach syntax $syntaxList {
3302 if {$syntax == "sep"} {
3305 $w add radiobutton -label $syntax -value $syntax -variable recordSyntax
3311 # Init: Definition of the Options|Elements menu.
3312 irmenu .top.options.m.elements
3313 .top.options.m.elements add radiobutton -label Unspecified \
3314 -value None -variable elementSetNames
3315 .top.options.m.elements add radiobutton -label Full \
3316 -value F -variable elementSetNames
3317 .top.options.m.elements add radiobutton -label Brief -value B -variable elementSetNames
3319 # Init: Definition of Help menu.
3320 menubutton .top.help -text "Help" -menu .top.help.m
3323 .top.help.m add command -label "Help on help" \
3324 -command {tkerror "Help on help not available. Sorry"}
3325 .top.help.m add command -label "About" -command {about-origin}
3327 # Init: Pack menu bar items.
3328 pack .top.file .top.target .top.service .top.rset .top.options -side left
3329 pack .top.help -side right
3331 # Init: Define query area.
3332 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
3333 image create photo scan -file ${libdir}/bitmaps/a-z.gif
3334 image create photo clear -file ${libdir}/bitmaps/trash.gif
3335 image create photo present -file ${libdir}/bitmaps/page.gif
3336 image create photo search -file ${libdir}/bitmaps/search.gif
3337 button .mid.search -image search -command {search-request 0} -state disabled -relief flat
3338 button .mid.scan -image scan -command scan-request -state disabled -relief flat
3339 button .mid.present -image present -command [list present-more 10] -state disabled -relief flat
3340 button .mid.clear -image clear -command index-clear -relief flat
3341 pack .mid.search .mid.scan .mid.present .mid.clear -side left -fill y -pady 1
3343 # Init: Define record area in main window.
3344 text .data.record -font fixed -height 2 -width 20 -wrap none -borderwidth 0 \
3345 -relief flat -yscrollcommand [list .data.scroll set] -wrap $textWrap
3346 scrollbar .data.scroll -command [list .data.record yview]
3347 .data.record configure -takefocus 0
3348 .data.scroll configure -takefocus 0
3350 pack .data.scroll -side right -fill y
3351 pack .data.record -expand yes -fill both
3354 # Init: Define standards tags. These are used in the display
3355 # format procedures.
3357 .data.record tag configure marc-tag -foreground blue
3358 .data.record tag configure marc-id -foreground red
3359 .data.record tag configure marc-data -foreground black
3360 .data.record tag configure marc-head -font $font(n,normal) \
3361 -foreground brown -relief raised -borderwidth 1
3362 .data.record tag configure marc-small-head -foreground brown
3363 .data.record tag configure marc-pref -font $font(n,normal) -foreground blue
3364 .data.record tag configure marc-text -font $font(n,normal) -foreground black
3365 .data.record tag configure marc-it -font $font(n,normal) -foreground black
3367 # Init: Define logo.
3368 button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
3369 .bot.logo configure -takefocus 0
3371 # Init: Define status information fields at the bottom.
3373 pack .bot.a -side left -fill x
3374 pack .bot.logo -side right -padx 2 -pady 2 -ipadx 1
3376 message .bot.a.target -text {} -aspect 2000 -border 1
3378 label .bot.a.status -text "Not connected" -width 15 -relief sunken -anchor w -border 1
3379 label .bot.a.set -text "" -width 5 -relief sunken -anchor w -border 1
3380 label .bot.a.message -text "" -width 15 -relief sunken -anchor w -border 1
3382 pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
3383 pack .bot.a.status .bot.a.set .bot.a.message -side left -padx 2 -pady 2 -ipadx 1 -ipady 1
3385 # Init: Determine if the IrTcl extension is already there. If
3386 # not, then dynamically load the IrTcl extension.
3387 if {[catch {ir z39}]} {
3388 set e [info sharedlibextension]
3389 puts -nonewline "Loading irtcl$e ..."
3390 load ${libdir}/irtcl$e irtcl
3395 if {[file exists ${libdir}/explain.tcl]} {
3396 source ${libdir}/explain.tcl
3399 #if {[file exists ${libdir}/setup.tcl]}
3400 source ${libdir}/setup.tcl
3403 # Init: Uncomment this line if you wan't to enable logging.
3404 ir-log-init all irtcl irtcl.log
3406 # Init: If hostid is a valid target, a new connection will be established
3408 if {[string compare $hostid Default]} {
3409 catch {open-target $hostid $hostbase}
3412 # Init: Enable the logo.