1 # IR toolkit for tcl/tk
2 # (c) Index Data 1995-1998
3 # See the file LICENSE for details.
4 # Sebastian Hammer, Adam Dickmeiss
7 # Revision 1.104 1998-02-12 13:32:41 adam
8 # Updated configuration system.
10 # Revision 1.103 1998/01/30 13:30:50 adam
11 # Name of target database is irtdb.tcl instead of clientrc.tcl.
13 # Revision 1.102 1997/11/19 13:19:54 adam
16 # Revision 1.101 1997/11/19 11:20:56 adam
17 # New target profile format - associative arrrays instead of LONG lists.
19 # Revision 1.100 1997/09/09 10:19:50 adam
20 # New MSV5.0 port with fewer warnings.
22 # Revision 1.99 1997/04/13 19:00:37 adam
23 # Added support for Tcl8.0/Tk8.0.
24 # New command ir-log-init to setup yaz logging facilities.
26 # Revision 1.98 1996/11/14 17:11:04 adam
27 # Added Explain documentaion.
29 # Revision 1.97 1996/09/13 10:54:22 adam
30 # Started work on Explain in client.
32 # Revision 1.96 1996/08/09 15:30:18 adam
33 # Procedure destroyGW modified to handle multiple calls - probably an
34 # error introduced by tk4.1 patch level 1.
36 # Revision 1.95 1996/07/26 09:15:08 adam
37 # IrTcl version 1.2 patch level 1.
39 # Revision 1.94 1996/07/25 15:55:34 adam
40 # IrTcl version 1.2 release.
42 # Revision 1.93 1996/06/28 08:43:54 adam
43 # Moved towards version 1.2.
45 # Revision 1.92 1996/03/29 16:04:30 adam
46 # Work on GRS-1 presentation.
48 # Revision 1.91 1996/03/27 17:00:53 adam
49 # Fix: main defined when using Tk3.6; it shouldn't be.
51 # Revision 1.90 1996/03/20 13:54:02 adam
52 # The Tcl_File structure is only manipulated in the Tk-event interface
55 # Revision 1.89 1996/03/05 09:16:04 adam
56 # Sets tearoff to off on several menus.
58 # Revision 1.88 1996/01/23 15:24:09 adam
59 # Wrore more comments.
61 # Revision 1.87 1996/01/22 17:13:34 adam
64 # Revision 1.86 1996/01/22 09:29:01 adam
67 # Revision 1.85 1996/01/19 16:22:36 adam
68 # New method: apduDump - returns information about last incoming APDU.
70 # Revision 1.84 1996/01/11 13:12:10 adam
73 # Revision 1.83 1995/11/28 17:26:36 adam
74 # Removed Carriage return from ir-tcl.c!
75 # Removed misc. debug logs.
77 # Revision 1.82 1995/11/02 08:47:56 adam
78 # Text widgets are flat now.
80 # Revision 1.81 1995/10/19 10:34:43 adam
81 # More configurable client.
83 # Revision 1.80 1995/10/18 17:20:32 adam
84 # Work on target setup in client.tcl.
86 # Revision 1.79 1995/10/18 16:42:37 adam
87 # New settings: smallSetElementSetNames and mediumSetElementSetNames.
89 # Revision 1.78 1995/10/18 15:45:36 quinn
90 # *** empty log message ***
92 # Revision 1.77 1995/10/18 15:37:46 adam
95 # Revision 1.76 1995/10/18 15:15:20 adam
98 # Revision 1.75 1995/10/17 14:18:05 adam
99 # Minor changes in presentation formats.
101 # Revision 1.74 1995/10/17 12:18:57 adam
102 # Bug fix: when target connection closed, the connection was not
103 # properly reestablished.
105 # Revision 1.73 1995/10/17 10:58:06 adam
106 # More work on presentation formats.
108 # Revision 1.72 1995/10/16 17:00:52 adam
109 # New setting: elementSetNames.
110 # Various client improvements. Medium presentation format looks better.
112 # Revision 1.71 1995/10/13 15:35:27 adam
113 # Relational operators may be used in search entries - changes
114 # in proc index-query.
116 # Revision 1.70 1995/10/12 14:46:52 adam
117 # Better record popup windows. Next/prev buttons in popup record windows.
118 # The record position in the raw format is much more visible.
120 # Revision 1.69 1995/09/21 13:42:54 adam
123 # Revision 1.68 1995/09/21 13:11:49 adam
124 # Support of dynamic loading.
125 # Test script uses load command if necessary.
127 # Revision 1.67 1995/09/20 14:35:19 adam
130 # Revision 1.66 1995/08/29 15:30:13 adam
131 # Work on GRS records.
133 # Revision 1.65 1995/08/24 15:39:09 adam
136 # Revision 1.64 1995/08/24 15:33:02 adam
139 # Revision 1.63 1995/08/04 13:20:48 adam
140 # Buttons at the bottom are slightly smaller.
142 # Revision 1.62 1995/08/04 11:32:37 adam
143 # More work on output queue. Memory related routines moved
146 # Revision 1.61 1995/07/20 08:09:39 adam
147 # client.tcl: Targets removed from hotTargets list when targets
148 # are removed/modified.
149 # ir-tcl.c: More work on triggerResourceControl.
151 # Revision 1.60 1995/06/30 16:30:19 adam
154 # Revision 1.59 1995/06/29 14:06:25 adam
155 # Another bug in install fixed. Configure searches for more versions of yaz.
157 # Revision 1.58 1995/06/29 12:34:06 adam
158 # IrTcl now works with both tk4.0b4/tcl7.4b4 and tk3.6/tcl7.3
160 # Revision 1.57 1995/06/29 09:20:30 adam
161 # Target entries in cascade menus are sorted.
163 # Revision 1.56 1995/06/27 19:03:48 adam
164 # Bug fix in do_present in ir-tcl.c: p->set_child member weren't set.
165 # nextResultSetPosition used instead of setOffset.
167 # Revision 1.55 1995/06/27 17:10:37 adam
168 # Bug fix: install procedure didn't work on some systems.
169 # Error turned up when clientrc.tcl was't present.
171 # Revision 1.54 1995/06/27 14:41:03 adam
172 # Bug fix in search-response. Didn't always observe non-surrogate diagnostics.
174 # Revision 1.53 1995/06/26 12:40:09 adam
175 # Client defines its own tkerror.
176 # User may specify 'no preferredRecordSyntax'.
178 # Revision 1.52 1995/06/22 13:14:59 adam
179 # Feature: SUTRS. Setting getSutrs implemented.
180 # Work on display formats.
181 # Preferred record syntax can be set by the user.
183 # Revision 1.51 1995/06/21 11:11:00 adam
184 # Bug fix: libdir undefined in about-origin.
186 # Revision 1.50 1995/06/21 11:04:48 adam
187 # Uses GNU autoconf 2.3.
188 # Install procedure implemented.
189 # boook bitmaps moved to sub directory bitmaps.
191 # Revision 1.49 1995/06/20 14:16:42 adam
192 # More work on cancel mechanism.
194 # Revision 1.48 1995/06/20 08:07:23 adam
195 # New setting: failInfo.
196 # Working on better cancel mechanism.
198 # Revision 1.47 1995/06/19 14:05:29 adam
199 # Bug fix: asked for SUTRS.
201 # Revision 1.46 1995/06/19 13:06:06 adam
202 # New define: IR_TCL_VERSION.
204 # Revision 1.45 1995/06/19 08:08:44 adam
205 # client.tcl: hotTargets now contain both database and target name.
206 # ir-tcl.c: setting protocol edited. Errors in callbacks are logged
207 # by logf(LOG_WARN, ...) calls.
209 # Revision 1.44 1995/06/16 14:55:18 adam
210 # Book logo mirrored.
212 # Revision 1.43 1995/06/16 14:41:05 adam
213 # Scan line entries can be copied to a search entry.
215 # Revision 1.42 1995/06/16 12:28:13 adam
216 # Implemented preferredRecordSyntax.
217 # Minor changes in diagnostic handling.
218 # Record list deleted when connection closes.
220 # Revision 1.41 1995/06/14 15:07:59 adam
221 # Bug fix in cascade-target-list. Uses yaz-version.h.
223 # Revision 1.40 1995/06/14 13:37:17 adam
224 # Setting recordType implemented.
225 # Setting implementationVersion implemented.
226 # Settings implementationId / implementationName edited.
228 # Revision 1.39 1995/06/14 12:16:22 adam
229 # hotTargets, textWrap and displayFormat saved in clientg.tcl.
231 # Revision 1.38 1995/06/14 07:22:45 adam
232 # Target definitions can be deleted.
233 # Listbox used in the query definition dialog.
235 # Revision 1.37 1995/06/13 14:37:59 adam
236 # Work on query setup.
237 # Better about origin/target.
238 # Better presentation formats.
240 # Revision 1.36 1995/06/13 07:42:14 adam
241 # Bindings removed from text widgets.
243 # Revision 1.35 1995/06/12 15:17:31 adam
244 # Text widget used in main window (instead of listbox) to support
245 # better presentation formats.
247 # Revision 1.34 1995/06/12 07:59:07 adam
248 # More work on geometry handling.
250 # Revision 1.33 1995/06/09 11:17:35 adam
251 # Start work on geometry management.
253 # Revision 1.32 1995/06/07 09:16:37 adam
254 # New presentation format.
256 # Revision 1.31 1995/06/06 16:31:09 adam
257 # Bug fix: target names couldn't contain blanks.
260 # Revision 1.30 1995/06/06 11:35:41 adam
261 # Work on scan. Display of old sets.
263 # Revision 1.29 1995/06/05 14:11:18 adam
264 # Bug fix in present-more.
266 # Revision 1.28 1995/06/02 14:52:13 adam
267 # Minor changes really.
269 # Revision 1.27 1995/06/02 14:29:42 adam
270 # Work on scan interface - up/down buttons.
272 # Revision 1.26 1995/06/01 16:36:46 adam
273 # About buttons. Minor bug fixes.
275 # Revision 1.25 1995/05/31 13:09:57 adam
276 # Client searches/presents may be interrupted.
277 # New moving book-logo.
279 # Revision 1.24 1995/05/31 08:36:24 adam
280 # Bug fix in client.tcl: didn't save options on clientrc.tcl.
281 # New method: referenceId. More work on scan.
283 # Revision 1.23 1995/05/29 10:33:41 adam
284 # README and rename of startup script.
286 # Revision 1.22 1995/05/26 11:44:09 adam
287 # Bugs fixed. More work on MARC utilities and queries. Test
288 # client is up-to-date again.
290 # Revision 1.21 1995/05/11 15:34:46 adam
291 # Scan request changed a bit. This version works with RLG.
293 # Revision 1.20 1995/04/21 16:31:57 adam
294 # New radiobutton: protocol (z39v2/SR).
296 # Revision 1.19 1995/04/18 16:11:50 adam
297 # First version of graphical Scan. Some work on query-by-form.
299 # Revision 1.18 1995/04/10 10:50:22 adam
300 # Result-set name defaults to suffix of ir-set name.
301 # Started working on scan. Not finished at this point.
303 # Revision 1.17 1995/03/31 09:34:57 adam
304 # Search-button disabled when there is no connection.
306 # Revision 1.16 1995/03/31 08:56:36 adam
307 # New button "Search".
309 # Revision 1.15 1995/03/28 12:45:22 adam
310 # New ir method failback: called on disconnect/protocol error.
311 # New ir set/get method: protocol: SR / Z3950.
312 # Simple popup and disconnect when failback is invoked.
314 # Revision 1.14 1995/03/22 16:07:55 adam
317 # Revision 1.13 1995/03/21 17:27:26 adam
318 # Short-hand keys in setup.
320 # Revision 1.12 1995/03/21 13:41:03 adam
321 # Comstack cs_create not used too often. Non-blocking connect.
323 # Revision 1.11 1995/03/21 10:39:06 adam
324 # Diagnostic error message displayed with tkerror.
326 # Revision 1.10 1995/03/20 15:24:06 adam
327 # Diagnostic records saved on searchResponse.
329 # Revision 1.9 1995/03/17 18:26:16 adam
330 # Non-blocking i/o used now. Database names popup as cascade items.
332 # Revision 1.8 1995/03/17 15:45:00 adam
333 # Improved target/database setup.
335 # Revision 1.7 1995/03/16 17:54:03 adam
336 # Minor changes really.
338 # Revision 1.6 1995/03/15 19:10:20 adam
339 # Database setup in protocol-setup (rather target setup).
341 # Revision 1.5 1995/03/15 13:59:23 adam
344 # Revision 1.4 1995/03/14 17:32:29 adam
345 # Presentation of full Marc record in popup window.
347 # Revision 1.3 1995/03/12 19:31:52 adam
348 # Pattern matching implemented when retrieving MARC records. More
349 # diagnostic functions.
351 # Revision 1.2 1995/03/10 18:00:15 adam
352 # Actual presentation in line-by-line format. RPN query support.
354 # Revision 1.1 1995/03/09 16:15:07 adam
355 # First presentRequest attempts. Hot-target list.
359 # Procedure tk4 is defined - returns 0 if tk 3.6 - returns 1 otherwise
360 if {$tk_version == "3.6"} {
370 # The following procedures deals with menu entries. The interface
371 # changed from Tk 3.6 to 4.X
384 # Procedure configure-enable-e {w n}
386 # n menu entry number (0 is first entry)
389 # Procedure configure-disable-e {w n}
391 # n menu entry number (0 is first entry)
392 # Disables menu entry
395 proc configure-enable-e {w n} {
397 $w entryconfigure $n -state normal
399 proc configure-disable-e {w n} {
401 $w entryconfigure $n -state disabled
403 set noFocus [list -takefocus 0]
405 proc configure-enable-e {w n} {
408 proc configure-disable-e {w n} {
414 # Define dummy clock function if it is not there.
415 if {[catch {clock seconds}]} {
420 # Set monoFlag to 1 if screen is known not to support colors; otherwise
423 if {[tk colormodel .] == "color"} {
432 # Define libdir to the IrTcl configuration directory.
433 # In the line below LIBDIR will be modified during 'make install'.
436 # If the bitmaps sub directory is present with a bitmap we assume
437 # the client is run from the source directory in which case we
438 # set libdir the current directory.
439 if {[file readable bitmaps/book2]} {
443 # Make a final check to see if libdir was set ok.
444 if {! [file readable ${libdir}/bitmaps/book2]} {
445 puts "Cannot locate system files in ${libdir}. You must either run this"
446 puts "program from the source directory root of ir-tcl or you must assure"
447 puts "that it is installed - normally in /usr/local/lib/irtcl"
451 # Initialize a lot of globals.
456 set profile(Default,description) {}
457 set profile(Default,host) {}
458 set profile(Default,port) 210
459 set profile(Default,authentication) {}
460 set profile(Default,maximumRecordSize) 50000
461 set profile(Default,preferredMessageSize) 30000
462 set profile(Default,comstack) tcpip
463 set profile(Default,namedResultSets) 1
464 set profile(Default,queryRPN) 1
465 set profile(Default,queryCCL) 0
466 set profile(Default,protocol) Z39
467 set profile(Default,windowNumber) 1
468 set profile(Default,largeSetLowerBound) 2
469 set profile(Default,smallSetUpperBound) 0
470 set profile(Default,mediumSetPresentNumber) 0
471 set profile(Default,presentChunk) 4
472 set profile(Default,timeDefine) {}
473 set profile(Default,timeLastInit) {}
474 set profile(Default,timeLastExplain) {}
475 set profile(Default,targetInfoName) {}
476 set profile(Default,recentNews) {}
477 set profile(Default,maxResultSets) {}
478 set profile(Default,maxResultSize) {}
479 set profile(Default,maxTerms) {}
480 set profile(Default,multipleDatabases) 0
481 set profile(Default,welcomeMessage) {}
484 set settingsChanged 0
492 set recordSyntax None
493 set elementSetNames None
497 set queryTypes {Simple}
498 set queryButtons { { {I 0} {I 1} {I 2} } }
499 set queryInfo { { {Title {1=4 4=1}} {Author {1=1}} \
500 {Subject {1=21}} {Any {1=1016}} } }
506 if {[lindex [split $tk_version .] 0] < 5} {
507 set font(bb,normal) -Adobe-Helvetica-Medium-R-Normal-*-240-*
508 set font(bb,bold) -Adobe-Helvetica-Bold-R-Normal-*-240-*
509 set font(b,normal) -Adobe-Helvetica-Medium-R-Normal-*-180-*
510 set font(b,bold) -Adobe-Helvetica-Bold-R-Normal-*-180-*
511 set font(n,normal) -Adobe-Helvetica-Medium-R-Normal-*-120-*
512 set font(n,bold) -Adobe-Helvetica-Bold-R-Normal-*-120-*
513 set font(s,bold) -Adobe-Helvetica-Bold-R-Normal-*-100-*
514 set font(ss,bold) -Adobe-Helvetica-Bold-R-Normal-*-80-*
516 set font(bb,normal) {Helvetica 24}
517 set font(bb,bold) {Helvetica 24 bold}
518 set font(b,normal) {Helvetica 24}
519 set font(b,bold) {Helvetica 18 bold}
520 set font(n,normal) {Helvetica 12}
521 set font(n,bold) {Helvetica 12 bold}
522 set font(s,bold) {Helvetica 10 bold}
523 set font(ss,bold) {Helvetica 8 bold}
526 # Procedure tkerror {err}
528 # Override the Tk error handler function.
534 if {[winfo exists $w]} {
543 label $w.top.b -bitmap error
544 message $w.top.t -aspect 300 -text "Error: $err" \
546 pack $w.top.b $w.top.t -side left -padx 10 -pady 10
548 bottom-buttons $w [list {Close} [list destroy $w]] 1
551 # Read tag set file (if present)
552 if {[file readable "${libdir}/tagsets.tcl"]} {
553 source "${libdir}/tagsets.tcl"
556 # Read the global target configuration file.
557 if {[file readable "${libdir}/irtdb.tcl"]} {
558 source "${libdir}/irtdb.tcl"
560 # Read the local target configuration file.
561 if {[file readable "irtdb.tcl"]} {
565 # Read the user configuration file.
566 if {[file readable "~/.clientrc.tcl"]} {
567 source "~/.clientrc.tcl"
570 # Convert old format to new format...
571 foreach target [array names profile] {
572 set timedef [clock seconds]
573 if {[string first , $target] == -1} {
574 if {![info exists profile($target,port)]} {
575 foreach n [array names profile Default,*] {
576 set profile($target,[string range $n 8 end]) $profile($n)
578 set profile($target,description) [lindex $profile($target) 0]
579 set profile($target,host) [lindex $profile($target) 1]
580 set profile($target,port) [lindex $profile($target) 2]
581 set profile($target,authentication) [lindex $profile($target) 3]
582 set profile($target,maximumRecordSize) \
583 [lindex $profile($target) 4]
584 set profile($target,preferredMessageSize) \
585 [lindex $profile($target) 5]
586 set profile($target,comstack) [lindex $profile($target) 6]
587 set profile($target,databases) [lindex $profile($target) 7]
588 set profile($target,timeDefine) $timedef
589 set profile($target,windowNumber) 1
591 unset profile($target)
595 # Assign unique ID's to each target's window number
597 foreach n [array names profile *,windowNumber] {
601 set profile(Default,windowNumber) $wno
603 # These globals describe the current query type. They are set to the
605 set queryButtonsFind [lindex $queryButtons 0]
606 set queryInfoFind [lindex $queryInfo 0]
608 # Procedure read-formats
609 # Read all Tcl source files in the subdirectory 'formats'.
610 # The name of each source will correspond to a display format.
611 proc read-formats {} {
612 global displayFormats
617 set formats [glob {*.[tT][cC][lL]}]
619 if {[file readable $f]} {
621 set l [string length $f]
622 set f [string tolower [string range $f 0 [expr $l - 5]]]
623 lappend displayFormats $f
629 # Procedure set-wrap {m}
630 # m boolean wrap mode
631 # Handler to enable/disable text wrap in the main record window
636 .data.record configure -wrap $m
639 # Procedure dputs {m}
640 # m string to be printed
641 # puts utility for debugging.
649 # Procedure apduDump {}
650 # Logs BER dump of last APDU in window if debugMode is true.
656 if {$debugMode == 0} return
659 set offset [lindex $x 1]
660 set length [lindex $x 0]
662 if {![winfo exists $w]} {
666 wm title $w "APDU information"
672 text $w.top.t -font fixed -width 60 -height 12 -wrap word \
673 -relief flat -borderwidth 0 \
674 -yscrollcommand [list $w.top.s set] -background grey85
675 scrollbar $w.top.s -command [list $w.top.t yview]
677 pack $w.top.s -side right -fill y
678 pack $w.top.t -expand yes -fill both
680 bottom-buttons $w [list {Close} [list destroy $w]] 0
682 $w.top.t insert end "Length: ${length}\n"
684 $w.top.t insert end "Offset: ${offset}\n"
686 $w.top.t insert end [lindex $x 2]
687 $w.top.t insert end "---------------------------------\n"
691 # Procedure set-display-format {f}
693 # Reformats main record window to use display format given by f
694 proc set-display-format {f} {
695 global displayFormat setNo busy
702 .bot.a.status configure -text "Reformatting"
705 add-title-lines -1 10000 1
708 # Procedure initBindings
709 # Disables various default bindings for Text and Listbox widgets.
710 proc initBindings {} {
713 foreach e [bind Text] {
714 set TextBinding($e) [bind Text $e]
718 bind $w <B1-Motion> {}
719 bind $w <Shift-B1-Motion> {}
724 # Procedure TextEditable
725 # Apply "standard" events to a text widget. It should be editable now.
726 proc TextEditable {w} {
729 foreach e [array names TextBinding] {
730 bind $w $e $TextBinding($e)
734 # Procedure post-menu {wbutton wmenu}
735 # wbutton button widget
737 # Post menu near button. Note: not used.
738 proc post-menu {wbutton wmenu} {
741 $wmenu post [winfo rootx $wbutton] \
742 [expr [winfo rooty $wbutton]+[winfo height $wbutton]]
746 # Procedure destroyGW {w}
748 # Saves geometry of widget w in windowGeometry array. This
749 # Procedure is used to save current geometry of a window before
751 # See also topLevelG.
753 global windowGeometry
754 catch {set windowGeometry($w) [wm geometry $w]}
757 # Procedure topLevelG
759 # Makes a new top level widget named w; sets geometry of window if it
760 # exists in windowGeometry array. The destroyGW procedure is set
761 # to be called when the Destroy event occurs.
763 global windowGeometry
766 if {[info exists windowGeometry($w)]} {
767 set g $windowGeometry($w)
772 bind $w <Destroy> [list destroyGW $w]
775 # Procedure top-down-window {w}
776 # w window (possibly top level)
777 # Makes two frames inside w called top and bot.
778 proc top-down-window {w} {
779 frame $w.top -relief raised -border 1
780 frame $w.bot -relief raised -border 1
782 pack $w.top -side top -fill both -expand yes
783 pack $w.bot -fill both
786 # Procedure top-down-ok-cancel {w ok-action g}
787 # w top level widget with $w.bot-frame
788 # ok-action ok script
790 # Makes two buttons in the bot frame called Ok and Cancel. The
791 # ok-action is executed if Ok is pressed. If Cancel is activated
792 # The window is destroyed. If g is true a grab is performed on the
793 # window and the procedure waits until the window is destroyed.
794 proc top-down-ok-cancel {w ok-action g} {
795 frame $w.bot.left -relief sunken -border 1
796 pack $w.bot.left -side left -expand yes -ipadx 2 -ipady 2 -padx 1 -pady 1
797 button $w.bot.left.ok -width 4 -text {Ok} \
798 -command ${ok-action}
799 pack $w.bot.left.ok -expand yes -ipadx 1 -ipady 1 -padx 2 -pady 2
800 button $w.bot.cancel -width 5 -text {Cancel} \
801 -command [list destroy $w]
802 pack $w.bot.cancel -side left -expand yes
810 # Procedure bottom-buttons {w buttonList g}
811 # w top level widget with $w.bot-frame
812 # buttonList button specifications
814 # Makes a list of buttons in the $w.bot frame. The buttonList is a list
815 # of button specifications. Each button specification consists of two
816 # items; the first item is button label name; the second item is a script
817 # of be executed when that button is executed. A grab is performed if g
818 # is true and it waits for the window to be destroyed.
819 proc bottom-buttons {w buttonList g} {
821 set l [llength $buttonList]
823 frame $w.bot.$i -relief sunken -border 1
824 pack $w.bot.$i -side left -expand yes -padx 2 -pady 2
825 button $w.bot.$i.ok -text [lindex $buttonList $i] \
826 -command [lindex $buttonList [expr $i+1]]
827 pack $w.bot.$i.ok -expand yes -padx 2 -pady 2 -side left
831 button $w.bot.$i -text [lindex $buttonList $i] \
832 -command [lindex $buttonList [expr $i+1]]
833 pack $w.bot.$i -expand yes -padx 2 -pady 2 -side left
843 # Procedure cancel-operation
844 # This handler is invoked when the user wishes to cancel an operation.
845 # If the system is currently busy a "Cancel" will be displayed in the
846 # status area and the cancelFlag is set to true indicating that future
847 # responses from the target should be ignored. The system is no longer
848 # busy when this procedure exists.
849 proc cancel-operation {} {
850 global cancelFlag busy delayRequest
855 show-status Cancel 0 1
859 # Procedure show-target {target base}
860 # target name of target
861 # base name of database
862 # Displays target name and database name in the target status area.
863 proc show-target {target base} {
864 if {![string length $target]} {
865 .bot.a.target configure -text {}
868 if {![string length $base]} {
869 .bot.a.target configure -text "$target"
871 .bot.a.target configure -text "$target - $base"
875 # Procedure show-logo {v1}
877 # This procedure maintains the book logo in the bottom of the screen.
878 # It is invoked only once during initialization of windows, etc., and
879 # by itself. The global 'busy' variable determines whether the logo is
881 proc show-logo {v1} {
889 .bot.logo configure -bitmap @${libdir}/bitmaps/book${v1}
890 after 140 [list show-logo $v1]
894 .bot.logo configure -bitmap @${libdir}/bitmaps/book1
903 # Procedure show-status {status b sb}
904 # status status message string
906 # sb search busy indicator
907 # Display status information according to 'status' and sets the global
908 # busy flag 'busy' to b if b is non-empty. If sb is non-empty it indicates
909 # whether service buttons should be enabled or disabled.
910 proc show-status {status b sb} {
911 global busy scanEnable
912 global setOffset setMax setNo
914 .bot.a.status configure -text "$status"
916 if {$busy == 0} {set busy 1}
924 .top.service configure -state normal
925 .mid.search configure -state normal
927 .mid.scan configure -state normal
929 configure-disable-e .top.service.m 3
932 configure-disable-e .top.service.m 1
933 } elseif {[z39.$setNo nextResultSetPosition] > 0 &&
934 [z39.$setNo nextResultSetPosition] <= [z39.$setNo resultCount]} {
935 configure-enable-e .top.service.m 1
936 .mid.present configure -state normal
938 configure-disable-e .top.service.m 1
939 .mid.present configure -state disabled
941 if {[winfo exists .scan-window]} {
942 .scan-window.bot.2 configure -state normal
943 .scan-window.bot.4 configure -state normal
946 .top.service configure -state disabled
947 .mid.search configure -state disabled
948 .mid.scan configure -state disabled
949 .mid.present configure -state disabled
951 if {[winfo exists .scan-window]} {
952 .scan-window.bot.2 configure -state disabled
953 .scan-window.bot.4 configure -state disabled
958 # Procedure show-message {msg}
960 # Sets message the bottom of the screen to msg.
961 proc show-message {msg} {
962 .bot.a.message configure -text "$msg"
965 # Procedure insertWithTags {w text args}
967 # text string to be inserted
969 # Inserts text at the insertion point in widget w. The text is tagged
970 # with the tags in args.
971 proc insertWithTags {w text args} {
972 set start [$w index insert]
973 $w insert insert $text
974 foreach tag [$w tag names $start] {
975 $w tag remove $tag $start insert
978 $w tag add $i $start insert
982 # Procedure popup-license
983 # Displays LICENSE information.
984 proc popup-license {} {
989 wm title $w "License"
995 text $w.top.t -width 80 -height 10 -wrap word -relief flat -borderwidth 0 \
996 -font fixed -yscrollcommand [list $w.top.s set]
997 scrollbar $w.top.s -command [list $w.top.t yview]
999 pack $w.top.s -side right -fill y
1000 pack $w.top.t -expand yes -fill both
1002 if {[file readable "${libdir}/LICENSE"]} {
1003 set f [open "${libdir}/LICENSE" r]
1004 while {[gets $f buf] != -1} {
1005 $w.top.t insert end $buf
1006 $w.top.t insert end "\n"
1010 bottom-buttons $w [list {Close} [list destroy $w]] 1
1013 # Procedure about-target
1014 # Displays various information about the current target, such
1015 # as implementation-name, implementation-id, etc.
1016 proc about-target {} {
1017 set w .about-target-w
1022 wm title $w "About target"
1026 frame $w.top.a -relief ridge -border 2
1027 frame $w.top.p -relief ridge -border 2
1029 pack $w.top.a $w.top.p -side top -fill x
1031 label $w.top.a.about -text "About"
1032 label $w.top.a.irtcl -text $hostid -font $font(bb,bold)
1033 pack $w.top.a.about $w.top.a.irtcl -side top
1035 set i [z39 targetImplementationName]
1036 label $w.top.p.in -text "Implementation name: $i"
1037 set i [z39 targetImplementationId]
1038 label $w.top.p.ii -text "Implementation id: $i"
1039 set i [z39 targetImplementationVersion]
1040 label $w.top.p.iv -text "Implementation version: $i"
1042 label $w.top.p.op -text "Protocol options: $i"
1044 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.op -side top -anchor nw
1046 bottom-buttons $w [list {Close} [list destroy $w]] 1
1049 # Procedure about-origin-logo {n}
1051 # Displays book logo in the .about-origin-w widget
1052 proc about-origin-logo {n} {
1054 set w .about-origin-w
1055 if {![winfo exists $w]} {
1062 $w.top.a.logo configure -bitmap @${libdir}/bitmaps/book$n
1063 after 140 [list about-origin-logo $n]
1066 # Procedure about-origin
1067 # Display various information about origin (this client).
1068 proc about-origin {} {
1069 set w .about-origin-w
1070 global libdir font tk_version
1072 if {[winfo exists $w]} {
1077 wm title $w "About IrTcl"
1081 frame $w.top.a -relief ridge -border 2
1082 frame $w.top.p -relief ridge -border 2
1084 pack $w.top.a $w.top.p -side top -fill x
1086 label $w.top.a.irtcl -text "IrTcl" -font $font(bb,bold)
1087 label $w.top.a.logo -bitmap @${libdir}/bitmaps/book1
1088 pack $w.top.a.irtcl $w.top.a.logo -side left -expand yes
1091 catch {set i [z39 implementationName]}
1092 label $w.top.p.in -text "Implementation name: $i"
1093 catch {set i [z39 implementationId]}
1094 label $w.top.p.ii -text "Implementation id: $i"
1095 catch {set i [z39 implementationVersion]}
1096 label $w.top.p.iv -text "Implementation version: $i"
1098 label $w.top.p.tk -text "Tk version: $i"
1100 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.tk -side top -anchor nw
1103 bottom-buttons $w [list {Close} [list destroy $w] \
1104 {License} [list popup-license]] 0
1107 # Procedure popup-marc {sno no b df}
1108 # sno result set number
1109 # no record position number
1110 # b popup window number
1112 # Displays record in set $sno at position $no in window .full-marc$b.
1113 # The global variable $popupMarcdf holds the current format method.
1114 proc popup-marc {sno no b df} {
1115 global font displayFormats popupMarcdf
1117 if {[z39.$sno type $no] != "DB"} {
1122 while {[winfo exists .full-marc$b]} {
1128 if {![winfo exists $w]} {
1133 frame $w.top -relief raised -border 1
1134 frame $w.bot -relief raised -border 1
1136 pack $w.top -side top -fill both -expand yes
1137 pack $w.bot -fill both
1139 text $w.top.record -width 60 -height 5 -wrap word -relief flat \
1140 -borderwidth 0 -font fixed \
1141 -yscrollcommand [list $w.top.s set] -background grey85
1142 scrollbar $w.top.s -command [list $w.top.record yview]
1146 $w.top.record tag configure marc-tag -foreground blue
1147 $w.top.record tag configure marc-id -foreground red
1149 $w.top.record tag configure marc-tag -foreground black
1150 $w.top.record tag configure marc-id -foreground black
1152 $w.top.record tag configure marc-data -foreground black
1153 $w.top.record tag configure marc-head -font $font(n,bold) \
1154 -background black -foreground white
1156 $w.top.record tag configure marc-pref -font $font(n,normal) \
1158 $w.top.record tag configure marc-text -font $font(n,normal) \
1160 $w.top.record tag configure marc-it -font $font(n,normal) \
1163 pack $w.top.s -side right -fill y
1164 pack $w.top.record -expand yes -fill both
1166 bottom-buttons $w [list \
1167 {Close} [list destroy $w] \
1171 menubutton $w.bot.formats -text "Format" -menu $w.bot.formats.m \
1173 irmenu $w.bot.formats.m
1174 pack $w.bot.formats -expand yes -ipadx 2 -ipady 2 \
1175 -padx 3 -pady 3 -side left
1177 $w.bot.formats.m delete 0 last
1180 foreach f $displayFormats {
1181 $w.bot.formats.m add radiobutton -label $f \
1182 -variable popupMarcdf -value $i \
1183 -command [list popup-marc $sno $no $b 0]
1186 $w.top.record delete 0.0 end
1187 set recordType [z39.$sno recordType $no]
1188 wm title $w "$recordType record #$no"
1190 $w.bot.2 configure -command \
1191 [list popup-marc $sno [expr $no-1] $b $df]
1192 $w.bot.4 configure -command \
1193 [list popup-marc $sno [expr $no+1] $b $df]
1195 $w.bot.2 configure -state disabled
1197 $w.bot.2 configure -state normal
1199 if {[z39.$sno type [expr $no+1]] != "DB"} {
1200 $w.bot.4 configure -state disabled
1202 $w.bot.4 configure -state normal
1204 $w.bot.6 configure -command [list popup-marc $sno $no -1 0]
1205 set ffunc [lindex $displayFormats $df]
1206 set ffunc "display-$ffunc"
1208 $ffunc $sno $no $w.top.record 0
1211 # Procedure update-target-hotlist {target base}
1212 # target current target name
1213 # base current database name
1214 # Updates the global $hotTargets so that $target and $base are
1215 # moved to the front, i.e. they become the number 1 target/base.
1216 # The target menu is updated by a call to set-target-hotlist.
1217 proc update-target-hotlist {target base} {
1220 set olen [llength $hotTargets]
1222 foreach e $hotTargets {
1223 if {$target == [lindex $e 0] && $base == [lindex $e 1]} {
1224 set hotTargets [lreplace $hotTargets $i $i]
1229 set hotTargets [linsert $hotTargets 0 [list $target $base]]
1230 set-target-hotlist $olen
1233 # Procedure delete-target-hotlist {target}
1234 # target target to be deleted
1235 # Updates the global $hotTargets so that $target is removed.
1236 # The target menu is updated by a call to set-target-hotlist.
1237 proc delete-target-hotlist {target} {
1240 set olen [llength $hotTargets]
1242 foreach e $hotTargets {
1243 if {$target == [lindex $e 0]} {
1244 set hotTargets [lreplace $hotTargets $i $i]
1248 set-target-hotlist $olen
1251 # Procedure set-target-hotlist {olen}
1252 # olen number of hot target entries to be deleted from menu
1253 # Updates the target menu with the targets with the first 8 entries
1254 # in the $hotTargets global.
1255 proc set-target-hotlist {olen} {
1260 .top.target.m delete 6 [expr 6+$olen]
1262 .top.target.m delete 6 [expr 6+$olen]
1266 foreach e $hotTargets {
1267 set target [lindex $e 0]
1268 set base [lindex $e 1]
1269 if {![string length $base]} {
1270 .top.target.m add command -label "$i $target" -command \
1271 [list reopen-target $target {}]
1273 .top.target.m add command -label "$i $target - $base" -command \
1274 [list reopen-target $target $base]
1283 # Procedure reopen-target {target base}
1284 # target target to be opened
1285 # base base to be used
1286 # Closes connection with current target and opens a new connection
1287 # with $target and database $base.
1288 proc reopen-target {target base} {
1290 open-target $target $base
1291 update-target-hotlist $target $base
1294 # Procedure define-target-action
1295 # Prepares the setup of a new target. The name of the target
1296 # is read from the dialog .target-define dialog (procedure
1297 # define-target-dialog) and the target definition window is displayed by
1298 # a call to protocol-setup.
1299 proc define-target-action {} {
1302 set target [.target-define.top.target.entry get]
1303 if {![string length $target]} {
1306 foreach n [array names profile *,host] {
1307 if {![string compare $n ${target},host]} {
1308 destroy .target-define
1313 foreach n [array names profile Default,*] {
1314 set profile($target,[string range $n 8 end]) $profile($n)
1317 incr profile(Default,windowNumber)
1319 protocol-setup $target
1320 destroy .target-define
1323 # Procedure fail-response {target}
1324 # target current target
1325 # Error handler (IrTcl failback) that takes care of serious protocol
1326 # errors, connection lost, etc.
1327 proc fail-response {target} {
1330 set c [lindex [z39 failInfo] 0]
1331 set m [lindex [z39 failInfo] 1]
1332 if {$c == 4 || $c == 5} {
1340 # Procedure connect-response {target base}
1341 # target current target
1342 # base current database
1343 # IrTcl connect response handler.
1344 proc connect-response {target base} {
1345 dputs "connect-response"
1346 init-request $target $base
1349 # Procedure open-target {target base}
1350 # target target to be opened
1351 # base database to be used
1352 # Opens a new connection with $target/$base.
1353 proc open-target {target base} {
1359 z39 comstack $profile($target,comstack)
1360 z39 protocol $profile($target,protocol)
1361 eval z39 idAuthentication $profile($target,authentication)
1362 z39 maximumRecordSize $profile($target,maximumRecordSize)
1363 z39 preferredMessageSize $profile($target,preferredMessageSize)
1364 dputs "maximumRecordSize=[z39 maximumRecordSize]"
1365 dputs "preferredMessageSize=[z39 preferredMessageSize]"
1366 show-status Connecting 1 0
1367 set x $profile($target,largeSetLowerBound)
1368 if {![string length $x]} {
1371 z39 largeSetLowerBound $x
1373 set x $profile($target,smallSetUpperBound)
1374 if {![string length $x]} {
1377 z39 smallSetUpperBound $x
1379 set x $profile($target,mediumSetPresentNumber)
1380 if {![string length $x]} {
1383 z39 mediumSetPresentNumber $x
1385 set presentChunk $profile($target,presentChunk)
1386 if {![string length $presentChunk]} {
1390 z39 failback [list fail-response $target]
1391 z39 callback [list connect-response $target $base]
1392 show-target $target $base
1395 z39 connect $profile($target,host):$profile($target,port)
1399 tkerror $errorMessage
1400 show-status "Not connected" 0 {}
1405 configure-disable-e .top.target.m 0
1406 configure-enable-e .top.target.m 1
1407 configure-enable-e .top.target.m 2
1410 # Procedure close-target
1411 # Shuts down the connection with current target.
1412 proc close-target {} {
1421 .bot.a.set configure -text ""
1425 show-status {Not connected} 0 0
1428 configure-disable-e .top.target.m 1
1429 configure-disable-e .top.target.m 2
1431 .top.rset.m delete 1 last
1433 .top.rset.m delete 1 last
1435 .top.rset.m add separator
1436 configure-enable-e .top.target.m 0
1439 # Procedure load-set-action
1440 # Loads records from a file. The filename is read from the entry
1441 # .load-set.filename.entry (see function load-set)
1442 proc load-set-action {} {
1446 ir-set z39.$setNoLast z39
1448 set fname [.load-set.top.filename.entry get]
1451 show-status Loading 1 {}
1453 z39.$setNoLast loadFile $fname
1455 set no [z39.$setNoLast numberOfRecordsReturned]
1456 add-title-lines $setNoLast $no 1
1458 set l [format "%-4d %7d" $setNoLast $no]
1459 .top.rset.m add command -label $l \
1460 -command [list add-title-lines $setNoLast 10000 1]
1461 show-status Ready 0 {}
1464 # Procedure load-set
1465 # Dialog that asks for a filename with records to be loaded
1466 # into a result set.
1470 set oldFocus [focus]
1474 frame $w.top.filename
1475 pack $w.top.filename -side top -anchor e -pady 2
1477 entry-fields $w.top {filename} \
1479 {load-set-action} {destroy .load-set}
1481 top-down-ok-cancel $w {load-set-action} 1
1485 # Procedure init-request
1486 # Sends an initialize request to the target. This procedure is called
1487 # when a connect has been established.
1488 proc init-request {target base} {
1495 z39 callback [list init-response $target $base]
1496 show-status Initializing 1 {}
1497 set err [catch {z39 init} errorMessage]
1499 tkerror $errorMessage
1500 show-status Ready 0 {}
1504 # Procedure init-response
1505 # Handles and incoming init-response. The service buttons
1506 # are enabled. The global $scanEnable indicates whether the target
1508 proc init-response {target base} {
1509 global cancelFlag profile scanEnable settingsChanged
1511 dputs {init-response}
1517 if {![z39 initResult]} {
1518 set u [z39 userInformationField]
1520 tkerror "Connection rejected by target: $u"
1522 z39 failback [list explain-crash $target $base]
1523 explain-check $target [list ready-response $base]
1527 # Procedure explain-crash
1528 # Handles target that dies during explain.
1529 proc explain-crash {target base} {
1530 global profile settingsChanged
1532 set profile($target,timeLastInit) [clock seconds]
1533 set settingsChanged 1
1536 open-target $target $base
1539 # Procedure explain-check
1540 # Stub function to check explain. May be overwritten later.
1541 proc explain-check {target response} {
1542 eval $response [list $target]
1545 # Procedure ready-response
1546 # Called after a target has been initialized and, possibly, explained
1547 proc ready-response {base target} {
1548 global profile settingsChanged scanEnable
1550 z39 failback [list fail-response $target]
1551 if {[string length $base]} {
1552 set profile($target,timeLastInit) [clock seconds]
1553 set settingsChanged 1
1555 z39 databaseNames $base
1556 cascade-dblist $target $base
1557 show-target $target $base
1559 if {[lsearch [z39 options] scan] >= 0} {
1564 .data.record delete 1.0 end
1565 set desc [string trim $profile($target,description)]
1566 if {[string length $desc]} {
1567 .data.record insert end "$desc\n\n"
1569 .data.record insert end "$target\n\n"
1571 set data [string trim $profile($target,welcomeMessage)]
1572 if {[string length $data]} {
1573 .data.record insert end "Welcome Message:\n$data\n\n"
1575 set data [string trim $profile($target,recentNews)]
1576 if {[string length $data]} {
1577 .data.record insert end "News:\n$data\n"
1580 show-status Ready 0 1
1583 # Procedure search-request
1584 # bflag flag to indicate if this procedure calls itself
1585 # Performs a search. If $busy is 1, the search-request is performed
1586 # at a later time (when another response arrives). This procedure
1587 # sets many search-related Z39-settings. The global $setNo is set
1588 # to the result set number (z39.$setNo).
1589 proc search-request {bflag} {
1598 global elementSetNames
1602 if {![string length [z39 connect]]} {
1605 dputs "search-request"
1607 if {!$bflag && $busy} {
1608 dputs "busy: search-request ignored"
1613 show-status Searching 1 0
1614 set delayRequest {search-request 1}
1619 set query [index-query]
1620 if {![string length $query]} {
1624 set setNo $setNoLast
1625 ir-set z39.$setNo z39
1627 if {$profile($target,namedResultSets)} {
1628 z39.$setNo setName $setNo
1629 dputs "setName=${setNo}"
1631 z39.$setNo setName default
1632 dputs "setName=default"
1634 if {$profile($target,queryRPN)} {
1635 z39.$setNo queryType rpn
1636 } elseif {$profile($target,queryCCL)} {
1637 z39.$setNo queryType ccl
1641 if {![string compare $recordSyntax None]} {
1642 z39.$setNo preferredRecordSyntax {}
1644 z39.$setNo preferredRecordSyntax $recordSyntax
1646 if {![string compare $elementSetNames None]} {
1647 z39.$setNo elementSetNames {}
1648 z39.$setNo smallSetElementSetNames {}
1649 z39.$setNo mediumSetElementSetNames {}
1651 z39.$setNo elementSetNames $elementSetNames
1652 z39.$setNo smallSetElementSetNames $elementSetNames
1653 z39.$setNo mediumSetElementSetNames $elementSetNames
1655 z39 callback {search-response}
1656 z39.$setNo search $query
1657 show-status Searching 1 0
1660 # Procedure scan-copy {y entry}
1661 # y y-position of mouse pointer
1662 # entry a search entry in the top
1663 # Copies the term in the list nearest $y to the query entry specified
1665 proc scan-copy {y entry} {
1667 set no [$w.top.list nearest $y]
1669 .lines.$entry.e delete 0 end
1670 .lines.$entry.e insert 0 [string range [$w.top.list get $no] 8 end]
1673 # Procedure scan-request
1674 # Performs a scan on term "0" with the current attributes in entry
1675 # specified by the global $curIndexEntry.
1676 proc scan-request {} {
1683 global curIndexEntry
1684 global queryButtonsFind
1685 global queryInfoFind
1689 dputs "scan-request"
1692 show-status Scanning 1 0
1693 set delayRequest scan-request
1702 set b [lindex $queryButtonsFind $curIndexEntry]
1704 foreach a [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end] {
1705 set attr "@attr $a $attr"
1707 set title [lindex [lindex $queryInfoFind [lindex $b 1]] 0]
1708 ir-scan z39.scan z39
1710 if {![winfo exists $w]} {
1717 entry $w.top.entry -relief sunken
1718 pack $w.top.entry -fill x -padx 4 -pady 2
1719 bind $w.top.entry <KeyRelease> [list scan-term-h $attr]
1720 listbox $w.top.list -yscrollcommand [list $w.top.scroll set] \
1722 scrollbar $w.top.scroll -orient vertical -border 1
1723 pack $w.top.list -side left -fill both -expand yes
1724 pack $w.top.scroll -side right -fill y
1725 $w.top.scroll config -command [list $w.top.list yview]
1727 bottom-buttons $w [list {Close} [list destroy $w] \
1728 {Up} [list scan-up $attr] \
1729 {Down} [list scan-down $attr]] 0
1730 bind $w.top.list <Up> [list scan-up $attr]
1731 bind $w.top.list <Down> [list scan-down $attr]
1734 bind $w.top.list <Double-Button-1> [list scan-copy %y $curIndexEntry]
1735 wm title $w "Scan $title"
1737 z39 callback [list scan-response $attr 0 35]
1738 z39.scan numberOfTermsRequested 5
1739 z39.scan preferredPositionInResponse 1
1740 z39.scan scan "${attr} 0"
1742 show-status Scanning 1 0
1745 # Procedure scan-term-h {attr}
1746 # attr attribute specification
1747 # This procedure is called whenever a key is released in the entry in the
1748 # scan window (.scan-window). A scan is then initiated with the new contents
1749 # of the entry as the starting term.
1750 proc scan-term-h {attr} {
1758 set nScanTerm [$w.top.entry get]
1759 if {$nScanTerm == $scanTerm} {
1762 set scanTerm $nScanTerm
1763 z39 callback [list scan-response $attr 0 35]
1764 z39.scan numberOfTermsRequested 5
1765 z39.scan preferredPositionInResponse 1
1766 dputs "${attr} \{${scanTerm}\}"
1767 if {![string length $scanTerm]} {
1768 z39.scan scan "${attr} 0"
1770 z39.scan scan "${attr} \{${scanTerm}\}"
1772 show-status Scanning 1 0
1775 # Procedure scan-response {attr start toget}
1776 # attr attribute specification
1777 # start position of first term in the response
1778 # toget number of total terms to get
1779 # This procedure handles all scan-responses. $start specifies the list
1780 # entry number of the first incoming term. The $toget indicates the total
1781 # number of terms to be retrieved from the target. The $toget may be
1782 # negative in which case, scan is performed 'backwards' (- $toget is
1783 # the total number of terms in this case). This procedure usually calls
1784 # itself several times in order to get small scan-term-list chunks.
1785 proc scan-response {attr start toget} {
1792 dputs "In scan-response"
1794 set m [z39.scan numberOfEntriesReturned]
1800 if {![winfo exists .scan-window]} {
1803 dputs "Handling cancel"
1804 if {$delayRequest != ""} {
1809 show-status Ready 0 1
1812 set nScanTerm [$w.top.entry get]
1813 if {$nScanTerm != $scanTerm} {
1814 z39 callback [list scan-response $attr 0 35]
1815 z39.scan numberOfTermsRequested 5
1816 z39.scan preferredPositionInResponse 1
1817 set scanTerm $nScanTerm
1818 dputs "${attr} \{${scanTerm}\}"
1819 if {![string length $scanTerm]} {
1820 z39.scan scan "${attr} 0"
1822 z39.scan scan "${attr} \{${scanTerm}\}"
1824 show-status Scanning 1 0
1827 set status [z39.scan scanStatus]
1830 show-status Ready 0 1
1835 for {set i 0} {$i < $m} {incr i} {
1836 set term [lindex [z39.scan scanLine $i] 1]
1837 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1838 $w.top.list insert $i "$nostr $term"
1841 $w.top.list yview $scanView
1843 $w.top.list delete $start end
1844 for {set i 0} {$i < $m} {incr i} {
1845 set term [lindex [z39.scan scanLine $i] 1]
1846 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1847 $w.top.list insert end "$nostr $term"
1851 dputs "Handling cancel"
1853 if {$delayRequest != ""} {
1859 if {$toget > 0 && $m > 1 && $m < $toget} {
1860 set ntoget [expr $toget - $m + 1]
1861 dputs ntoget=$ntoget
1862 z39 callback [list scan-response $attr [expr $start + $m - 1] $ntoget]
1864 dputs "down continue: $q"
1866 z39.scan numberOfTermsRequested 10
1868 z39.scan numberOfTermsRequested $ntoget
1870 z39.scan preferredPositionInResponse 1
1871 dputs "${attr} \{$q\}"
1872 z39.scan scan "${attr} \{$q\}"
1875 if {$toget < 0 && $m > 1 && $m < [expr - $toget]} {
1876 set ntoget [expr - $toget - $m]
1877 dputs ntoget=$ntoget
1878 z39 callback [list scan-response $attr 0 -$ntoget]
1879 set q [string range [$w.top.list get 0] 8 end]
1880 dputs "up continue: $q"
1882 z39.scan numberOfTermsRequested 10
1883 z39.scan preferredPositionInResponse 11
1885 z39.scan numberOfTermsRequested $ntoget
1886 z39.scan preferredPositionInResponse [incr ntoget]
1888 dputs "${attr} \{$q\}"
1889 z39.scan scan "${attr} \{$q\}"
1892 show-status Ready 0 1
1895 # Procedure scan-down {attr}
1896 # attr attribute specification
1897 # This procedure is called when the user hits the Down button the scan
1898 # window. A new scan is initiated with a positive $toget passed to the
1899 # scan-response handler.
1900 proc scan-down {attr} {
1908 show-status {Scanning down} 1 0
1909 set delayRequest [list scan-down $attr]
1915 set scanView [expr $scanView + 5]
1916 set s [$w.top.list size]
1917 if {$scanView > $s} {
1918 z39 callback [list scan-response $attr [expr $s - 1] 25]
1919 set q [string range [$w.top.list get [expr $s - 1]] 8 end]
1921 z39.scan numberOfTermsRequested 10
1922 z39.scan preferredPositionInResponse 1
1923 show-status Scanning 1 0
1924 dputs "${attr} \{$q\}"
1925 z39.scan scan "${attr} \{$q\}"
1928 $w.top.list yview $scanView
1931 # Procedure scan-up {attr}
1932 # attr attribute specification
1933 # This procedure is called when the user hits the Up button the scan
1934 # window. A new scan is initiated with a negative $toget passed to the
1935 # scan-response handler.
1936 proc scan-up {attr} {
1944 show-status Scanning 1 0
1945 set delayRequest [list scan-up $attr]
1951 set scanView [expr $scanView - 5]
1952 if {$scanView < 0} {
1953 z39 callback [list scan-response $attr 0 -25]
1954 set q [string range [$w.top.list get 0] 8 end]
1956 z39.scan numberOfTermsRequested 10
1957 z39.scan preferredPositionInResponse 11
1958 show-status Scanning 1 0
1959 z39.scan scan "${attr} \{$q\}"
1962 $w.top.list yview $scanView
1965 # Procedure search-response
1966 # This procedure handles search-responses. If the search is successful
1967 # this procedure will try to retrieve a total of 20 records from the target;
1968 # however not more than $presentChunk records at a time. This procedure
1969 # affects the following globals:
1970 # $setOffset current record position offset
1971 # $setMax total number of records to be retrieved
1972 proc search-response {} {
1982 dputs "In search-response"
1984 dputs "Handling cancel"
1986 if {$delayRequest != ""} {
1994 set setMax [z39.$setNo resultCount]
1995 show-status Ready 0 1
1996 set status [z39.$setNo responseStatus]
1997 if {![string compare [lindex $status 0] NSD]} {
1998 z39.$setNo nextResultSetPosition 0
1999 set code [lindex $status 1]
2000 set msg [lindex $status 2]
2001 set addinfo [lindex $status 3]
2002 tkerror "NSD$code: $msg: $addinfo"
2005 show-message "${setMax} hits"
2010 show-status Ready 0 1
2011 set l [format "%-4d %7d" $setNo $setMax]
2012 .top.rset.m add command -label $l \
2013 -command [list recall-set $setNo]
2017 set no [z39.$setNo numberOfRecordsReturned]
2018 dputs "Returned $no records, setOffset $setOffset"
2019 add-title-lines $setNo $no $setOffset
2020 set setOffset [expr $setOffset + $no]
2022 set toGet [expr $setMax - $setOffset + 1]
2024 if {$setOffset == 1} {
2026 } elseif {$toGet > $presentChunk} {
2027 set toGet $presentChunk
2029 z39 callback {present-response}
2030 z39.$setNo present $setOffset $toGet
2031 show-status Retrieving 1 0
2035 # Procedure present-more {number}
2036 # number number of records to be retrieved
2037 # This procedure starts a present-request. The $number variable indicates
2038 # the total number of records to be retrieved. The global $presentChunk
2039 # specifies the number of records to be retrieved at a time. If $number
2040 # is the empty string all remaining records in the result set are
2042 proc present-more {number} {
2051 dputs "present-more"
2053 show-status Retrieving 1 0
2054 set delayRequest "present-more $number"
2060 dputs "setNo=$setNo"
2063 set setOffset [z39.$setNo nextResultSetPosition]
2064 dputs "setOffest=${setOffset}"
2065 dputs "setNo=${setNo}"
2066 set max [z39.$setNo resultCount]
2067 if {$max < $setOffset} {
2069 dputs "setOffset=$setOffset"
2070 show-status Ready 0 1
2073 if {![string length $number]} {
2077 if {$setMax > $max} {
2081 z39 callback {present-response}
2083 set toGet [expr $setMax - $setOffset + 1]
2087 if {$toGet > $presentChunk} {
2088 set toGet $presentChunk
2090 z39.$setNo present $setOffset $toGet
2091 show-status Retrieving 1 0
2094 # Procedure init-title-lines
2095 # Utility that cleans the main record window.
2096 proc init-title-lines {} {
2097 .data.record delete 1.0 end
2100 # Procedure recall-set {setno}
2101 # setno Set number to recall
2102 proc recall-set {setno} {
2103 add-title-lines $setno 10000 1
2106 # Procedure add-title-lines {setno no offset}
2108 # no Number of records
2109 # offset Starting offset
2110 # This procedure displays the records $offset .. $offset+$no-1 in result
2111 # set $setno in the main record window by using the display format in the
2112 # global $displayFormat
2113 proc add-title-lines {setno no offset} {
2114 global displayFormats
2115 global displayFormat
2119 dputs "add-title-lines offset=${offset} no=${no}"
2126 .bot.a.set configure -text $setno
2127 .data.record delete 1.0 end
2129 set ffunc [lindex $displayFormats $displayFormat]
2130 dputs "ffunc=$ffunc"
2131 set ffunc "display-$ffunc"
2132 for {set i 0} {$i < $no} {incr i} {
2133 set o [expr $i + $offset]
2134 set type [z39.$setno type $o]
2135 if {![string length $type]} {
2136 dputs "no more at $o"
2139 .data.record tag bind r$o <Any-Enter> {}
2140 .data.record tag bind r$o <Any-Leave> {}
2141 set insert0 [.data.record index insert]
2142 $ffunc $setno $o .data.record 1
2143 .data.record tag add r$o $insert0 insert
2144 .data.record tag bind r$o <1> \
2145 [list popup-marc $setno $o 0 0]
2149 show-status Ready 0 1
2153 # Procedure present-response
2154 # Present-response handler. The incoming records are displayed and a new
2155 # present request is performed until all records ($setMax) is returned
2157 proc present-response {} {
2165 dputs "In present-response"
2167 set no [z39.$setNo numberOfRecordsReturned]
2168 dputs "Returned $no records, setOffset $setOffset"
2169 add-title-lines $setNo $no $setOffset
2170 set setOffset [expr $setOffset + $no]
2172 dputs "Handling cancel"
2174 if {$delayRequest != ""} {
2179 set status [z39.$setNo responseStatus]
2180 if {![string compare [lindex $status 0] NSD]} {
2181 show-status Ready 0 1
2182 set code [lindex $status 1]
2183 set msg [lindex $status 2]
2184 set addinfo [lindex $status 3]
2185 tkerror "NSD$code: $msg: $addinfo"
2188 if {$no > 0 && $setOffset <= $setMax} {
2189 dputs "present-request from ${setOffset}"
2190 set toGet [expr $setMax - $setOffset + 1]
2191 if {$toGet > $presentChunk} {
2192 set toGet $presentChunk
2194 z39.$setNo present $setOffset $toGet
2196 show-status Ready 0 1
2200 # Procedure left-cursor {w}
2202 # Tries to move the cursor left in entry window $w
2203 proc left-cursor {w} {
2204 set i [$w index insert]
2212 # Procedure right-cursor {w}
2214 # Tries to move the cursor right in entry window $w
2215 proc right-cursor {w} {
2216 set i [$w index insert]
2222 # Procedure bind-fields {list returnAction escapeAction}
2223 # list list of entry widgets
2224 # returnAction return script
2225 # escapeAction escape script
2226 # Each widget in list are assigned bindings for <Tab>, <Left>, <Right>,
2227 # <Return> and <Escape>.
2228 proc bind-fields {list returnAction escapeAction} {
2229 set max [expr [llength $list]-1]
2230 for {set i 0} {$i < $max} {incr i} {
2231 bind [lindex $list $i] <Return> $returnAction
2232 bind [lindex $list $i] <Escape> $escapeAction
2234 bind [lindex $list $i] <Tab> \
2235 [list focus [lindex $list [expr $i+1]]]
2236 bind [lindex $list $i] <Left> \
2237 [list left-cursor [lindex $list $i]]
2238 bind [lindex $list $i] <Right> \
2239 [list right-cursor [lindex $list $i]]
2242 bind [lindex $list $i] <Return> $returnAction
2243 bind [lindex $list $i] <Escape> $escapeAction
2245 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
2246 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
2247 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
2249 focus [lindex $list 0]
2252 # Procedure entry-fields {parent list tlist returnAction escapeAction}
2253 # list list of frame widgets
2254 # tlist list of text to be used as lead of each entry
2255 # returnAction return script
2256 # escapeAction escape script
2257 # Makes label and entry widgets in each widget in $list.
2258 proc entry-fields {parent list tlist returnAction escapeAction} {
2261 foreach field $list {
2262 set label ${parent}.${field}.label
2263 set entry ${parent}.${field}.entry
2264 label $label -text [lindex $tlist $i] -anchor e
2265 entry $entry -width 32 -relief sunken
2266 pack $label -side left
2267 pack $entry -side right
2268 lappend alist $entry
2271 bind-fields $alist $returnAction $escapeAction
2274 # Procedure define-target-dialog
2275 # Dialog that asks for new target to be defined.
2276 proc define-target-dialog {} {
2277 set w .target-define
2283 pack $w.top.target \
2284 -side top -anchor e -pady 2
2285 entry-fields $w.top {target} \
2287 {define-target-action} {destroy .target-define}
2288 top-down-ok-cancel $w {define-target-action} 1
2291 # Procedure protocol-setup-delete
2292 # This procedure is invoked when the user tries to delete a target
2293 # definition. If user is sure, the target definition is deleted.
2294 proc protocol-setup-delete {target w} {
2295 global profile settingsChanged
2297 set a [alert "Are you sure you want to delete the target \
2298 definition $target ?"]
2301 foreach n [array names profile $target,*] {
2304 set settingsChanged 1
2306 delete-target-hotlist $target
2310 # Procedure protocol-setup-action {target w}
2311 # target target to be defined
2312 # w target definition toplevel widget
2313 # This procedure reads all appropriate globals and makes a new/modified
2314 # profile for the target. The global array $profileS contains most of the
2315 # information the user may modify.
2316 proc protocol-setup-action {target w} {
2317 global profile settingsChanged profileS
2320 set settingsChanged 1
2322 set timedef $profile($target,timeDefine)
2323 if {![string length $timedef]} {
2324 set timedef [clock seconds]
2326 set profileS($target,timeDefine) $timedef
2328 foreach n [array names profile $target,*] {
2329 set profile($n) $profileS($n)
2333 set len [$w.top.databases.list size]
2334 catch {unset profile($target,databases)}
2335 for {set i 0} {$i < $len} {incr i} {
2336 lappend profile($target,databases) [$w.top.databases.list get $i]
2340 delete-target-hotlist $target
2344 # Procedure place-force {window parent}
2345 # window new top level widget
2346 # parent parent widget used as base
2347 # Sets geometry of $window relative to $parent window.
2348 proc place-force {window parent} {
2349 set g [wm geometry $parent]
2351 set p1 [string first + $g]
2352 set p2 [string last + $g]
2354 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
2355 set y [expr 60+[string range $g [expr $p2 +1] end]]
2356 wm geometry $window +${x}+${y}
2359 # Procedure add-database-action {target w}
2360 # target target to be defined
2361 # w top level widget for the target definition
2362 # Adds the contents of .database-select.top.database.entry to list of
2364 proc add-database-action {target w} {
2367 $w.top.databases.list insert end \
2368 [.database-select.top.database.entry get]
2369 destroy .database-select
2372 # Procedure add-database {target wp}
2373 # target target to be defined
2374 # wp top level widget for the target definition
2375 # Makes a dialog in which the user enters new database
2376 proc add-database {target wp} {
2379 set w .database-select
2381 set oldFocus [focus]
2387 frame $w.top.database
2389 pack $w.top.database -side top -anchor e -pady 2
2391 entry-fields $w.top {database} \
2392 {{Database to add:}} \
2393 [list add-database-action $target $wp] {destroy .database-select}
2395 top-down-ok-cancel $w [list add-database-action $target $wp] 1
2400 # Procedure delete-database {target w}
2401 # target target to be defined
2402 # w top level widget for the target definition
2403 # Asks the user if he/she really wishes to delete a database and removes
2404 # the database from the database-list if requested.
2405 proc delete-database {target w} {
2409 foreach i [$w.top.databases.list curselection] {
2410 set b [$w.top.databases.list get $i]
2413 set a [alert "Are you sure you want to remove the database(s)${l}?"]
2415 foreach i [lsort -decreasing \
2416 [$w.top.databases.list curselection]] {
2417 $w.top.databases.list delete $i
2422 # Procedure protocol-setup {target}
2423 # target target to be defined
2424 # Makes a dialog in which the user may modify/view a target definition
2425 # (profile). The $profileS - array holds the initial definition of the
2427 proc protocol-setup {target} {
2428 global profile profileS
2431 while {[winfo exists .setup-$bno]} {
2438 wm title $w "Setup $target"
2442 if {![string length $target]} {
2445 foreach n [array names profile $target,*] {
2446 set profileS($n) $profile($n)
2449 frame $w.top.description
2452 frame $w.top.idAuthentication
2454 frame $w.top.cs-type -relief ridge -border 2
2455 frame $w.top.protocol -relief ridge -border 2
2456 frame $w.top.query -relief ridge -border 2
2457 frame $w.top.databases -relief ridge -border 2
2459 # Maximum/preferred/idAuth ...
2460 pack $w.top.description $w.top.host $w.top.port \
2461 $w.top.idAuthentication -side top -anchor e -pady 2
2463 entry-fields $w.top {description host port idAuthentication } \
2464 {{Description:} {Host:} {Port:} {Id Authentication:}} \
2465 [list protocol-setup-action $target $w] [list destroy $w]
2467 foreach sub {description host port idAuthentication} {
2469 bind $w.top.$sub.entry <Control-a> [list add-database $target $w]
2470 bind $w.top.$sub.entry <Control-d> [list delete-database $target $w]
2472 $w.top.description.entry configure -textvariable \
2473 profileS($target,description)
2474 $w.top.host.entry configure -textvariable \
2475 profileS($target,host)
2476 $w.top.port.entry configure -textvariable \
2477 profileS($target,port)
2478 $w.top.idAuthentication.entry configure -textvariable \
2479 profileS($target,authentication)
2482 pack $w.top.databases -side left -pady 2 -padx 2 -expand yes -fill both
2484 label $w.top.databases.label -text "Databases"
2485 button $w.top.databases.add -text Add \
2486 -command [list add-database $target $w]
2487 button $w.top.databases.delete -text Delete \
2488 -command [list delete-database $target $w]
2490 listbox $w.top.databases.list -geometry 14x6 \
2491 -yscrollcommand "$w.top.databases.scroll set"
2493 listbox $w.top.databases.list -width 14 -height 5\
2494 -yscrollcommand "$w.top.databases.scroll set"
2496 scrollbar $w.top.databases.scroll -orient vertical -border 1
2497 pack $w.top.databases.label -side top -fill x \
2499 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
2501 pack $w.top.databases.list -side left -fill both -expand yes \
2503 pack $w.top.databases.scroll -side right -fill y \
2505 $w.top.databases.scroll config -command "$w.top.databases.list yview"
2507 if {[info exists profile($target,databases)]} {
2508 foreach b $profile($target,databases) {
2509 $w.top.databases.list insert end $b
2513 pack $w.top.cs-type -pady 2 -padx 2 -side top -fill x
2515 label $w.top.cs-type.label -text "Transport"
2516 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" -anchor w \
2517 -variable profileS($target,comstack) -value tcpip
2518 radiobutton $w.top.cs-type.mosi -text "MOSI" -anchor w\
2519 -variable profileS($target,comstack) -value mosi
2521 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
2522 -padx 2 -side top -fill x
2525 pack $w.top.protocol -pady 2 -padx 2 -side top -fill x
2527 label $w.top.protocol.label -text "Protocol"
2528 radiobutton $w.top.protocol.z39v2 -text "Z39.50" -anchor w \
2529 -variable profileS($target,protocol) -value Z39
2530 radiobutton $w.top.protocol.sr -text "SR" -anchor w \
2531 -variable profileS($target,protocol) -value SR
2533 pack $w.top.protocol.label $w.top.protocol.z39v2 $w.top.protocol.sr \
2534 -padx 2 -side top -fill x
2537 pack $w.top.query -pady 2 -padx 2 -side top -fill x
2539 label $w.top.query.label -text "Query support"
2540 checkbutton $w.top.query.c1 -text "RPN query" -anchor w \
2541 -variable profileS($target,queryRPN)
2542 checkbutton $w.top.query.c2 -text "CCL query" -anchor w \
2543 -variable profileS($target,queryCCL)
2544 checkbutton $w.top.query.c3 -text "Result sets" -anchor w \
2545 -variable profileS($target,namedResultSets)
2547 pack $w.top.query.label -side top
2548 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
2549 -padx 2 -side top -fill x
2552 bottom-buttons $w [list {Ok} [list protocol-setup-action $target $w] \
2553 {Delete} [list protocol-setup-delete $target $w] \
2554 {Advanced} [list advanced-setup $target $bno] \
2555 {Cancel} [list destroy $w]] 0
2558 # Procedure advanced-setup {target b}
2559 # target target to be defined
2560 # b window number of target top level
2561 # Makes a dialog in which the user may modify/view advanced settings
2562 # of a target definition (profile).
2563 proc advanced-setup {target b} {
2567 set w .advanced-setup-$b
2571 wm title $w "Advanced setup $target"
2575 if {![string length $target]} {
2580 frame $w.top.largeSetLowerBound
2581 frame $w.top.smallSetUpperBound
2582 frame $w.top.mediumSetPresentNumber
2583 frame $w.top.presentChunk
2584 frame $w.top.maximumRecordSize
2585 frame $w.top.preferredMessageSize
2587 pack $w.top.largeSetLowerBound $w.top.smallSetUpperBound \
2588 $w.top.mediumSetPresentNumber $w.top.presentChunk \
2589 $w.top.maximumRecordSize $w.top.preferredMessageSize \
2590 -side top -anchor e -pady 2
2592 entry-fields $w.top {largeSetLowerBound smallSetUpperBound \
2593 mediumSetPresentNumber presentChunk maximumRecordSize \
2594 preferredMessageSize} \
2595 {{Large Set Lower Bound:} {Small Set Upper Bound:} \
2596 {Medium Set Present Number:} {Present Chunk:} \
2597 {Maximum Record Size:} {Preferred Message Size:}} \
2598 [list advanced-setup-action $target $b] [list destroy $w]
2600 $w.top.largeSetLowerBound.entry configure -textvariable \
2601 profileS($target,largeSetLowerBound)
2602 $w.top.smallSetUpperBound.entry configure -textvariable \
2603 profileS($target,smallSetUpperBound)
2604 $w.top.mediumSetPresentNumber.entry configure -textvariable \
2605 profileS($target,mediumSetPresentNumber)
2606 $w.top.presentChunk.entry configure -textvariable \
2607 profileS($target,presentChunk)
2608 $w.top.maximumRecordSize.entry configure -textvariable \
2609 profileS($target,maximumRecordSize)
2610 $w.top.preferredMessageSize.entry configure -textvariable \
2611 profileS($target,preferredMessageSize)
2613 bottom-buttons $w [list {Ok} [list advanced-setup-action $target $b] \
2614 {Cancel} [list destroy $w]] 0
2617 # Procedure advanced-setup-action {target b}
2618 # target target to be defined
2619 # b window number of target top level
2620 # This procedure is called when the user hits Ok in the advanced target
2621 # setup dialog. The temporary result is stored in the $profileS - array.
2622 proc advanced-setup-action {target b} {
2623 set w .advanced-setup-$b
2626 set profileS($target,LSLB) [$w.top.largeSetLowerBound.entry get]
2627 set profileS($target,SSUB) [$w.top.smallSetUpperBound.entry get]
2628 set profileS($target,MSPN) [$w.top.mediumSetPresentNumber.entry get]
2629 set profileS($target,presentChunk) [$w.top.presentChunk.entry get]
2630 set profileS($target,MRS) [$w.top.maximumRecordSize.entry get]
2631 set profileS($target,PMS) [$w.top.preferredMessageSize.entry get]
2633 dputs "advanced-setup-action"
2637 # Procedure database-select-action
2638 # Called when the user commits a database select change. See procedure
2640 proc database-select-action {} {
2641 set w .database-select.top
2643 foreach indx [$w.databases.list curselection] {
2644 lappend b [$w.databases.list get $indx]
2647 z39 databaseNames $b
2649 destroy .database-select
2652 # Procedure database-select
2653 # Makes a dialog in which the user may select a database
2654 proc database-select {} {
2655 set w .database-select
2660 set oldFocus [focus]
2665 frame $w.top.databases -relief ridge -border 2
2667 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
2669 label $w.top.databases.label -text "List"
2670 listbox $w.top.databases.list -width 20 -height 6 \
2671 -yscrollcommand "$w.top.databases.scroll set"
2672 scrollbar $w.top.databases.scroll -orient vertical -border 1
2673 pack $w.top.databases.label -side top -fill x \
2675 pack $w.top.databases.list -side left -fill both -expand yes \
2677 pack $w.top.databases.scroll -side right -fill y \
2679 $w.top.databases.scroll config -command "$w.top.databases.list yview"
2681 foreach b $profile($hostid,databases) {
2682 $w.top.databases.list insert end $b
2684 top-down-ok-cancel $w {database-select-action} 1
2688 # Procedure cascase-dblist-select
2689 proc cascade-dblist-select {target db} {
2690 show-target $target $db
2691 z39 databaseNames $db
2694 # Procedure cascade-dblist
2695 # Makes the Service/database list with proper databases for the target
2696 proc cascade-dblist {target base} {
2699 set w .top.service.m.dblist
2701 if {[info exists profile($target,databases)]} {
2702 foreach db $profile($target,databases) {
2703 $w add command -label $db \
2704 -command [list cascade-dblist-select $target $db]
2709 # Procedure cascade-target-list
2710 # Makes all target/databases available in the Target|Connect
2711 # menu as well as all targets in the Target|Setup menu.
2712 # This procedure is called whenever target definitions occur.
2713 proc cascade-target-list {} {
2716 foreach sub [winfo children .top.target.m.clist] {
2719 .top.target.m.clist delete 0 last
2720 foreach nn [lsort [array names profile *,host]] {
2721 if {[string length $profile($nn)]} {
2722 set ll [expr [string length $nn] - 6]
2723 set n [string range $nn 0 $ll]
2725 set nl $profile($n,windowNumber)
2726 if {[info exists profile($n,databases)]} {
2727 set ndb [llength $profile($n,databases)]
2732 .top.target.m.clist add cascade -label $n \
2733 -menu .top.target.m.clist.$nl
2734 irmenu .top.target.m.clist.$nl
2735 foreach b $profile($n,databases) {
2736 .top.target.m.clist.$nl add command -label $b \
2737 -command [list reopen-target $n $b]
2739 } elseif {$ndb == 1} {
2740 .top.target.m.clist add command -label $n -command \
2741 [list reopen-target $n [lindex $profile($n,databases) 0]]
2743 .top.target.m.clist add command -label $n -command \
2744 [list reopen-target $n {}]
2748 .top.target.m.slist delete 0 last
2749 foreach nn [lsort [array names profile *,host]] {
2750 set ll [expr [string length $nn] - 6]
2751 set n [string range $nn 0 $ll]
2753 .top.target.m.slist add command -label $n \
2754 -command [list protocol-setup $n]
2758 # Procedure query-select {i}
2759 # i Query type number (integer)
2760 # This procedure is called when the user selects a Query type. The current
2761 # query type information given by the globals $queryButtonsFind and
2762 # $queryInfoFind are affected by this operation.
2763 proc query-select {i} {
2764 global queryButtonsFind
2765 global queryInfoFind
2769 set queryInfoFind [lindex $queryInfo $i]
2770 set queryButtonsFind [lindex $queryButtons $i]
2772 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2775 # Procedure query-new-action
2776 # Commits a new query type definition by extending the globals
2777 # $queryTypes, $queryButtons and $queryInfo.
2778 proc query-new-action {} {
2782 global settingsChanged
2784 set settingsChanged 1
2785 lappend queryTypes [.query-new.top.index.entry get]
2786 lappend queryButtons {}
2787 lappend queryInfo {}
2793 # Procedure query-new
2794 # Makes a dialog in which the user is requested to enter the name of a
2800 set oldFocus [focus]
2805 -side top -anchor e -pady 2
2806 entry-fields $w.top index \
2808 query-new-action {destroy .query-new}
2809 top-down-ok-cancel $w query-new-action 1
2813 # Procedure query-delete-action {queryNo}
2814 # queryNo query type number (integer)
2815 # Procedure that deletes the query type specified by $queryNo.
2816 proc query-delete-action {queryNo} {
2820 global settingsChanged
2822 set settingsChanged 1
2824 set queryTypes [lreplace $queryTypes $queryNo $queryNo]
2825 set queryButtons [lreplace $queryButtons $queryNo $queryNo]
2826 set queryInfo [lreplace $queryInfo $queryNo $queryNo]
2827 destroy .query-delete
2831 # Procedure query-delete {queryNo}
2832 # queryNo query type number (integer)
2833 # Asks if the user really want to delete a given query type; calls
2834 # query-delete-action if 'yes'.
2835 proc query-delete {queryNo} {
2843 set n [lindex $queryTypes $queryNo]
2845 label $w.top.warning -bitmap warning
2846 message $w.top.quest -text "Are you sure you want to delete the \
2847 query type $n ?" -aspect 300
2848 pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
2849 bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
2850 {Cancel} [list destroy $w]] 1
2853 # Procedure cascade-query-list
2854 # Updates the enties below Options|Query to list all query types.
2855 proc cascade-query-list {} {
2857 set w .top.options.m.query
2860 $w.slist delete 0 last
2861 foreach n $queryTypes {
2862 $w.slist add command -label $n -command [list query-setup $i]
2867 $w.clist delete 0 last
2868 foreach n $queryTypes {
2869 $w.clist add command -label $n -command [list query-select $i]
2873 $w.dlist delete 0 last
2874 foreach n $queryTypes {
2875 $w.dlist add command -label $n -command [list query-delete $i]
2880 # Procedure save-geometry
2881 # This procedure saves the per-user related settings in ~/.clientrc.tcl.
2882 # The geometry information stored in the global array $windowGeometry is
2883 # saved. Also a few other user settings, such as current display format, are
2885 proc save-geometry {} {
2886 global windowGeometry
2889 global displayFormat
2892 global elementSetNames
2895 set windowGeometry(.) [wm geometry .]
2897 if {[catch {set f [open ~/.clientrc.tcl w]}]} {
2900 if {$hostid != "Default"} {
2901 puts $f "set hostid [list $hostid]"
2902 set b [z39 databaseNames]
2903 puts $f "set hostbase [list $b]"
2905 puts $f "set hotTargets [list $hotTargets]"
2906 puts $f "set textWrap $textWrap"
2907 puts $f "set displayFormat $displayFormat"
2908 puts $f "set popupMarcdf $popupMarcdf"
2909 puts $f "set recordSyntax $recordSyntax"
2910 puts $f "set elementSetNames $elementSetNames"
2911 foreach n [array names windowGeometry] {
2912 puts -nonewline $f "set [list windowGeometry($n)] "
2913 puts $f [list $windowGeometry($n)]
2918 # Procedure save-settings
2919 # This procedure saves the per-host related settings irtdb.tcl which
2920 # is normally kept in the directory /usr/local/lib/irtcl.
2921 # All query types and target defintion profiles are saved.
2922 proc save-settings {} {
2925 global settingsChanged
2930 if {[file writable "${libdir}/irtdb.tcl"]} {
2931 set f [open "${libdir}/irtdb.tcl" w]
2933 set f [open "irtdb.tcl" w]
2935 puts $f "# Setup file"
2937 foreach n [lsort [array names profile]] {
2938 puts $f "set [list profile($n)] [list $profile($n)]"
2940 puts $f "set queryTypes [list $queryTypes]"
2942 puts $f "set queryButtons [list $queryButtons]"
2944 puts $f "set queryInfo [list $queryInfo]"
2946 set settingsChanged 0
2949 # Procedure alert {ask}
2951 # Makes a grabbed dialog in which the user is requested to answer
2952 # "Ok" or "Cancel". This procedure returns 1 if the user hits "Ok"; 0
2957 global alertAnswer font
2960 set oldFocus [focus]
2964 label $w.top.warning -bitmap warning
2965 message $w.top.message -text $ask -aspect 300 -font $font(b,normal)
2967 pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
2970 top-down-ok-cancel $w {alert-action} 1
2975 # Procedure alert-action
2976 # Called when the user hits "Ok" in the .alert-window.
2977 proc alert-action {} {
2983 # Procedure exit-action
2984 # This procedure is called if the user exists the application
2985 proc exit-action {} {
2986 global settingsChanged
2988 if {$settingsChanged} {
2995 # Procedure listbuttonaction {w name h user i}
2996 # w menubutton widget
2997 # name name information
2998 # h handler to be invoked
2999 # user user information to be passed to handler $h
3000 # i index passed as second argument to handler $h
3001 # Utility function to emulate a listbutton. Called when the user
3002 # Modifies the listbutton. See procedure listbuttonx.
3003 proc listbuttonaction {w name h user i} {
3004 $w configure -text [lindex $name 0]
3005 $h [lindex $name 1] $user $i
3008 # Procedure listbuttonx {button no names handle user}
3009 # button menubutton widget
3010 # no initial value index (integer)
3011 # names list of name entries. The first entry in each name
3012 # entry is the actual name
3013 # handle user function to be called when the listbutton changes
3015 # user user argument to the $handle function
3016 # Makes an extended listbutton.
3017 proc listbuttonx {button no names handle user} {
3018 if {[winfo exists $button]} {
3019 $button configure -text [lindex [lindex $names $no] 0]
3020 ${button}.m delete 0 last
3022 menubutton $button -text [lindex [lindex $names $no] 0] \
3023 -width 10 -menu ${button}.m -relief raised -border 1
3026 ${button}.m configure -tearoff off
3030 foreach name $names {
3031 ${button}.m add command -label [lindex $name 0] \
3032 -command [list listbuttonaction ${button} $name \
3038 # Procedure listbutton {button no names}
3039 # button menubutton widget
3040 # no initial value index (integer)
3041 # names list of possible values.
3042 # Makes a listbutton. The functionality is emulated by the use menubutton-
3044 proc listbutton {button no names} {
3045 menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
3046 -relief raised -border 1
3049 ${button}.m configure -tearoff off
3051 foreach name $names {
3052 ${button}.m add command -label $name \
3053 -command [list ${button} configure -text $name]
3057 # Procedure listbuttonv-action {button var names i}
3058 # button menubutton widget
3059 # var global variable to be affected
3060 # names list of possible names and values
3061 # This procedure is called when the user alters a menu created by the
3062 # listbuttonv procedure. The global variable $var is updated.
3063 proc listbuttonv-action {button var names i} {
3066 set $var [lindex $names [expr $i+1]]
3067 $button configure -text [lindex $names $i]
3070 # Procedure listbuttonv {button var names}
3071 # button menubutton widget
3072 # var global variable to be affected
3073 # names List of name/value pairs, i.e. {n1 v1 n2 v2 ...}.
3074 # This procedure emulates a listbutton by means of menu/menubutton widgets.
3075 # The global variable $var is automatically updated and set to one of the
3076 # values v1, v2, ...
3077 proc listbuttonv {button var names} {
3081 eval "set val $$var"
3082 set l [llength $names]
3083 for {set i 1} {$i < $l} {incr i 2} {
3084 if {$val == [lindex $names $i]} {
3086 set n [lindex $names $i]
3090 if {[winfo exists $button]} {
3091 $button configure -text $n
3094 menubutton $button -text $n -menu ${button}.m \
3095 -relief raised -border 1
3098 ${button}.m configure -tearoff off
3100 for {set i 0} {$i < $l} {incr i 2} {
3101 ${button}.m add command -label [lindex $names $i] \
3102 -command [list listbuttonv-action $button $var $names $i]
3106 # Procedure query-add-index-action {queryNo}
3107 # queryNo query type number (integer)
3108 # Handler that makes a new query index.
3109 proc query-add-index-action {queryNo} {
3113 global queryButtonsTmp
3115 set newI [.query-add-index.top.index.entry get]
3116 lappend queryInfoTmp [list $newI {}]
3117 $w.top.index.list insert end $newI
3118 destroy .query-add-index
3119 #destroy $w.top.lines
3120 #frame $w.top.lines -relief ridge -border 2
3121 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3122 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
3125 # Procedure query-add-line
3126 # queryNo query type number (integer)
3127 # Handler that adds new query line.
3128 proc query-add-line {queryNo} {
3132 global queryButtonsTmp
3134 lappend queryButtonsTmp {I 0}
3136 #destroy $w.top.lines
3137 #frame $w.top.lines -relief ridge -border 2
3138 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3139 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
3142 # Procedure query-del-line
3143 # queryNo query type number (integer)
3144 # Handler that removes query line.
3145 proc query-del-line {queryNo} {
3149 global queryButtonsTmp
3151 set l [llength $queryButtonsTmp]
3156 set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
3157 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3160 # Procedure query-add-index
3161 # queryNo query type number (integer)
3162 # Handler that adds new query index.
3163 proc query-add-index {queryNo} {
3164 set w .query-add-index
3167 set oldFocus [focus]
3168 place-force $w .query-setup
3172 -side top -anchor e -pady 2
3173 entry-fields $w.top {index} \
3175 [list query-add-index-action $queryNo] [list destroy $w]
3176 top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
3180 # Procedure query-setup-action
3181 # queryNo query type number (integer)
3182 # Handler that updates the query information database stored in the
3183 # globals $queryInfo and $queryButtons. This procedure is executed when
3184 # the user commits the query setup changes by pressing button "Ok".
3185 proc query-setup-action {queryNo} {
3188 global queryButtonsTmp
3190 global queryButtonsFind
3191 global queryInfoFind
3193 global settingsChanged
3195 set settingsChanged 1
3197 set queryInfo [lreplace $queryInfo $queryNo $queryNo \
3199 set queryButtons [lreplace $queryButtons $queryNo $queryNo \
3201 set queryInfoFind $queryInfoTmp
3202 set queryButtonsFind $queryButtonsTmp
3204 destroy .query-setup
3205 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
3208 # Procedure activate-e-index {value no i}
3210 # no query index number
3211 # i menu index (integer)
3212 # Procedure called when listbutton is activated in the query type edit
3213 # window. The global $queryButtonsTmp is updated in this operation.
3214 proc activate-e-index {value no i} {
3215 global queryButtonsTmp
3216 global queryIndexTmp
3218 set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
3219 dputs $queryButtonsTmp
3220 set queryIndexTmp $i
3223 # Procedure activate-index {value no i}
3225 # no query index number
3226 # i menu index (integer)
3227 # Procedure called when listbutton is activated in the main query
3228 # window. The global $queryButtonsFind is updated in this operation.
3229 proc activate-index {value no i} {
3230 global queryButtonsFind
3232 set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
3234 dputs "queryButtonsFind $queryButtonsFind"
3237 # Procedure update-attr
3238 # This procedure creates listbuttons for all bib-1 attributes except
3239 # the use-attribute in the .index-setup window.
3240 # The globals $relationTmpValue, $positionTmpValue, $structureTmpValue,
3241 # $truncationTmpValue and $completenessTmpValue are maintainted by the
3243 proc update-attr {} {
3245 listbuttonv $w.top.relation.b relationTmpValue\
3246 {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
3247 {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
3248 {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
3249 listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
3250 {First in field} 1 {First in subfield} 2 {Any position in field} 3}
3251 listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
3252 {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list} 6 \
3253 {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
3254 {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
3255 {local-number} 107 {string} 108 {numeric string} 109}
3256 listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
3257 {Left} 2 {Left and right} 3 {No truncation} 100 \
3258 {Process #} 101 {Re-1} 102 {Re-2} 103}
3259 listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
3260 {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
3263 # Procedure use-attr {init}
3265 # This procedure creates a listbox with several Bib-1 use attributes.
3266 # If $init is 1 the listbox is created with the attributes. If $init
3267 # is 0 the current selection of the listbox is read and the global
3268 # $useTmpValue is set to the current use-value.
3269 proc use-attr {init} {
3281 {BNB card number} 10
3282 {BGF(sic) number} 11
3284 {Dewey classification} 13
3285 {UDC classification} 14
3286 {Bliss classification} 15
3288 {NLM call number} 17
3289 {NAL call number} 18
3290 {MOS call number} 19
3291 {Local classification} 20
3292 {Subject heading} 21
3294 {BDI-index-subject} 23
3298 {LC-subject-heading} 27
3299 {RVM-subject-heading} 28
3300 {Local subject index} 29
3302 {Date of publication} 31
3303 {Date of acquisition} 32
3305 {Title-collective} 34
3308 {Title-added-title-page} 37
3312 {Title-other-variant} 41
3314 {Title-abbreviated} 43
3318 {Subject-subdivision} 47
3319 {Number-natl-bibliography} 48
3320 {Number-legal-deposit} 49
3321 {Number-govt-publication} 50
3322 {Number-publisher-for-music} 51
3324 {Number-local-call} 53
3326 {Code-geographic-area} 55
3327 {Code-institution} 56
3329 {Name-geographic} 58
3330 {Place-publication} 59
3332 {Microform-generation} 61
3339 {Author-name-personal} 1004
3340 {Author-name-corporate} 1005
3341 {Author-name-conference} 1006
3342 {Identifier-standard} 1007
3343 {Subject-LC-children's} 1008
3344 {Subject-name-personal} 1009
3346 {Date/time added to database} 1011
3347 {Date/time last modified} 1012
3348 {Authority/format identifier} 1013
3350 {Concept-reference} 1015
3352 {Server choice} 1017
3354 {Record source} 1019
3357 {Geographic class} 1022
3361 {Related periodical} 1026
3362 {Report number} 1027
3364 {Thematic number} 1030
3365 {Material type} 1031
3373 set l [llength $attr]
3378 for {set i 0} {$i < $l} {incr i} {
3379 $w.top.use.list insert end [lindex $attr $i]
3381 if {$useTmpValue == [lindex $attr $i]} {
3387 $w.top.use.list selection clear 0 end
3388 $w.top.use.list selection set $s $s
3390 $w.top.use.list select from $s
3391 $w.top.use.list select to $s
3397 $w.top.use.list yview $s
3399 set lno [lindex [$w.top.use.list curselection] 0]
3400 set i [expr $lno+$lno+1]
3401 set useTmpValue [lindex $attr $i]
3402 dputs "useTmpValue=$useTmpValue"
3406 # Procedure index-setup-action {oldAttr queryNo indexNo}
3407 # oldAttr original attributes (?)
3408 # queryNo query number
3409 # indexNo index number
3410 # Commits setup of a query index. The mapping from the index to
3411 # the Bib-1 attributes are handled by this function.
3412 proc index-setup-action {oldAttr queryNo indexNo} {
3413 set attr [lindex $oldAttr 0]
3416 global relationTmpValue
3417 global structureTmpValue
3418 global truncationTmpValue
3419 global completenessTmpValue
3420 global positionTmpValue
3425 dputs "index-setup-action"
3426 dputs "queryNo $queryNo"
3427 dputs "indexNo $indexNo"
3428 if {$useTmpValue > 0} {
3429 lappend attr "1=$useTmpValue"
3431 if {$relationTmpValue > 0} {
3432 lappend attr "2=$relationTmpValue"
3434 if {$positionTmpValue > 0} {
3435 lappend attr "3=$positionTmpValue"
3437 if {$structureTmpValue > 0} {
3438 lappend attr "4=$structureTmpValue"
3440 if {$truncationTmpValue > 0} {
3441 lappend attr "5=$truncationTmpValue"
3443 if {$completenessTmpValue > 0} {
3444 lappend attr "6=$completenessTmpValue"
3446 dputs "new attr $attr"
3447 set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
3448 destroy .index-setup
3451 # Procedure index-setup {attr queryNo indexNo}
3452 # attr original attributes
3453 # queryNo query number
3454 # indexNo index number
3455 # Makes a window with settings of a given query index which the user
3456 # may inspect/modify.
3457 proc index-setup {attr queryNo indexNo} {
3460 global relationTmpValue
3461 global structureTmpValue
3462 global truncationTmpValue
3463 global completenessTmpValue
3464 global positionTmpValue
3466 set relationTmpValue 0
3467 set truncationTmpValue 0
3468 set structureTmpValue 0
3469 set positionTmpValue 0
3470 set completenessTmpValue 0
3476 set n [lindex $attr 0]
3477 wm title $w "Index setup $n"
3481 set len [llength $attr]
3482 for {set i 1} {$i < $len} {incr i} {
3483 set q [lindex $attr $i]
3484 set l [string first = $q]
3486 set t [string range $q 0 [expr $l - 1]]
3487 set v [string range $q [expr $l + 1] end]
3490 { set useTmpValue $v }
3492 { set relationTmpValue $v }
3494 { set positionTmpValue $v }
3496 { set structureTmpValue $v }
3498 { set truncationTmpValue $v }
3500 { set completenessTmpValue $v }
3505 frame $w.top.use -relief ridge -border 2
3506 frame $w.top.relation -relief ridge -border 2
3507 frame $w.top.position -relief ridge -border 2
3508 frame $w.top.structure -relief ridge -border 2
3509 frame $w.top.truncation -relief ridge -border 2
3510 frame $w.top.completeness -relief ridge -border 2
3516 pack $w.top.use -side left -pady 6 -padx 6 -fill y
3518 label $w.top.use.label -text "Use"
3520 listbox $w.top.use.list -width 26 \
3521 -yscrollcommand "$w.top.use.scroll set"
3523 listbox $w.top.use.list -geometry 26x10 \
3524 -yscrollcommand "$w.top.use.scroll set"
3526 scrollbar $w.top.use.scroll -orient vertical -border 1
3527 pack $w.top.use.label -side top -fill x \
3529 pack $w.top.use.list -side left -fill both -expand yes \
3531 pack $w.top.use.scroll -side right -fill y \
3533 $w.top.use.scroll config -command "$w.top.use.list yview"
3537 # Relation Attributes
3539 pack $w.top.relation -pady 6 -padx 6 -side top
3540 label $w.top.relation.label -text "Relation" -width 18
3542 pack $w.top.relation.label $w.top.relation.b -fill x
3544 # Position Attributes
3546 pack $w.top.position -pady 6 -padx 6 -side top
3547 label $w.top.position.label -text "Position" -width 18
3549 pack $w.top.position.label $w.top.position.b -fill x
3551 # Structure Attributes
3553 pack $w.top.structure -pady 6 -padx 6 -side top
3554 label $w.top.structure.label -text "Structure" -width 18
3556 pack $w.top.structure.label $w.top.structure.b -fill x
3558 # Truncation Attributes
3560 pack $w.top.truncation -pady 6 -padx 6 -side top
3561 label $w.top.truncation.label -text "Truncation" -width 18
3563 pack $w.top.truncation.label $w.top.truncation.b -fill x
3565 # Completeness Attributes
3567 pack $w.top.completeness -pady 6 -padx 6 -side top
3568 label $w.top.completeness.label -text "Completeness" -width 18
3570 pack $w.top.completeness.label $w.top.completeness.b -fill x
3573 bottom-buttons $w [list \
3574 {Ok} [list index-setup-action $attr $queryNo $indexNo] \
3575 {Cancel} [list destroy $w]] 0
3579 # Procedure query-edit-index {queryNo}
3580 # queryNo query number
3581 # Determines if a selection of an index is active. If one is selected
3582 # the index-setup dialog is started.
3583 proc query-edit-index {queryNo} {
3587 set i [lindex [$w.top.index.list curselection] 0]
3588 if {![string length $i]} {
3591 set attr [lindex $queryInfoTmp $i]
3592 dputs "Editing no $i $attr"
3593 index-setup $attr $queryNo $i
3596 # Procedure query-delete-index {queryNo}
3597 # queryNo query number
3598 # Determines if a selection of an index is active. If one is selected
3599 # the index is deleted.
3600 proc query-delete-index {queryNo} {
3602 global queryButtonsTmp
3605 set i [lindex [$w.top.index.list curselection] 0]
3606 if {![string length $i]} {
3609 set queryInfoTmp [lreplace $queryInfoTmp $i $i]
3610 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3611 $w.top.index.list delete $i
3614 # Procedure query-setup {queryNo}
3615 # queryNo query number
3616 # Makes a dialog in which a query type an be customized.
3617 proc query-setup {queryNo} {
3623 global queryButtonsTmp
3625 global queryIndexTmp
3628 set queryName [lindex $queryTypes $queryNo]
3629 set queryInfoTmp [lindex $queryInfo $queryNo]
3630 set queryButtonsTmp [lindex $queryButtons $queryNo]
3635 wm title $w "Query setup $queryName"
3639 frame $w.top.lines -relief ridge -border 2
3641 pack $w.top.lines -side left -pady 6 -padx 6 -fill y
3645 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3647 button $w.top.lines.add -text "Add" \
3648 -command [list query-add-line $queryNo]
3649 button $w.top.lines.del -text "Remove" \
3650 -command [list query-del-line $queryNo]
3652 pack $w.top.lines.del -fill x -side bottom
3653 pack $w.top.lines.add -fill x -pady 10 -side bottom
3657 frame $w.top.index -relief ridge -border 2
3658 pack $w.top.index -pady 6 -padx 6 -side right -fill y
3660 listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
3661 scrollbar $w.top.index.scroll -orient vertical -border 1 \
3662 -command [list $w.top.index.list yview]
3663 bind $w.top.index.list <Double-1> [list query-edit-index $queryNo]
3665 pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
3666 pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
3669 $w.top.index.list selection clear 0 end
3670 $w.top.index.list selection set 0 0
3672 $w.top.index.list select from 0
3673 $w.top.index.list select to 0
3676 foreach x $queryInfoTmp {
3677 $w.top.index.list insert end [lindex $x 0]
3681 bottom-buttons $w [list \
3682 Ok [list query-setup-action $queryNo] \
3683 Add [list query-add-index $queryNo] \
3684 Edit [list query-edit-index $queryNo] \
3685 Delete [list query-delete-index $queryNo] \
3686 Cancel [list destroy $w]] 0
3689 # Procedure index-clear
3690 # Handler that clears the search entry fields.
3691 proc index-clear {} {
3692 global queryButtonsFind
3695 foreach b $queryButtonsFind {
3696 .lines.$i.e delete 0 end
3701 # Procedure index-query
3702 # The purpose of this function is to read the user's query and convert
3703 # it to the prefix query that IrTcl/YAZ uses to represent an RPN query.
3704 # Each entry in a search fields takes the form
3706 # Here, relOp is an optional relational operator and one of:
3708 # which sets the Bib-1 relation to greater-than, less-than, etc.
3709 # The ? (question-mark) is also optional. A (?) on left-side indicates
3710 # left truncation; (?) on right-side indicates right-truncation; (?)
3711 # on both sides indicates both-left-and-right truncation.
3712 proc index-query {} {
3713 global queryButtonsFind
3714 global queryInfoFind
3719 foreach b $queryButtonsFind {
3720 set term [string trim [.lines.$i.e get]]
3722 set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
3725 set len [string length $term]
3729 if {[string index $term 0] == ">"} {
3730 if {[string index $term 1] == "=" } {
3731 set term [string trim [string range $term 2 $len]]
3734 set term [string trim [string range $term 1 $len]]
3737 } elseif {[string index $term 0] == "<"} {
3738 if {[string index $term 1] == "=" } {
3739 set term [string trim [string range $term 2 $len]]
3741 } elseif {[string index $term 1] == ">"} {
3742 set term [string trim [string range $term 2 $len]]
3745 set term [string trim [string range $term 1 $len]]
3750 set len [string length $term]
3754 if {[string index $term $len] == "?"} {
3756 set term [string range $term 0 [expr $len - 1]]
3758 if {[string index $term 0] == "?"} {
3760 set term [string range $term 1 end]
3762 set term "\{${term}\}"
3763 if {$right && $left} {
3764 set term "@attr 5=3 ${term}"
3766 set term "@attr 5=1 ${term}"
3768 set term "@attr 5=2 ${term}"
3770 if {$relation != ""} {
3771 set term "@attr 2=${relation} ${term}"
3774 set term "@attr $a ${term}"
3777 set qs "@and ${qs} ${term}"
3788 # Procedure index-focus-in {w i}
3791 # This procedure handles <FocusIn> events. A red border is drawed
3792 # around the active search entry field when tk3.6 is used (tk4.X
3793 # makes a black focus border itself).
3794 proc index-focus-in {w i} {
3795 global curIndexEntry
3798 $w.$i configure -background red
3800 set curIndexEntry $i
3803 # Procedure index-lines {w readOp buttonInfo queryInfo handle}
3804 # w search fields entry frame
3805 # realOp if true, search-request bindings are bound to the entries.
3806 # buttonInfo query type button information
3807 # queryInfo query type field information
3808 # handle handler called a when a 'listbutton' changes its value
3809 # Makes one or more search areas - with listbuttons on the left
3810 # and entries on the right.
3811 proc index-lines {w realOp buttonInfo queryInfo handle} {
3813 foreach b $buttonInfo {
3814 if {! [winfo exists $w.$i]} {
3816 frame $w.$i -border 0
3818 frame $w.$i -background white -border 1
3821 listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
3824 if {! [winfo exists $w.$i.e]} {
3825 entry $w.$i.e -width 32 -relief sunken -border 1
3826 bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
3828 bind $w.$i.e <FocusOut> [list $w.$i configure \
3831 pack $w.$i.l -side left
3832 pack $w.$i.e -side left -fill x -expand yes
3833 pack $w.$i -side top -fill x -padx 2 -pady 2
3835 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
3836 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
3838 bind $w.$i.e <Return> {search-request 0}
3841 pack $w.$i.l -side left
3842 pack $w.$i -side top -fill x -padx 2 -pady 2
3847 while {[winfo exists $w.$j]} {
3859 bind $w.$j.e <Tab> "focus $w.$k.e"
3865 bind $w.$i.e <Tab> "focus $w.0.e"
3871 # Procedure search-fields {w buttondefs}
3872 # w search fields entry frame
3873 # buttondefs button definitions
3874 # Makes search entry fields and listbuttons.
3875 # Note: This procedure is not used elsewhere. The index-lines
3876 # procedure is used instead.
3877 proc search-fields {w buttondefs} {
3879 foreach buttondef $buttondefs {
3880 frame $w.$i -background white
3882 listbutton $w.$i.l 0 $buttondef
3883 entry $w.$i.e -width 32 -relief sunken
3885 pack $w.$i.l -side left
3886 pack $w.$i.e -side left -fill x -expand yes
3888 pack $w.$i -side top -fill x -padx 2 -pady 2
3890 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
3891 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
3899 bind $w.$j.e <Tab> "focus $w.$k.e \n
3900 $w.$k configure -background red \n
3901 $w.$j configure -background white"
3904 bind $w.$i.e <Tab> "focus $w.0.e \n
3905 $w.0 configure -background red \n
3906 $w.$i configure -background white"
3908 $w.0 configure -background red
3911 # Init: The geometry information for the main window is set - either
3912 # to a default value or to the value in windowGeometry(.)
3913 if {[catch {set g $windowGeometry(.)}]} {
3914 wm geometry . 420x340
3919 # Init: Presentation formats are read.
3922 # Init: The main window is defined.
3923 frame .top -border 1 -relief raised
3924 frame .lines -border 1 -relief raised
3925 frame .mid -border 1 -relief raised
3926 frame .data -border 1 -relief raised
3927 frame .bot -border 1 -relief raised
3928 pack .top .lines .mid -side top -fill x
3929 pack .data -side top -fill both -expand yes
3932 # Init: Definition of File menu.
3933 menubutton .top.file -text File -menu .top.file.m
3935 .top.file.m add command -label {Save settings} -command {save-settings}
3936 .top.file.m add separator
3937 .top.file.m add command -label Exit -command {exit-action}
3939 # Init: Definition of Target menu.
3940 menubutton .top.target -text Target -menu .top.target.m
3941 irmenu .top.target.m
3942 .top.target.m add cascade -label Connect -menu .top.target.m.clist
3943 .top.target.m add command -label Disconnect -command {close-target}
3944 .top.target.m add command -label About -command {about-target}
3945 .top.target.m add cascade -label Setup -menu .top.target.m.slist
3946 .top.target.m add command -label {Setup new} -command {define-target-dialog}
3947 .top.target.m add separator
3948 set-target-hotlist 0
3950 configure-disable-e .top.target.m 1
3951 configure-disable-e .top.target.m 2
3953 irmenu .top.target.m.clist
3954 irmenu .top.target.m.slist
3957 # Init: Definition of Service menu.
3958 menubutton .top.service -text Service -menu .top.service.m
3959 irmenu .top.service.m
3960 .top.service.m add cascade -label Database -menu .top.service.m.dblist
3961 .top.service.m add cascade -label Present -menu .top.service.m.present
3962 irmenu .top.service.m.present
3963 .top.service.m.present add command -label {10 More} \
3964 -command [list present-more 10]
3965 .top.service.m.present add command -label All \
3966 -command [list present-more {}]
3967 .top.service.m add command -label Search -command {search-request 0}
3968 .top.service.m add command -label Scan -command {scan-request}
3969 .top.service.m add command -label Explain -command \
3970 {explain-refresh $hostid {ready-response {}} }
3972 .top.service configure -state disabled
3974 irmenu .top.service.m.dblist
3976 # Init: Definition of Set menu.
3977 menubutton .top.rset -text Set -menu .top.rset.m
3979 .top.rset.m add command -label Load -command {load-set}
3980 .top.rset.m add separator
3982 # Init: Definition of the Options menu.
3983 menubutton .top.options -text Options -menu .top.options.m
3984 irmenu .top.options.m
3985 .top.options.m add cascade -label Query -menu .top.options.m.query
3986 .top.options.m add cascade -label Format -menu .top.options.m.formats
3987 .top.options.m add cascade -label Wrap -menu .top.options.m.wrap
3988 .top.options.m add cascade -label Syntax -menu .top.options.m.syntax
3989 .top.options.m add cascade -label Elements -menu .top.options.m.elements
3990 .top.options.m add radiobutton -label Debug -variable debugMode -value 1
3992 # Init: Definition of the Options|Query menu.
3993 irmenu .top.options.m.query
3994 .top.options.m.query add cascade -label Select \
3995 -menu .top.options.m.query.clist
3996 .top.options.m.query add cascade -label Edit \
3997 -menu .top.options.m.query.slist
3998 .top.options.m.query add command -label New \
3999 -command {query-new}
4000 .top.options.m.query add cascade -label Delete \
4001 -menu .top.options.m.query.dlist
4003 irmenu .top.options.m.query.slist
4004 irmenu .top.options.m.query.clist
4005 irmenu .top.options.m.query.dlist
4008 # Init: Definition of the Options|Formats menu.
4009 irmenu .top.options.m.formats
4011 foreach f $displayFormats {
4012 .top.options.m.formats add radiobutton -label $f -value $i \
4013 -command [list set-display-format $i] -variable displayFormat
4017 # Init: Definition of the Options|Wrap menu.
4018 irmenu .top.options.m.wrap
4019 .top.options.m.wrap add radiobutton -label Character \
4020 -value char -variable textWrap -command {set-wrap char}
4021 .top.options.m.wrap add radiobutton -label Word \
4022 -value word -variable textWrap -command {set-wrap word}
4023 .top.options.m.wrap add radiobutton -label None \
4024 -value none -variable textWrap -command {set-wrap none}
4026 # Init: Definition of the Options|Syntax menu.
4027 irmenu .top.options.m.syntax
4028 .top.options.m.syntax add radiobutton -label None \
4029 -value None -variable recordSyntax
4030 .top.options.m.syntax add separator
4031 .top.options.m.syntax add radiobutton -label USMARC \
4032 -value USMARC -variable recordSyntax
4033 .top.options.m.syntax add radiobutton -label UNIMARC \
4034 -value UNIMARC -variable recordSyntax
4035 .top.options.m.syntax add radiobutton -label UKMARC \
4036 -value UKMARC -variable recordSyntax
4037 .top.options.m.syntax add radiobutton -label DANMARC \
4038 -value DANMARC -variable recordSyntax
4039 .top.options.m.syntax add radiobutton -label FINMARC \
4040 -value FINMARC -variable recordSyntax
4041 .top.options.m.syntax add radiobutton -label NORMARC \
4042 -value NORMARC -variable recordSyntax
4043 .top.options.m.syntax add radiobutton -label PICAMARC \
4044 -value PICAMARC -variable recordSyntax
4045 .top.options.m.syntax add separator
4046 .top.options.m.syntax add radiobutton -label SUTRS \
4047 -value SUTRS -variable recordSyntax
4048 .top.options.m.syntax add separator
4049 .top.options.m.syntax add radiobutton -label GRS1 \
4050 -value GRS1 -variable recordSyntax
4052 # Init: Definition of the Options|Elements menu.
4053 irmenu .top.options.m.elements
4054 .top.options.m.elements add radiobutton -label Unspecified \
4055 -value None -variable elementSetNames
4056 .top.options.m.elements add radiobutton -label Full \
4057 -value F -variable elementSetNames
4058 .top.options.m.elements add radiobutton -label Brief \
4059 -value B -variable elementSetNames
4061 # Init: Definition of Help menu.
4062 menubutton .top.help -text "Help" -menu .top.help.m
4065 .top.help.m add command -label "Help on help" \
4066 -command {tkerror "Help on help not available. Sorry"}
4067 .top.help.m add command -label "About" -command {about-origin}
4069 # Init: Pack menu bar items.
4070 pack .top.file .top.target .top.service .top.rset .top.options -side left
4071 pack .top.help -side right
4073 # Init: Define query area.
4074 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
4076 button .mid.search -text Search -command {search-request 0} \
4078 button .mid.scan -text Scan \
4079 -command scan-request -state disabled
4080 button .mid.present -text {Present} -command [list present-more 10] \
4083 button .mid.clear -text Clear -command index-clear
4084 pack .mid.search .mid.scan .mid.present .mid.clear -side left \
4087 # Init: Define record area in main window.
4088 text .data.record -font fixed -height 2 -width 20 -wrap none -borderwidth 0 \
4089 -relief flat -yscrollcommand [list .data.scroll set] \
4090 -wrap $textWrap -background grey85
4091 scrollbar .data.scroll -command [list .data.record yview]
4093 .data.record configure -takefocus 0
4094 .data.scroll configure -takefocus 0
4097 pack .data.scroll -side right -fill y
4098 pack .data.record -expand yes -fill both
4101 # Init: Define standards tags. These are used in the display
4102 # format procedures.
4104 .data.record tag configure marc-tag -foreground blue
4105 .data.record tag configure marc-id -foreground red
4107 .data.record tag configure marc-tag -foreground black
4108 .data.record tag configure marc-id -foreground black
4110 .data.record tag configure marc-data -foreground black
4111 .data.record tag configure marc-head -font $font(n,normal) \
4112 -foreground brown -relief raised -borderwidth 1
4113 .data.record tag configure marc-small-head -foreground brown
4114 .data.record tag configure marc-pref \
4115 -font $font(n,normal) -foreground blue
4116 .data.record tag configure marc-text \
4117 -font $font(n,normal) -foreground black
4118 .data.record tag configure marc-it \
4119 -font $font(n,normal) -foreground black
4121 # Init: Define logo.
4122 button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
4124 .bot.logo configure -takefocus 0
4126 # Init: Define status information fields at the bottom.
4128 pack .bot.a -side left -fill x
4129 pack .bot.logo -side right -padx 2 -pady 2 -ipadx 1
4131 message .bot.a.target -text {} -aspect 2000 -border 1
4133 label .bot.a.status -text "Not connected" -width 15 -relief \
4134 sunken -anchor w -border 1
4135 label .bot.a.set -text "" -width 5 -relief \
4136 sunken -anchor w -border 1
4137 label .bot.a.message -text "" -width 15 -relief \
4138 sunken -anchor w -border 1
4140 pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
4141 pack .bot.a.status .bot.a.set .bot.a.message \
4142 -side left -padx 2 -pady 2 -ipadx 1 -ipady 1
4144 # Init: Determine if the IrTcl extension is already there. If
4145 # not, then dynamically load the IrTcl extension.
4146 if {[catch {ir z39}]} {
4147 set e [info sharedlibextension]
4148 puts -nonewline "Loading irtcl$e ..."
4149 load ${libdir}/irtcl$e irtcl
4154 if {[file exists ${libdir}/explain.tcl]} {
4155 source ${libdir}/explain.tcl
4158 if {[file exists ${libdir}/setup.tcl]} {
4159 source ${libdir}/setup.tcl
4162 # Init: Uncomment this line if you wan't to enable logging.
4163 ir-log-init all irtcl irtcl.log
4165 # Init: If hostid is a valid target, a new connection will be established
4167 if {[string compare $hostid Default]} {
4168 catch {open-target $hostid $hostbase}
4171 # Init: Enable the logo.