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.109 1999-12-12 00:25:59 adam
8 # Updated list of preconfigure targets.
10 # Revision 1.108 1999/11/30 14:05:58 adam
11 # Updated for new location of YAZ headers.
13 # Revision 1.107 1999/02/11 11:30:08 adam
16 # Revision 1.106 1998/06/10 13:22:47 adam
19 # Revision 1.105 1998/06/10 13:00:45 adam
20 # Added ir-version command.
22 # Revision 1.104 1998/02/12 13:32:41 adam
23 # Updated configuration system.
25 # Revision 1.103 1998/01/30 13:30:50 adam
26 # Name of target database is irtdb.tcl instead of clientrc.tcl.
28 # Revision 1.102 1997/11/19 13:19:54 adam
31 # Revision 1.101 1997/11/19 11:20:56 adam
32 # New target profile format - associative arrrays instead of LONG lists.
34 # Revision 1.100 1997/09/09 10:19:50 adam
35 # New MSV5.0 port with fewer warnings.
37 # Revision 1.99 1997/04/13 19:00:37 adam
38 # Added support for Tcl8.0/Tk8.0.
39 # New command ir-log-init to setup yaz logging facilities.
41 # Revision 1.98 1996/11/14 17:11:04 adam
42 # Added Explain documentaion.
44 # Revision 1.97 1996/09/13 10:54:22 adam
45 # Started work on Explain in client.
47 # Revision 1.96 1996/08/09 15:30:18 adam
48 # Procedure destroyGW modified to handle multiple calls - probably an
49 # error introduced by tk4.1 patch level 1.
51 # Revision 1.95 1996/07/26 09:15:08 adam
52 # IrTcl version 1.2 patch level 1.
54 # Revision 1.94 1996/07/25 15:55:34 adam
55 # IrTcl version 1.2 release.
57 # Revision 1.93 1996/06/28 08:43:54 adam
58 # Moved towards version 1.2.
60 # Revision 1.92 1996/03/29 16:04:30 adam
61 # Work on GRS-1 presentation.
63 # Revision 1.91 1996/03/27 17:00:53 adam
64 # Fix: main defined when using Tk3.6; it shouldn't be.
66 # Revision 1.90 1996/03/20 13:54:02 adam
67 # The Tcl_File structure is only manipulated in the Tk-event interface
70 # Revision 1.89 1996/03/05 09:16:04 adam
71 # Sets tearoff to off on several menus.
73 # Revision 1.88 1996/01/23 15:24:09 adam
74 # Wrore more comments.
76 # Revision 1.87 1996/01/22 17:13:34 adam
79 # Revision 1.86 1996/01/22 09:29:01 adam
82 # Revision 1.85 1996/01/19 16:22:36 adam
83 # New method: apduDump - returns information about last incoming APDU.
85 # Revision 1.84 1996/01/11 13:12:10 adam
88 # Revision 1.83 1995/11/28 17:26:36 adam
89 # Removed Carriage return from ir-tcl.c!
90 # Removed misc. debug logs.
92 # Revision 1.82 1995/11/02 08:47:56 adam
93 # Text widgets are flat now.
95 # Revision 1.81 1995/10/19 10:34:43 adam
96 # More configurable client.
98 # Revision 1.80 1995/10/18 17:20:32 adam
99 # Work on target setup in client.tcl.
101 # Revision 1.79 1995/10/18 16:42:37 adam
102 # New settings: smallSetElementSetNames and mediumSetElementSetNames.
104 # Revision 1.78 1995/10/18 15:45:36 quinn
105 # *** empty log message ***
107 # Revision 1.77 1995/10/18 15:37:46 adam
108 # Piggy-back present.
110 # Revision 1.76 1995/10/18 15:15:20 adam
113 # Revision 1.75 1995/10/17 14:18:05 adam
114 # Minor changes in presentation formats.
116 # Revision 1.74 1995/10/17 12:18:57 adam
117 # Bug fix: when target connection closed, the connection was not
118 # properly reestablished.
120 # Revision 1.73 1995/10/17 10:58:06 adam
121 # More work on presentation formats.
123 # Revision 1.72 1995/10/16 17:00:52 adam
124 # New setting: elementSetNames.
125 # Various client improvements. Medium presentation format looks better.
127 # Revision 1.71 1995/10/13 15:35:27 adam
128 # Relational operators may be used in search entries - changes
129 # in proc index-query.
131 # Revision 1.70 1995/10/12 14:46:52 adam
132 # Better record popup windows. Next/prev buttons in popup record windows.
133 # The record position in the raw format is much more visible.
135 # Revision 1.69 1995/09/21 13:42:54 adam
138 # Revision 1.68 1995/09/21 13:11:49 adam
139 # Support of dynamic loading.
140 # Test script uses load command if necessary.
142 # Revision 1.67 1995/09/20 14:35:19 adam
145 # Revision 1.66 1995/08/29 15:30:13 adam
146 # Work on GRS records.
148 # Revision 1.65 1995/08/24 15:39:09 adam
151 # Revision 1.64 1995/08/24 15:33:02 adam
154 # Revision 1.63 1995/08/04 13:20:48 adam
155 # Buttons at the bottom are slightly smaller.
157 # Revision 1.62 1995/08/04 11:32:37 adam
158 # More work on output queue. Memory related routines moved
161 # Revision 1.61 1995/07/20 08:09:39 adam
162 # client.tcl: Targets removed from hotTargets list when targets
163 # are removed/modified.
164 # ir-tcl.c: More work on triggerResourceControl.
166 # Revision 1.60 1995/06/30 16:30:19 adam
169 # Revision 1.59 1995/06/29 14:06:25 adam
170 # Another bug in install fixed. Configure searches for more versions of yaz.
172 # Revision 1.58 1995/06/29 12:34:06 adam
173 # IrTcl now works with both tk4.0b4/tcl7.4b4 and tk3.6/tcl7.3
175 # Revision 1.57 1995/06/29 09:20:30 adam
176 # Target entries in cascade menus are sorted.
178 # Revision 1.56 1995/06/27 19:03:48 adam
179 # Bug fix in do_present in ir-tcl.c: p->set_child member weren't set.
180 # nextResultSetPosition used instead of setOffset.
182 # Revision 1.55 1995/06/27 17:10:37 adam
183 # Bug fix: install procedure didn't work on some systems.
184 # Error turned up when clientrc.tcl was't present.
186 # Revision 1.54 1995/06/27 14:41:03 adam
187 # Bug fix in search-response. Didn't always observe non-surrogate diagnostics.
189 # Revision 1.53 1995/06/26 12:40:09 adam
190 # Client defines its own tkerror.
191 # User may specify 'no preferredRecordSyntax'.
193 # Revision 1.52 1995/06/22 13:14:59 adam
194 # Feature: SUTRS. Setting getSutrs implemented.
195 # Work on display formats.
196 # Preferred record syntax can be set by the user.
198 # Revision 1.51 1995/06/21 11:11:00 adam
199 # Bug fix: libdir undefined in about-origin.
201 # Revision 1.50 1995/06/21 11:04:48 adam
202 # Uses GNU autoconf 2.3.
203 # Install procedure implemented.
204 # boook bitmaps moved to sub directory bitmaps.
206 # Revision 1.49 1995/06/20 14:16:42 adam
207 # More work on cancel mechanism.
209 # Revision 1.48 1995/06/20 08:07:23 adam
210 # New setting: failInfo.
211 # Working on better cancel mechanism.
213 # Revision 1.47 1995/06/19 14:05:29 adam
214 # Bug fix: asked for SUTRS.
216 # Revision 1.46 1995/06/19 13:06:06 adam
217 # New define: IR_TCL_VERSION.
219 # Revision 1.45 1995/06/19 08:08:44 adam
220 # client.tcl: hotTargets now contain both database and target name.
221 # ir-tcl.c: setting protocol edited. Errors in callbacks are logged
222 # by logf(LOG_WARN, ...) calls.
224 # Revision 1.44 1995/06/16 14:55:18 adam
225 # Book logo mirrored.
227 # Revision 1.43 1995/06/16 14:41:05 adam
228 # Scan line entries can be copied to a search entry.
230 # Revision 1.42 1995/06/16 12:28:13 adam
231 # Implemented preferredRecordSyntax.
232 # Minor changes in diagnostic handling.
233 # Record list deleted when connection closes.
235 # Revision 1.41 1995/06/14 15:07:59 adam
236 # Bug fix in cascade-target-list. Uses yaz-version.h.
238 # Revision 1.40 1995/06/14 13:37:17 adam
239 # Setting recordType implemented.
240 # Setting implementationVersion implemented.
241 # Settings implementationId / implementationName edited.
243 # Revision 1.39 1995/06/14 12:16:22 adam
244 # hotTargets, textWrap and displayFormat saved in clientg.tcl.
246 # Revision 1.38 1995/06/14 07:22:45 adam
247 # Target definitions can be deleted.
248 # Listbox used in the query definition dialog.
250 # Revision 1.37 1995/06/13 14:37:59 adam
251 # Work on query setup.
252 # Better about origin/target.
253 # Better presentation formats.
255 # Revision 1.36 1995/06/13 07:42:14 adam
256 # Bindings removed from text widgets.
258 # Revision 1.35 1995/06/12 15:17:31 adam
259 # Text widget used in main window (instead of listbox) to support
260 # better presentation formats.
262 # Revision 1.34 1995/06/12 07:59:07 adam
263 # More work on geometry handling.
265 # Revision 1.33 1995/06/09 11:17:35 adam
266 # Start work on geometry management.
268 # Revision 1.32 1995/06/07 09:16:37 adam
269 # New presentation format.
271 # Revision 1.31 1995/06/06 16:31:09 adam
272 # Bug fix: target names couldn't contain blanks.
275 # Revision 1.30 1995/06/06 11:35:41 adam
276 # Work on scan. Display of old sets.
278 # Revision 1.29 1995/06/05 14:11:18 adam
279 # Bug fix in present-more.
281 # Revision 1.28 1995/06/02 14:52:13 adam
282 # Minor changes really.
284 # Revision 1.27 1995/06/02 14:29:42 adam
285 # Work on scan interface - up/down buttons.
287 # Revision 1.26 1995/06/01 16:36:46 adam
288 # About buttons. Minor bug fixes.
290 # Revision 1.25 1995/05/31 13:09:57 adam
291 # Client searches/presents may be interrupted.
292 # New moving book-logo.
294 # Revision 1.24 1995/05/31 08:36:24 adam
295 # Bug fix in client.tcl: didn't save options on clientrc.tcl.
296 # New method: referenceId. More work on scan.
298 # Revision 1.23 1995/05/29 10:33:41 adam
299 # README and rename of startup script.
301 # Revision 1.22 1995/05/26 11:44:09 adam
302 # Bugs fixed. More work on MARC utilities and queries. Test
303 # client is up-to-date again.
305 # Revision 1.21 1995/05/11 15:34:46 adam
306 # Scan request changed a bit. This version works with RLG.
308 # Revision 1.20 1995/04/21 16:31:57 adam
309 # New radiobutton: protocol (z39v2/SR).
311 # Revision 1.19 1995/04/18 16:11:50 adam
312 # First version of graphical Scan. Some work on query-by-form.
314 # Revision 1.18 1995/04/10 10:50:22 adam
315 # Result-set name defaults to suffix of ir-set name.
316 # Started working on scan. Not finished at this point.
318 # Revision 1.17 1995/03/31 09:34:57 adam
319 # Search-button disabled when there is no connection.
321 # Revision 1.16 1995/03/31 08:56:36 adam
322 # New button "Search".
324 # Revision 1.15 1995/03/28 12:45:22 adam
325 # New ir method failback: called on disconnect/protocol error.
326 # New ir set/get method: protocol: SR / Z3950.
327 # Simple popup and disconnect when failback is invoked.
329 # Revision 1.14 1995/03/22 16:07:55 adam
332 # Revision 1.13 1995/03/21 17:27:26 adam
333 # Short-hand keys in setup.
335 # Revision 1.12 1995/03/21 13:41:03 adam
336 # Comstack cs_create not used too often. Non-blocking connect.
338 # Revision 1.11 1995/03/21 10:39:06 adam
339 # Diagnostic error message displayed with tkerror.
341 # Revision 1.10 1995/03/20 15:24:06 adam
342 # Diagnostic records saved on searchResponse.
344 # Revision 1.9 1995/03/17 18:26:16 adam
345 # Non-blocking i/o used now. Database names popup as cascade items.
347 # Revision 1.8 1995/03/17 15:45:00 adam
348 # Improved target/database setup.
350 # Revision 1.7 1995/03/16 17:54:03 adam
351 # Minor changes really.
353 # Revision 1.6 1995/03/15 19:10:20 adam
354 # Database setup in protocol-setup (rather target setup).
356 # Revision 1.5 1995/03/15 13:59:23 adam
359 # Revision 1.4 1995/03/14 17:32:29 adam
360 # Presentation of full Marc record in popup window.
362 # Revision 1.3 1995/03/12 19:31:52 adam
363 # Pattern matching implemented when retrieving MARC records. More
364 # diagnostic functions.
366 # Revision 1.2 1995/03/10 18:00:15 adam
367 # Actual presentation in line-by-line format. RPN query support.
369 # Revision 1.1 1995/03/09 16:15:07 adam
370 # First presentRequest attempts. Hot-target list.
375 # Procedure tk4 is defined - returns 0 if tk 3.6 - returns 1 otherwise
376 if {$tk_version == "3.6"} {
386 # The following procedures deals with menu entries. The interface
387 # changed from Tk 3.6 to 4.X
400 # Procedure configure-enable-e {w n}
402 # n menu entry number (0 is first entry)
405 # Procedure configure-disable-e {w n}
407 # n menu entry number (0 is first entry)
408 # Disables menu entry
411 proc configure-enable-e {w n} {
413 $w entryconfigure $n -state normal
415 proc configure-disable-e {w n} {
417 $w entryconfigure $n -state disabled
419 set noFocus [list -takefocus 0]
421 proc configure-enable-e {w n} {
424 proc configure-disable-e {w n} {
430 # Define dummy clock function if it is not there.
431 if {[catch {clock seconds}]} {
436 # Set monoFlag to 1 if screen is known not to support colors; otherwise
439 if {[tk colormodel .] == "color"} {
448 # Define libdir to the IrTcl configuration directory.
449 # In the line below LIBDIR will be modified during 'make install'.
452 # If the bitmaps sub directory is present with a bitmap we assume
453 # the client is run from the source directory in which case we
454 # set libdir the current directory.
455 if {[file readable bitmaps/book2]} {
459 # Make a final check to see if libdir was set ok.
460 if {! [file readable ${libdir}/bitmaps/book2]} {
461 puts "Cannot locate system files in ${libdir}. You must either run this"
462 puts "program from the source directory root of ir-tcl or you must assure"
463 puts "that it is installed - normally in /usr/local/lib/irtcl"
467 # Initialize a lot of globals.
472 set profile(Default,description) {}
473 set profile(Default,host) {}
474 set profile(Default,port) 210
475 set profile(Default,authentication) {}
476 set profile(Default,maximumRecordSize) 50000
477 set profile(Default,preferredMessageSize) 30000
478 set profile(Default,comstack) tcpip
479 set profile(Default,namedResultSets) 1
480 set profile(Default,queryRPN) 1
481 set profile(Default,queryCCL) 0
482 set profile(Default,protocol) Z39
483 set profile(Default,windowNumber) 1
484 set profile(Default,largeSetLowerBound) 2
485 set profile(Default,smallSetUpperBound) 0
486 set profile(Default,mediumSetPresentNumber) 0
487 set profile(Default,presentChunk) 4
488 set profile(Default,timeDefine) {}
489 set profile(Default,timeLastInit) {}
490 set profile(Default,timeLastExplain) {}
491 set profile(Default,targetInfoName) {}
492 set profile(Default,recentNews) {}
493 set profile(Default,maxResultSets) {}
494 set profile(Default,maxResultSize) {}
495 set profile(Default,maxTerms) {}
496 set profile(Default,multipleDatabases) 0
497 set profile(Default,welcomeMessage) {}
500 set settingsChanged 0
508 set recordSyntax None
509 set elementSetNames None
513 set queryTypes {Simple}
514 set queryButtons { { {I 0} {I 1} {I 2} } }
515 set queryInfo {{{Title {1=4}} {Author {1=1003}} \
516 {Subject {1=21}} {Any {1=1016}} {Abstract {1=62}}}}
522 if {[lindex [split $tk_version .] 0] < 5} {
523 set font(bb,normal) -Adobe-Helvetica-Medium-R-Normal-*-240-*
524 set font(bb,bold) -Adobe-Helvetica-Bold-R-Normal-*-240-*
525 set font(b,normal) -Adobe-Helvetica-Medium-R-Normal-*-180-*
526 set font(b,bold) -Adobe-Helvetica-Bold-R-Normal-*-180-*
527 set font(n,normal) -Adobe-Helvetica-Medium-R-Normal-*-120-*
528 set font(n,bold) -Adobe-Helvetica-Bold-R-Normal-*-120-*
529 set font(s,bold) -Adobe-Helvetica-Bold-R-Normal-*-100-*
530 set font(ss,bold) -Adobe-Helvetica-Bold-R-Normal-*-80-*
532 set font(bb,normal) {Helvetica 24}
533 set font(bb,bold) {Helvetica 24 bold}
534 set font(b,normal) {Helvetica 24}
535 set font(b,bold) {Helvetica 18 bold}
536 set font(n,normal) {Helvetica 12}
537 set font(n,bold) {Helvetica 12 bold}
538 set font(s,bold) {Helvetica 10 bold}
539 set font(ss,bold) {Helvetica 8 bold}
542 # Procedure tkerror {err}
544 # Override the Tk error handler function.
550 if {[winfo exists $w]} {
559 label $w.top.b -bitmap error
560 message $w.top.t -aspect 300 -text "Error: $err" \
562 pack $w.top.b $w.top.t -side left -padx 10 -pady 10
564 bottom-buttons $w [list {Close} [list destroy $w]] 1
567 # Read tag set file (if present)
568 if {[file readable "${libdir}/tagsets.tcl"]} {
569 source "${libdir}/tagsets.tcl"
572 # Read the global target configuration file.
573 if {[file readable "${libdir}/irtdb.tcl"]} {
574 source "${libdir}/irtdb.tcl"
576 # Read the local target configuration file.
577 if {[file readable "irtdb.tcl"]} {
581 # Read the user configuration file.
582 if {[file readable "~/.clientrc.tcl"]} {
583 source "~/.clientrc.tcl"
586 # Convert old format to new format...
587 foreach target [array names profile] {
588 set timedef [clock seconds]
589 if {[string first , $target] == -1} {
590 if {![info exists profile($target,port)]} {
591 foreach n [array names profile Default,*] {
592 set profile($target,[string range $n 8 end]) $profile($n)
594 set profile($target,description) [lindex $profile($target) 0]
595 set profile($target,host) [lindex $profile($target) 1]
596 set profile($target,port) [lindex $profile($target) 2]
597 set profile($target,authentication) [lindex $profile($target) 3]
598 set profile($target,maximumRecordSize) \
599 [lindex $profile($target) 4]
600 set profile($target,preferredMessageSize) \
601 [lindex $profile($target) 5]
602 set profile($target,comstack) [lindex $profile($target) 6]
603 set profile($target,databases) [lindex $profile($target) 7]
604 set profile($target,timeDefine) $timedef
605 set profile($target,windowNumber) 1
607 unset profile($target)
611 # Assign unique ID's to each target's window number
613 foreach n [array names profile *,windowNumber] {
617 set profile(Default,windowNumber) $wno
619 # These globals describe the current query type. They are set to the
621 set queryButtonsFind [lindex $queryButtons 0]
622 set queryInfoFind [lindex $queryInfo 0]
624 # Procedure read-formats
625 # Read all Tcl source files in the subdirectory 'formats'.
626 # The name of each source will correspond to a display format.
627 proc read-formats {} {
628 global displayFormats
633 set formats [glob {*.[tT][cC][lL]}]
635 if {[file readable $f]} {
637 set l [string length $f]
638 set f [string tolower [string range $f 0 [expr $l - 5]]]
639 lappend displayFormats $f
645 # Procedure set-wrap {m}
646 # m boolean wrap mode
647 # Handler to enable/disable text wrap in the main record window
652 .data.record configure -wrap $m
655 # Procedure dputs {m}
656 # m string to be printed
657 # puts utility for debugging.
665 # Procedure apduDump {}
666 # Logs BER dump of last APDU in window if debugMode is true.
672 if {$debugMode == 0} return
675 set offset [lindex $x 1]
676 set length [lindex $x 0]
678 if {![winfo exists $w]} {
682 wm title $w "APDU information"
688 text $w.top.t -font fixed -width 60 -height 12 -wrap word \
689 -relief flat -borderwidth 0 \
690 -yscrollcommand [list $w.top.s set] -background grey85
691 scrollbar $w.top.s -command [list $w.top.t yview]
693 pack $w.top.s -side right -fill y
694 pack $w.top.t -expand yes -fill both
696 bottom-buttons $w [list {Close} [list destroy $w]] 0
698 $w.top.t insert end "Length: ${length}\n"
700 $w.top.t insert end "Offset: ${offset}\n"
702 $w.top.t insert end [lindex $x 2]
703 $w.top.t insert end "---------------------------------\n"
707 # Procedure set-display-format {f}
709 # Reformats main record window to use display format given by f
710 proc set-display-format {f} {
711 global displayFormat setNo busy
718 .bot.a.status configure -text "Reformatting"
721 add-title-lines -1 10000 1
724 # Procedure initBindings
725 # Disables various default bindings for Text and Listbox widgets.
726 proc initBindings {} {
729 foreach e [bind Text] {
730 set TextBinding($e) [bind Text $e]
734 bind $w <B1-Motion> {}
735 bind $w <Shift-B1-Motion> {}
740 # Procedure TextEditable
741 # Apply "standard" events to a text widget. It should be editable now.
742 proc TextEditable {w} {
745 foreach e [array names TextBinding] {
746 bind $w $e $TextBinding($e)
750 # Procedure post-menu {wbutton wmenu}
751 # wbutton button widget
753 # Post menu near button. Note: not used.
754 proc post-menu {wbutton wmenu} {
757 $wmenu post [winfo rootx $wbutton] \
758 [expr [winfo rooty $wbutton]+[winfo height $wbutton]]
762 # Procedure place-force {window parent}
763 # window new top level widget
764 # parent parent widget used as base
765 # Sets geometry of $window relative to $parent window.
766 proc place-force {window parent} {
767 set g [wm geometry $parent]
769 set p1 [string first + $g]
770 set p2 [string last + $g]
772 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
773 set y [expr 60+[string range $g [expr $p2 +1] end]]
774 wm geometry $window +${x}+${y}
777 # Procedure destroyGW {w}
779 # Saves geometry of widget w in windowGeometry array. This
780 # Procedure is used to save current geometry of a window before
782 # See also topLevelG.
784 global windowGeometry
785 catch {set windowGeometry($w) [wm geometry $w]}
788 # Procedure topLevelG
790 # Makes a new top level widget named w; sets geometry of window if it
791 # exists in windowGeometry array. The destroyGW procedure is set
792 # to be called when the Destroy event occurs.
794 global windowGeometry
797 if {[info exists windowGeometry($w)]} {
798 set g $windowGeometry($w)
799 if {[string length $g]} {
803 bind $w <Destroy> [list destroyGW $w]
806 # Procedure top-down-window {w}
807 # w window (possibly top level)
808 # Makes two frames inside w called top and bot.
809 proc top-down-window {w} {
810 frame $w.top -relief raised -border 1
811 frame $w.bot -relief raised -border 1
813 pack $w.top -side top -fill both -expand yes
814 pack $w.bot -fill both
817 # Init: The geometry information for the main window is set - either
818 # to a default value or to the value in windowGeometry(.)
819 if {[catch {set g $windowGeometry(.)}]} {
820 wm geometry . 420x340+20+20
825 # Procedure top-down-ok-cancel {w ok-action g}
826 # w top level widget with $w.bot-frame
827 # ok-action ok script
829 # Makes two buttons in the bot frame called Ok and Cancel. The
830 # ok-action is executed if Ok is pressed. If Cancel is activated
831 # The window is destroyed. If g is true a grab is performed on the
832 # window and the procedure waits until the window is destroyed.
833 proc top-down-ok-cancel {w ok-action g} {
834 frame $w.bot.left -relief sunken -border 1
835 pack $w.bot.left -side left -expand yes -ipadx 2 -ipady 2 -padx 1 -pady 1
836 button $w.bot.left.ok -width 4 -text {Ok} \
837 -command ${ok-action}
838 pack $w.bot.left.ok -expand yes -ipadx 1 -ipady 1 -padx 2 -pady 2
839 button $w.bot.cancel -width 5 -text {Cancel} \
840 -command [list destroy $w]
841 pack $w.bot.cancel -side left -expand yes
849 # Procedure bottom-buttons {w buttonList g}
850 # w top level widget with $w.bot-frame
851 # buttonList button specifications
853 # Makes a list of buttons in the $w.bot frame. The buttonList is a list
854 # of button specifications. Each button specification consists of two
855 # items; the first item is button label name; the second item is a script
856 # of be executed when that button is executed. A grab is performed if g
857 # is true and it waits for the window to be destroyed.
858 proc bottom-buttons {w buttonList g} {
860 set l [llength $buttonList]
862 frame $w.bot.$i -relief sunken -border 1
863 pack $w.bot.$i -side left -expand yes -padx 2 -pady 2
864 button $w.bot.$i.ok -text [lindex $buttonList $i] \
865 -command [lindex $buttonList [expr $i+1]]
866 pack $w.bot.$i.ok -expand yes -padx 2 -pady 2 -side left
870 button $w.bot.$i -text [lindex $buttonList $i] \
871 -command [lindex $buttonList [expr $i+1]]
872 pack $w.bot.$i -expand yes -padx 2 -pady 2 -side left
882 # Procedure cancel-operation
883 # This handler is invoked when the user wishes to cancel an operation.
884 # If the system is currently busy a "Cancel" will be displayed in the
885 # status area and the cancelFlag is set to true indicating that future
886 # responses from the target should be ignored. The system is no longer
887 # busy when this procedure exists.
888 proc cancel-operation {} {
889 global cancelFlag busy delayRequest
894 show-status Cancel 0 1
898 # Procedure show-target {target base}
899 # target name of target
900 # base name of database
901 # Displays target name and database name in the target status area.
902 proc show-target {target base} {
903 if {![string length $target]} {
904 .bot.a.target configure -text {}
907 if {![string length $base]} {
908 .bot.a.target configure -text "$target"
910 .bot.a.target configure -text "$target - $base"
914 # Procedure show-logo {v1}
916 # This procedure maintains the book logo in the bottom of the screen.
917 # It is invoked only once during initialization of windows, etc., and
918 # by itself. The global 'busy' variable determines whether the logo is
920 proc show-logo {v1} {
928 .bot.logo configure -bitmap @${libdir}/bitmaps/book${v1}
929 after 140 [list show-logo $v1]
933 .bot.logo configure -bitmap @${libdir}/bitmaps/book1
942 # Procedure show-status {status b sb}
943 # status status message string
945 # sb search busy indicator
946 # Display status information according to 'status' and sets the global
947 # busy flag 'busy' to b if b is non-empty. If sb is non-empty it indicates
948 # whether service buttons should be enabled or disabled.
949 proc show-status {status b sb} {
950 global busy scanEnable
951 global setOffset setMax setNo
953 .bot.a.status configure -text "$status"
955 if {$busy == 0} {set busy 1}
963 .top.service configure -state normal
964 .mid.search configure -state normal
966 .mid.scan configure -state normal
968 configure-disable-e .top.service.m 3
971 configure-disable-e .top.service.m 1
972 } elseif {[z39.$setNo nextResultSetPosition] > 0 &&
973 [z39.$setNo nextResultSetPosition] <= [z39.$setNo resultCount]} {
974 configure-enable-e .top.service.m 1
975 .mid.present configure -state normal
977 configure-disable-e .top.service.m 1
978 .mid.present configure -state disabled
980 if {[winfo exists .scan-window]} {
981 .scan-window.bot.2 configure -state normal
982 .scan-window.bot.4 configure -state normal
985 .top.service configure -state disabled
986 .mid.search configure -state disabled
987 .mid.scan configure -state disabled
988 .mid.present configure -state disabled
990 if {[winfo exists .scan-window]} {
991 .scan-window.bot.2 configure -state disabled
992 .scan-window.bot.4 configure -state disabled
997 # Procedure show-message {msg}
999 # Sets message the bottom of the screen to msg.
1000 proc show-message {msg} {
1001 .bot.a.message configure -text "$msg"
1004 # Procedure insertWithTags {w text args}
1006 # text string to be inserted
1008 # Inserts text at the insertion point in widget w. The text is tagged
1009 # with the tags in args.
1010 proc insertWithTags {w text args} {
1011 set start [$w index insert]
1012 $w insert insert $text
1013 foreach tag [$w tag names $start] {
1014 $w tag remove $tag $start insert
1017 $w tag add $i $start insert
1021 # Procedure popup-license
1022 # Displays LICENSE information.
1023 proc popup-license {} {
1025 set w .popup-licence
1028 wm title $w "License"
1034 text $w.top.t -width 80 -height 10 -wrap word -relief flat -borderwidth 0 \
1035 -font fixed -yscrollcommand [list $w.top.s set]
1036 scrollbar $w.top.s -command [list $w.top.t yview]
1038 pack $w.top.s -side right -fill y
1039 pack $w.top.t -expand yes -fill both
1041 if {[file readable "${libdir}/LICENSE"]} {
1042 set f [open "${libdir}/LICENSE" r]
1043 while {[gets $f buf] != -1} {
1044 $w.top.t insert end $buf
1045 $w.top.t insert end "\n"
1049 bottom-buttons $w [list {Close} [list destroy $w]] 1
1052 # Procedure about-target
1053 # Displays various information about the current target, such
1054 # as implementation-name, implementation-id, etc.
1055 proc about-target {} {
1056 set w .about-target-w
1061 wm title $w "About target"
1065 frame $w.top.a -relief ridge -border 2
1066 frame $w.top.p -relief ridge -border 2
1068 pack $w.top.a $w.top.p -side top -fill x
1070 label $w.top.a.about -text "About"
1071 label $w.top.a.irtcl -text $hostid -font $font(bb,bold)
1072 pack $w.top.a.about $w.top.a.irtcl -side top
1074 set i [z39 targetImplementationName]
1075 label $w.top.p.in -text "Implementation name: $i"
1076 set i [z39 targetImplementationId]
1077 label $w.top.p.ii -text "Implementation id: $i"
1078 set i [z39 targetImplementationVersion]
1079 label $w.top.p.iv -text "Implementation version: $i"
1081 label $w.top.p.op -text "Protocol options: $i"
1083 pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.op -side top -anchor nw
1085 bottom-buttons $w [list {Close} [list destroy $w]] 1
1088 # Procedure about-origin-logo {n}
1090 # Displays book logo in the .about-origin-w widget
1091 proc about-origin-logo {n} {
1093 set w .about-origin-w
1094 if {![winfo exists $w]} {
1101 $w.top.a.logo configure -bitmap @${libdir}/bitmaps/book$n
1102 after 140 [list about-origin-logo $n]
1105 # Procedure about-origin
1106 # Display various information about origin (this client).
1107 proc about-origin {} {
1108 set w .about-origin-w
1109 global libdir font tk_version
1111 if {[winfo exists $w]} {
1116 wm title $w "About IrTcl"
1120 frame $w.top.a -relief ridge -border 2
1121 frame $w.top.p -relief ridge -border 2
1123 pack $w.top.a $w.top.p -side top -fill x
1125 label $w.top.a.irtcl -text "IrTcl" -font $font(bb,bold)
1126 label $w.top.a.logo -bitmap @${libdir}/bitmaps/book1
1127 pack $w.top.a.irtcl $w.top.a.logo -side left -expand yes
1129 label $w.top.p.irtcl -text "IrTcl version: [lindex [ir-version] 0]"
1130 label $w.top.p.yaz -text "Yaz version: [lindex [ir-version] 1]"
1132 label $w.top.p.tk -text "Tk version: $tk_version"
1134 pack $w.top.p.irtcl $w.top.p.yaz $w.top.p.tk -side top -anchor nw
1137 bottom-buttons $w [list {Close} [list destroy $w] \
1138 {License} [list popup-license]] 0
1141 # Procedure popup-marc {sno no b df}
1142 # sno result set number
1143 # no record position number
1144 # b popup window number
1146 # Displays record in set $sno at position $no in window .full-marc$b.
1147 # The global variable $popupMarcdf holds the current format method.
1148 proc popup-marc {sno no b df} {
1149 global font displayFormats popupMarcdf
1151 if {[z39.$sno type $no] != "DB"} {
1156 while {[winfo exists .full-marc$b]} {
1162 if {![winfo exists $w]} {
1167 frame $w.top -relief raised -border 1
1168 frame $w.bot -relief raised -border 1
1170 pack $w.top -side top -fill both -expand yes
1171 pack $w.bot -fill both
1173 text $w.top.record -width 60 -height 5 -wrap word -relief flat \
1174 -borderwidth 0 -font fixed \
1175 -yscrollcommand [list $w.top.s set] -background grey85
1176 scrollbar $w.top.s -command [list $w.top.record yview]
1180 $w.top.record tag configure marc-tag -foreground blue
1181 $w.top.record tag configure marc-id -foreground red
1183 $w.top.record tag configure marc-tag -foreground black
1184 $w.top.record tag configure marc-id -foreground black
1186 $w.top.record tag configure marc-data -foreground black
1187 $w.top.record tag configure marc-head -font $font(n,bold) \
1188 -background black -foreground white
1190 $w.top.record tag configure marc-pref -font $font(n,normal) \
1192 $w.top.record tag configure marc-text -font $font(n,normal) \
1194 $w.top.record tag configure marc-it -font $font(n,normal) \
1197 pack $w.top.s -side right -fill y
1198 pack $w.top.record -expand yes -fill both
1200 bottom-buttons $w [list \
1201 {Close} [list destroy $w] \
1205 menubutton $w.bot.formats -text "Format" -menu $w.bot.formats.m \
1207 irmenu $w.bot.formats.m
1208 pack $w.bot.formats -expand yes -ipadx 2 -ipady 2 \
1209 -padx 3 -pady 3 -side left
1211 $w.bot.formats.m delete 0 last
1214 foreach f $displayFormats {
1215 $w.bot.formats.m add radiobutton -label $f \
1216 -variable popupMarcdf -value $i \
1217 -command [list popup-marc $sno $no $b 0]
1220 $w.top.record delete 0.0 end
1221 set recordType [z39.$sno recordType $no]
1222 wm title $w "$recordType record #$no"
1224 $w.bot.2 configure -command \
1225 [list popup-marc $sno [expr $no-1] $b $df]
1226 $w.bot.4 configure -command \
1227 [list popup-marc $sno [expr $no+1] $b $df]
1229 $w.bot.2 configure -state disabled
1231 $w.bot.2 configure -state normal
1233 if {[z39.$sno type [expr $no+1]] != "DB"} {
1234 $w.bot.4 configure -state disabled
1236 $w.bot.4 configure -state normal
1238 $w.bot.6 configure -command [list popup-marc $sno $no -1 0]
1239 set ffunc [lindex $displayFormats $df]
1240 set ffunc "display-$ffunc"
1242 $ffunc $sno $no $w.top.record 0
1245 # Procedure update-target-hotlist {target base}
1246 # target current target name
1247 # base current database name
1248 # Updates the global $hotTargets so that $target and $base are
1249 # moved to the front, i.e. they become the number 1 target/base.
1250 # The target menu is updated by a call to set-target-hotlist.
1251 proc update-target-hotlist {target base} {
1254 set olen [llength $hotTargets]
1256 foreach e $hotTargets {
1257 if {$target == [lindex $e 0] && $base == [lindex $e 1]} {
1258 set hotTargets [lreplace $hotTargets $i $i]
1263 set hotTargets [linsert $hotTargets 0 [list $target $base]]
1264 set-target-hotlist $olen
1267 # Procedure delete-target-hotlist {target}
1268 # target target to be deleted
1269 # Updates the global $hotTargets so that $target is removed.
1270 # The target menu is updated by a call to set-target-hotlist.
1271 proc delete-target-hotlist {target} {
1274 set olen [llength $hotTargets]
1276 foreach e $hotTargets {
1277 if {$target == [lindex $e 0]} {
1278 set hotTargets [lreplace $hotTargets $i $i]
1282 set-target-hotlist $olen
1285 # Procedure set-target-hotlist {olen}
1286 # olen number of hot target entries to be deleted from menu
1287 # Updates the target menu with the targets with the first 8 entries
1288 # in the $hotTargets global.
1289 proc set-target-hotlist {olen} {
1294 .top.target.m delete 6 [expr 6+$olen]
1296 .top.target.m delete 6 [expr 6+$olen]
1300 foreach e $hotTargets {
1301 set target [lindex $e 0]
1302 set base [lindex $e 1]
1303 if {![string length $base]} {
1304 .top.target.m add command -label "$i $target" -command \
1305 [list reopen-target $target {}]
1307 .top.target.m add command -label "$i $target - $base" -command \
1308 [list reopen-target $target $base]
1317 # Procedure reopen-target {target base}
1318 # target target to be opened
1319 # base base to be used
1320 # Closes connection with current target and opens a new connection
1321 # with $target and database $base.
1322 proc reopen-target {target base} {
1324 open-target $target $base
1325 update-target-hotlist $target $base
1328 # Procedure define-target-action
1329 # Prepares the setup of a new target. The name of the target
1330 # is read from the dialog .target-define dialog (procedure
1331 # define-target-dialog) and the target definition window is displayed by
1332 # a call to protocol-setup.
1333 proc define-target-action {} {
1336 set target [.target-define.top.target.entry get]
1337 if {![string length $target]} {
1340 foreach n [array names profile *,host] {
1341 if {![string compare $n ${target},host]} {
1342 destroy .target-define
1347 foreach n [array names profile Default,*] {
1348 set profile($target,[string range $n 8 end]) $profile($n)
1351 incr profile(Default,windowNumber)
1353 protocol-setup $target
1354 destroy .target-define
1357 # Procedure fail-response {target}
1358 # target current target
1359 # Error handler (IrTcl failback) that takes care of serious protocol
1360 # errors, connection lost, etc.
1361 proc fail-response {target} {
1364 set c [lindex [z39 failInfo] 0]
1365 set m [lindex [z39 failInfo] 1]
1366 if {$c == 4 || $c == 5} {
1374 # Procedure connect-response {target base}
1375 # target current target
1376 # base current database
1377 # IrTcl connect response handler.
1378 proc connect-response {target base} {
1379 dputs "connect-response"
1380 init-request $target $base
1383 # Procedure open-target {target base}
1384 # target target to be opened
1385 # base database to be used
1386 # Opens a new connection with $target/$base.
1387 proc open-target {target base} {
1393 z39 comstack $profile($target,comstack)
1394 z39 protocol $profile($target,protocol)
1395 eval z39 idAuthentication $profile($target,authentication)
1396 z39 maximumRecordSize $profile($target,maximumRecordSize)
1397 z39 preferredMessageSize $profile($target,preferredMessageSize)
1398 dputs "maximumRecordSize=[z39 maximumRecordSize]"
1399 dputs "preferredMessageSize=[z39 preferredMessageSize]"
1400 show-status Connecting 1 0
1401 set x $profile($target,largeSetLowerBound)
1402 if {![string length $x]} {
1405 z39 largeSetLowerBound $x
1407 set x $profile($target,smallSetUpperBound)
1408 if {![string length $x]} {
1411 z39 smallSetUpperBound $x
1413 set x $profile($target,mediumSetPresentNumber)
1414 if {![string length $x]} {
1417 z39 mediumSetPresentNumber $x
1419 set presentChunk $profile($target,presentChunk)
1420 if {![string length $presentChunk]} {
1424 z39 failback [list fail-response $target]
1425 z39 callback [list connect-response $target $base]
1426 show-target $target $base
1429 z39 connect $profile($target,host):$profile($target,port)
1433 tkerror $errorMessage
1434 show-status "Not connected" 0 {}
1439 configure-disable-e .top.target.m 0
1440 configure-enable-e .top.target.m 1
1441 configure-enable-e .top.target.m 2
1444 # Procedure close-target
1445 # Shuts down the connection with current target.
1446 proc close-target {} {
1455 .bot.a.set configure -text ""
1459 show-status {Not connected} 0 0
1462 configure-disable-e .top.target.m 1
1463 configure-disable-e .top.target.m 2
1465 .top.rset.m delete 1 last
1467 .top.rset.m delete 1 last
1469 .top.rset.m add separator
1470 configure-enable-e .top.target.m 0
1473 # Procedure load-set-action
1474 # Loads records from a file. The filename is read from the entry
1475 # .load-set.filename.entry (see function load-set)
1476 proc load-set-action {} {
1480 ir-set z39.$setNoLast z39
1482 set fname [.load-set.top.filename.entry get]
1485 show-status Loading 1 {}
1487 z39.$setNoLast loadFile $fname
1489 set no [z39.$setNoLast numberOfRecordsReturned]
1490 add-title-lines $setNoLast $no 1
1492 set l [format "%-4d %7d" $setNoLast $no]
1493 .top.rset.m add command -label $l \
1494 -command [list add-title-lines $setNoLast 10000 1]
1495 show-status Ready 0 {}
1498 # Procedure load-set
1499 # Dialog that asks for a filename with records to be loaded
1500 # into a result set.
1504 set oldFocus [focus]
1508 frame $w.top.filename
1509 pack $w.top.filename -side top -anchor e -pady 2
1511 entry-fields $w.top {filename} \
1513 {load-set-action} {destroy .load-set}
1515 top-down-ok-cancel $w {load-set-action} 1
1519 # Procedure init-request
1520 # Sends an initialize request to the target. This procedure is called
1521 # when a connect has been established.
1522 proc init-request {target base} {
1529 z39 callback [list init-response $target $base]
1530 show-status Initializing 1 {}
1531 set err [catch {z39 init} errorMessage]
1533 tkerror $errorMessage
1534 show-status Ready 0 {}
1538 # Procedure init-response
1539 # Handles and incoming init-response. The service buttons
1540 # are enabled. The global $scanEnable indicates whether the target
1542 proc init-response {target base} {
1543 global cancelFlag profile scanEnable settingsChanged
1545 dputs {init-response}
1551 if {![z39 initResult]} {
1552 set u [z39 userInformationField]
1554 tkerror "Connection rejected by target: $u"
1556 z39 failback [list explain-crash $target $base]
1557 explain-check $target [list ready-response $base]
1561 # Procedure explain-crash
1562 # Handles target that dies during explain.
1563 proc explain-crash {target base} {
1564 global profile settingsChanged
1566 set profile($target,timeLastInit) [clock seconds]
1567 set profile($target,timeLastExplain) {}
1568 set settingsChanged 1
1571 open-target $target $base
1574 # Procedure explain-check
1575 # Stub function to check explain. May be overwritten later.
1576 proc explain-check {target response} {
1577 eval $response [list $target]
1580 # Procedure ready-response
1581 # Called after a target has been initialized and, possibly, explained
1582 proc ready-response {base target} {
1583 global profile settingsChanged scanEnable
1585 z39 failback [list fail-response $target]
1586 if {[string length $base]} {
1587 set profile($target,timeLastInit) [clock seconds]
1588 set settingsChanged 1
1590 z39 databaseNames $base
1591 cascade-dblist $target $base
1592 show-target $target $base
1594 if {[lsearch [z39 options] scan] >= 0} {
1599 .data.record delete 1.0 end
1600 set desc [string trim $profile($target,description)]
1601 if {[string length $desc]} {
1602 .data.record insert end "$desc\n\n"
1604 .data.record insert end "$target\n\n"
1606 set data [string trim $profile($target,welcomeMessage)]
1607 if {[string length $data]} {
1608 .data.record insert end "Welcome Message:\n$data\n\n"
1610 set data [string trim $profile($target,recentNews)]
1611 if {[string length $data]} {
1612 .data.record insert end "News:\n$data\n"
1615 show-status Ready 0 1
1618 # Procedure search-request
1619 # bflag flag to indicate if this procedure calls itself
1620 # Performs a search. If $busy is 1, the search-request is performed
1621 # at a later time (when another response arrives). This procedure
1622 # sets many search-related Z39-settings. The global $setNo is set
1623 # to the result set number (z39.$setNo).
1624 proc search-request {bflag} {
1633 global elementSetNames
1637 if {![string length [z39 connect]]} {
1640 dputs "search-request"
1642 if {!$bflag && $busy} {
1643 dputs "busy: search-request ignored"
1648 show-status Searching 1 0
1649 set delayRequest {search-request 1}
1654 set query [index-query]
1655 if {![string length $query]} {
1659 set setNo $setNoLast
1660 ir-set z39.$setNo z39
1662 if {$profile($target,namedResultSets)} {
1663 z39.$setNo setName $setNo
1664 dputs "setName=${setNo}"
1666 z39.$setNo setName default
1667 dputs "setName=default"
1669 if {$profile($target,queryRPN)} {
1670 z39.$setNo queryType rpn
1671 } elseif {$profile($target,queryCCL)} {
1672 z39.$setNo queryType ccl
1676 if {![string compare $recordSyntax None]} {
1677 z39.$setNo preferredRecordSyntax {}
1679 z39.$setNo preferredRecordSyntax $recordSyntax
1681 if {![string compare $elementSetNames None]} {
1682 z39.$setNo elementSetNames {}
1683 z39.$setNo smallSetElementSetNames {}
1684 z39.$setNo mediumSetElementSetNames {}
1686 z39.$setNo elementSetNames $elementSetNames
1687 z39.$setNo smallSetElementSetNames $elementSetNames
1688 z39.$setNo mediumSetElementSetNames $elementSetNames
1690 z39 callback {search-response}
1691 z39.$setNo search $query
1692 show-status Searching 1 0
1695 # Procedure scan-copy {y entry}
1696 # y y-position of mouse pointer
1697 # entry a search entry in the top
1698 # Copies the term in the list nearest $y to the query entry specified
1700 proc scan-copy {y entry} {
1702 set no [$w.top.list nearest $y]
1704 .lines.$entry.e delete 0 end
1705 .lines.$entry.e insert 0 [string range [$w.top.list get $no] 8 end]
1708 # Procedure scan-request
1709 # Performs a scan on term "0" with the current attributes in entry
1710 # specified by the global $curIndexEntry.
1711 proc scan-request {} {
1718 global curIndexEntry
1719 global queryButtonsFind
1720 global queryInfoFind
1724 dputs "scan-request"
1727 show-status Scanning 1 0
1728 set delayRequest scan-request
1737 set b [lindex $queryButtonsFind $curIndexEntry]
1739 foreach a [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end] {
1740 set attr "@attr $a $attr"
1742 set title [lindex [lindex $queryInfoFind [lindex $b 1]] 0]
1743 ir-scan z39.scan z39
1745 if {![winfo exists $w]} {
1752 entry $w.top.entry -relief sunken
1753 pack $w.top.entry -fill x -padx 4 -pady 2
1754 bind $w.top.entry <KeyRelease> [list scan-term-h $attr]
1755 listbox $w.top.list -yscrollcommand [list $w.top.scroll set] \
1757 scrollbar $w.top.scroll -orient vertical -border 1
1758 pack $w.top.list -side left -fill both -expand yes
1759 pack $w.top.scroll -side right -fill y
1760 $w.top.scroll config -command [list $w.top.list yview]
1762 bottom-buttons $w [list {Close} [list destroy $w] \
1763 {Up} [list scan-up $attr] \
1764 {Down} [list scan-down $attr]] 0
1765 bind $w.top.list <Up> [list scan-up $attr]
1766 bind $w.top.list <Down> [list scan-down $attr]
1769 bind $w.top.list <Double-Button-1> [list scan-copy %y $curIndexEntry]
1770 wm title $w "Scan $title"
1772 z39 callback [list scan-response $attr 0 35]
1773 z39.scan numberOfTermsRequested 5
1774 z39.scan preferredPositionInResponse 1
1775 z39.scan scan "${attr} 0"
1777 show-status Scanning 1 0
1780 # Procedure scan-term-h {attr}
1781 # attr attribute specification
1782 # This procedure is called whenever a key is released in the entry in the
1783 # scan window (.scan-window). A scan is then initiated with the new contents
1784 # of the entry as the starting term.
1785 proc scan-term-h {attr} {
1793 set nScanTerm [$w.top.entry get]
1794 if {$nScanTerm == $scanTerm} {
1797 set scanTerm $nScanTerm
1798 z39 callback [list scan-response $attr 0 35]
1799 z39.scan numberOfTermsRequested 5
1800 z39.scan preferredPositionInResponse 1
1801 dputs "${attr} \{${scanTerm}\}"
1802 if {![string length $scanTerm]} {
1803 z39.scan scan "${attr} 0"
1805 z39.scan scan "${attr} \{${scanTerm}\}"
1807 show-status Scanning 1 0
1810 # Procedure scan-response {attr start toget}
1811 # attr attribute specification
1812 # start position of first term in the response
1813 # toget number of total terms to get
1814 # This procedure handles all scan-responses. $start specifies the list
1815 # entry number of the first incoming term. The $toget indicates the total
1816 # number of terms to be retrieved from the target. The $toget may be
1817 # negative in which case, scan is performed 'backwards' (- $toget is
1818 # the total number of terms in this case). This procedure usually calls
1819 # itself several times in order to get small scan-term-list chunks.
1820 proc scan-response {attr start toget} {
1827 dputs "In scan-response"
1829 set m [z39.scan numberOfEntriesReturned]
1835 if {![winfo exists .scan-window]} {
1838 dputs "Handling cancel"
1839 if {$delayRequest != ""} {
1844 show-status Ready 0 1
1847 set nScanTerm [$w.top.entry get]
1848 if {$nScanTerm != $scanTerm} {
1849 z39 callback [list scan-response $attr 0 35]
1850 z39.scan numberOfTermsRequested 5
1851 z39.scan preferredPositionInResponse 1
1852 set scanTerm $nScanTerm
1853 dputs "${attr} \{${scanTerm}\}"
1854 if {![string length $scanTerm]} {
1855 z39.scan scan "${attr} 0"
1857 z39.scan scan "${attr} \{${scanTerm}\}"
1859 show-status Scanning 1 0
1862 set status [z39.scan scanStatus]
1865 show-status Ready 0 1
1870 for {set i 0} {$i < $m} {incr i} {
1871 set term [lindex [z39.scan scanLine $i] 1]
1872 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1873 $w.top.list insert $i "$nostr $term"
1876 $w.top.list yview $scanView
1878 $w.top.list delete $start end
1879 for {set i 0} {$i < $m} {incr i} {
1880 set term [lindex [z39.scan scanLine $i] 1]
1881 set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1882 $w.top.list insert end "$nostr $term"
1886 dputs "Handling cancel"
1888 if {$delayRequest != ""} {
1894 if {$toget > 0 && $m > 1 && $m < $toget} {
1895 set ntoget [expr $toget - $m + 1]
1896 dputs ntoget=$ntoget
1897 z39 callback [list scan-response $attr [expr $start + $m - 1] $ntoget]
1899 dputs "down continue: $q"
1901 z39.scan numberOfTermsRequested 10
1903 z39.scan numberOfTermsRequested $ntoget
1905 z39.scan preferredPositionInResponse 1
1906 dputs "${attr} \{$q\}"
1907 z39.scan scan "${attr} \{$q\}"
1910 if {$toget < 0 && $m > 1 && $m < [expr - $toget]} {
1911 set ntoget [expr - $toget - $m]
1912 dputs ntoget=$ntoget
1913 z39 callback [list scan-response $attr 0 -$ntoget]
1914 set q [string range [$w.top.list get 0] 8 end]
1915 dputs "up continue: $q"
1917 z39.scan numberOfTermsRequested 10
1918 z39.scan preferredPositionInResponse 11
1920 z39.scan numberOfTermsRequested $ntoget
1921 z39.scan preferredPositionInResponse [incr ntoget]
1923 dputs "${attr} \{$q\}"
1924 z39.scan scan "${attr} \{$q\}"
1927 show-status Ready 0 1
1930 # Procedure scan-down {attr}
1931 # attr attribute specification
1932 # This procedure is called when the user hits the Down button the scan
1933 # window. A new scan is initiated with a positive $toget passed to the
1934 # scan-response handler.
1935 proc scan-down {attr} {
1943 show-status {Scanning down} 1 0
1944 set delayRequest [list scan-down $attr]
1950 set scanView [expr $scanView + 5]
1951 set s [$w.top.list size]
1952 if {$scanView > $s} {
1953 z39 callback [list scan-response $attr [expr $s - 1] 25]
1954 set q [string range [$w.top.list get [expr $s - 1]] 8 end]
1956 z39.scan numberOfTermsRequested 10
1957 z39.scan preferredPositionInResponse 1
1958 show-status Scanning 1 0
1959 dputs "${attr} \{$q\}"
1960 z39.scan scan "${attr} \{$q\}"
1963 $w.top.list yview $scanView
1966 # Procedure scan-up {attr}
1967 # attr attribute specification
1968 # This procedure is called when the user hits the Up button the scan
1969 # window. A new scan is initiated with a negative $toget passed to the
1970 # scan-response handler.
1971 proc scan-up {attr} {
1979 show-status Scanning 1 0
1980 set delayRequest [list scan-up $attr]
1986 set scanView [expr $scanView - 5]
1987 if {$scanView < 0} {
1988 z39 callback [list scan-response $attr 0 -25]
1989 set q [string range [$w.top.list get 0] 8 end]
1991 z39.scan numberOfTermsRequested 10
1992 z39.scan preferredPositionInResponse 11
1993 show-status Scanning 1 0
1994 z39.scan scan "${attr} \{$q\}"
1997 $w.top.list yview $scanView
2000 # Procedure search-response
2001 # This procedure handles search-responses. If the search is successful
2002 # this procedure will try to retrieve a total of 50 records from the target;
2003 # however not more than $presentChunk records at a time. This procedure
2004 # affects the following globals:
2005 # $setOffset current record position offset
2006 # $setMax total number of records to be retrieved
2007 proc search-response {} {
2017 dputs "In search-response"
2019 dputs "Handling cancel"
2021 if {$delayRequest != ""} {
2029 set setMax [z39.$setNo resultCount]
2030 show-status Ready 0 1
2031 set status [z39.$setNo responseStatus]
2032 if {![string compare [lindex $status 0] NSD]} {
2033 z39.$setNo nextResultSetPosition 0
2034 set code [lindex $status 1]
2035 set msg [lindex $status 2]
2036 set addinfo [lindex $status 3]
2037 tkerror "NSD$code: $msg: $addinfo"
2040 show-message "${setMax} hits"
2045 show-status Ready 0 1
2046 set l [format "%-4d %7d" $setNo $setMax]
2047 .top.rset.m add command -label $l \
2048 -command [list recall-set $setNo]
2052 set no [z39.$setNo numberOfRecordsReturned]
2053 dputs "Returned $no records, setOffset $setOffset"
2054 add-title-lines $setNo $no $setOffset
2055 set setOffset [expr $setOffset + $no]
2057 set toGet [expr $setMax - $setOffset + 1]
2059 if {$setOffset == 1} {
2061 } elseif {$toGet > $presentChunk} {
2062 set toGet $presentChunk
2064 z39 callback {present-response}
2065 z39.$setNo present $setOffset $toGet
2066 show-status Retrieving 1 0
2070 # Procedure present-more {number}
2071 # number number of records to be retrieved
2072 # This procedure starts a present-request. The $number variable indicates
2073 # the total number of records to be retrieved. The global $presentChunk
2074 # specifies the number of records to be retrieved at a time. If $number
2075 # is the empty string all remaining records in the result set are
2077 proc present-more {number} {
2086 dputs "present-more"
2088 show-status Retrieving 1 0
2089 set delayRequest "present-more $number"
2095 dputs "setNo=$setNo"
2098 set setOffset [z39.$setNo nextResultSetPosition]
2099 dputs "setOffest=${setOffset}"
2100 dputs "setNo=${setNo}"
2101 set max [z39.$setNo resultCount]
2102 if {$max < $setOffset} {
2104 dputs "setOffset=$setOffset"
2105 show-status Ready 0 1
2108 if {![string length $number]} {
2112 if {$setMax > $max} {
2116 z39 callback {present-response}
2118 set toGet [expr $setMax - $setOffset + 1]
2122 if {$toGet > $presentChunk} {
2123 set toGet $presentChunk
2125 z39.$setNo present $setOffset $toGet
2126 show-status Retrieving 1 0
2129 # Procedure init-title-lines
2130 # Utility that cleans the main record window.
2131 proc init-title-lines {} {
2132 .data.record delete 1.0 end
2135 # Procedure recall-set {setno}
2136 # setno Set number to recall
2137 proc recall-set {setno} {
2138 add-title-lines $setno 10000 1
2141 # Procedure add-title-lines {setno no offset}
2143 # no Number of records
2144 # offset Starting offset
2145 # This procedure displays the records $offset .. $offset+$no-1 in result
2146 # set $setno in the main record window by using the display format in the
2147 # global $displayFormat
2148 proc add-title-lines {setno no offset} {
2149 global displayFormats
2150 global displayFormat
2154 dputs "add-title-lines offset=${offset} no=${no}"
2161 .bot.a.set configure -text $setno
2162 .data.record delete 1.0 end
2164 set ffunc [lindex $displayFormats $displayFormat]
2165 dputs "ffunc=$ffunc"
2166 set ffunc "display-$ffunc"
2167 for {set i 0} {$i < $no} {incr i} {
2168 set o [expr $i + $offset]
2169 set type [z39.$setno type $o]
2170 if {![string length $type]} {
2171 dputs "no more at $o"
2174 .data.record tag bind r$o <Any-Enter> {}
2175 .data.record tag bind r$o <Any-Leave> {}
2176 set insert0 [.data.record index insert]
2177 $ffunc $setno $o .data.record 1
2178 .data.record tag add r$o $insert0 insert
2179 .data.record tag bind r$o <1> \
2180 [list popup-marc $setno $o 0 0]
2184 show-status Ready 0 1
2188 # Procedure present-response
2189 # Present-response handler. The incoming records are displayed and a new
2190 # present request is performed until all records ($setMax) is returned
2192 proc present-response {} {
2200 dputs "In present-response"
2202 set no [z39.$setNo numberOfRecordsReturned]
2203 dputs "Returned $no records, setOffset $setOffset"
2204 add-title-lines $setNo $no $setOffset
2205 set setOffset [expr $setOffset + $no]
2207 dputs "Handling cancel"
2209 if {$delayRequest != ""} {
2214 set status [z39.$setNo responseStatus]
2215 if {![string compare [lindex $status 0] NSD]} {
2216 show-status Ready 0 1
2217 set code [lindex $status 1]
2218 set msg [lindex $status 2]
2219 set addinfo [lindex $status 3]
2220 tkerror "NSD$code: $msg: $addinfo"
2223 if {$no > 0 && $setOffset <= $setMax} {
2224 dputs "present-request from ${setOffset}"
2225 set toGet [expr $setMax - $setOffset + 1]
2226 if {$toGet > $presentChunk} {
2227 set toGet $presentChunk
2229 z39.$setNo present $setOffset $toGet
2231 show-status Ready 0 1
2235 # Procedure left-cursor {w}
2237 # Tries to move the cursor left in entry window $w
2238 proc left-cursor {w} {
2239 set i [$w index insert]
2247 # Procedure right-cursor {w}
2249 # Tries to move the cursor right in entry window $w
2250 proc right-cursor {w} {
2251 set i [$w index insert]
2257 # Procedure bind-fields {list returnAction escapeAction}
2258 # list list of entry widgets
2259 # returnAction return script
2260 # escapeAction escape script
2261 # Each widget in list are assigned bindings for <Tab>, <Left>, <Right>,
2262 # <Return> and <Escape>.
2263 proc bind-fields {list returnAction escapeAction} {
2264 set max [expr [llength $list]-1]
2265 for {set i 0} {$i < $max} {incr i} {
2266 bind [lindex $list $i] <Return> $returnAction
2267 bind [lindex $list $i] <Escape> $escapeAction
2269 bind [lindex $list $i] <Tab> \
2270 [list focus [lindex $list [expr $i+1]]]
2271 bind [lindex $list $i] <Left> \
2272 [list left-cursor [lindex $list $i]]
2273 bind [lindex $list $i] <Right> \
2274 [list right-cursor [lindex $list $i]]
2277 bind [lindex $list $i] <Return> $returnAction
2278 bind [lindex $list $i] <Escape> $escapeAction
2280 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
2281 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
2282 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
2284 focus [lindex $list 0]
2287 # Procedure entry-fields {parent list tlist returnAction escapeAction}
2288 # list list of frame widgets
2289 # tlist list of text to be used as lead of each entry
2290 # returnAction return script
2291 # escapeAction escape script
2292 # Makes label and entry widgets in each widget in $list.
2293 proc entry-fields {parent list tlist returnAction escapeAction} {
2296 foreach field $list {
2297 set label ${parent}.${field}.label
2298 set entry ${parent}.${field}.entry
2299 label $label -text [lindex $tlist $i] -anchor e
2300 entry $entry -width 32 -relief sunken
2301 pack $label -side left
2302 pack $entry -side right
2303 lappend alist $entry
2306 bind-fields $alist $returnAction $escapeAction
2309 # Procedure define-target-dialog
2310 # Dialog that asks for new target to be defined.
2311 proc define-target-dialog {} {
2312 set w .target-define
2318 pack $w.top.target \
2319 -side top -anchor e -pady 2
2320 entry-fields $w.top {target} \
2322 {define-target-action} {destroy .target-define}
2323 top-down-ok-cancel $w {define-target-action} 1
2326 # Procedure protocol-setup-delete
2327 # This procedure is invoked when the user tries to delete a target
2328 # definition. If user is sure, the target definition is deleted.
2329 proc protocol-setup-delete {target w} {
2330 global profile settingsChanged
2332 set a [alert "Are you sure you want to delete the target \
2333 definition $target ?"]
2336 foreach n [array names profile $target,*] {
2339 set settingsChanged 1
2341 delete-target-hotlist $target
2345 # Procedure protocol-setup-action {target w}
2346 # target target to be defined
2347 # w target definition toplevel widget
2348 # This procedure reads all appropriate globals and makes a new/modified
2349 # profile for the target. The global array $profileS contains most of the
2350 # information the user may modify.
2351 proc protocol-setup-action {target w} {
2352 global profile settingsChanged profileS
2355 set settingsChanged 1
2357 puts "protocol-setup-action"
2358 set timedef $profile($target,timeDefine)
2359 if {![string length $timedef]} {
2360 set timedef [clock seconds]
2362 set profileS($target,timeDefine) $timedef
2364 foreach n [array names profile $target,*] {
2365 set profile($n) $profileS($n)
2369 set len [$w.top.databases.list size]
2370 catch {unset profile($target,databases)}
2371 for {set i 0} {$i < $len} {incr i} {
2372 lappend profile($target,databases) [$w.top.databases.list get $i]
2376 delete-target-hotlist $target
2380 # Procedure add-database-action {target w}
2381 # target target to be defined
2382 # w top level widget for the target definition
2383 # Adds the contents of .database-select.top.database.entry to list of
2385 proc add-database-action {target w} {
2388 $w.top.databases.list insert end \
2389 [.database-select.top.database.entry get]
2390 destroy .database-select
2393 # Procedure add-database {target wp}
2394 # target target to be defined
2395 # wp top level widget for the target definition
2396 # Makes a dialog in which the user enters new database
2397 proc add-database {target wp} {
2400 set w .database-select
2402 set oldFocus [focus]
2408 frame $w.top.database
2410 pack $w.top.database -side top -anchor e -pady 2
2412 entry-fields $w.top {database} \
2413 {{Database to add:}} \
2414 [list add-database-action $target $wp] {destroy .database-select}
2416 top-down-ok-cancel $w [list add-database-action $target $wp] 1
2421 # Procedure delete-database {target w}
2422 # target target to be defined
2423 # w top level widget for the target definition
2424 # Asks the user if he/she really wishes to delete a database and removes
2425 # the database from the database-list if requested.
2426 proc delete-database {target w} {
2430 foreach i [$w.top.databases.list curselection] {
2431 set b [$w.top.databases.list get $i]
2434 set a [alert "Are you sure you want to remove the database(s)${l}?"]
2436 foreach i [lsort -decreasing \
2437 [$w.top.databases.list curselection]] {
2438 $w.top.databases.list delete $i
2443 # Procedure protocol-setup {target}
2444 # target target to be defined
2445 # Makes a dialog in which the user may modify/view a target definition
2446 # (profile). The $profileS - array holds the initial definition of the
2448 proc protocol-setup {target} {
2449 global profile profileS
2452 while {[winfo exists .setup-$bno]} {
2459 wm title $w "Setup $target"
2463 if {![string length $target]} {
2466 foreach n [array names profile $target,*] {
2467 set profileS($n) $profile($n)
2470 frame $w.top.description
2473 frame $w.top.idAuthentication
2475 frame $w.top.cs-type -relief ridge -border 2
2476 frame $w.top.protocol -relief ridge -border 2
2477 frame $w.top.query -relief ridge -border 2
2478 frame $w.top.databases -relief ridge -border 2
2480 # Maximum/preferred/idAuth ...
2481 pack $w.top.description $w.top.host $w.top.port \
2482 $w.top.idAuthentication -side top -anchor e -pady 2
2484 entry-fields $w.top {description host port idAuthentication } \
2485 {{Description:} {Host:} {Port:} {Id Authentication:}} \
2486 [list protocol-setup-action $target $w] [list destroy $w]
2488 foreach sub {description host port idAuthentication} {
2490 bind $w.top.$sub.entry <Control-a> [list add-database $target $w]
2491 bind $w.top.$sub.entry <Control-d> [list delete-database $target $w]
2493 $w.top.description.entry configure -textvariable \
2494 profileS($target,description)
2495 $w.top.host.entry configure -textvariable \
2496 profileS($target,host)
2497 $w.top.port.entry configure -textvariable \
2498 profileS($target,port)
2499 $w.top.idAuthentication.entry configure -textvariable \
2500 profileS($target,authentication)
2503 pack $w.top.databases -side left -pady 2 -padx 2 -expand yes -fill both
2505 label $w.top.databases.label -text "Databases"
2506 button $w.top.databases.add -text Add \
2507 -command [list add-database $target $w]
2508 button $w.top.databases.delete -text Delete \
2509 -command [list delete-database $target $w]
2511 listbox $w.top.databases.list -geometry 14x6 \
2512 -yscrollcommand "$w.top.databases.scroll set"
2514 listbox $w.top.databases.list -width 14 -height 5\
2515 -yscrollcommand "$w.top.databases.scroll set"
2517 scrollbar $w.top.databases.scroll -orient vertical -border 1
2518 pack $w.top.databases.label -side top -fill x \
2520 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
2522 pack $w.top.databases.list -side left -fill both -expand yes \
2524 pack $w.top.databases.scroll -side right -fill y \
2526 $w.top.databases.scroll config -command "$w.top.databases.list yview"
2528 if {[info exists profile($target,databases)]} {
2529 foreach b $profile($target,databases) {
2530 $w.top.databases.list insert end $b
2534 pack $w.top.cs-type -pady 2 -padx 2 -side top -fill x
2536 label $w.top.cs-type.label -text "Transport"
2537 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" -anchor w \
2538 -variable profileS($target,comstack) -value tcpip
2539 radiobutton $w.top.cs-type.mosi -text "MOSI" -anchor w\
2540 -variable profileS($target,comstack) -value mosi
2542 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
2543 -padx 2 -side top -fill x
2546 pack $w.top.protocol -pady 2 -padx 2 -side top -fill x
2548 label $w.top.protocol.label -text "Protocol"
2549 radiobutton $w.top.protocol.z39v2 -text "Z39.50" -anchor w \
2550 -variable profileS($target,protocol) -value Z39
2551 radiobutton $w.top.protocol.sr -text "SR" -anchor w \
2552 -variable profileS($target,protocol) -value SR
2554 pack $w.top.protocol.label $w.top.protocol.z39v2 $w.top.protocol.sr \
2555 -padx 2 -side top -fill x
2558 pack $w.top.query -pady 2 -padx 2 -side top -fill x
2560 label $w.top.query.label -text "Query support"
2561 checkbutton $w.top.query.c1 -text "RPN query" -anchor w \
2562 -variable profileS($target,queryRPN)
2563 checkbutton $w.top.query.c2 -text "CCL query" -anchor w \
2564 -variable profileS($target,queryCCL)
2565 checkbutton $w.top.query.c3 -text "Result sets" -anchor w \
2566 -variable profileS($target,namedResultSets)
2568 pack $w.top.query.label -side top
2569 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
2570 -padx 2 -side top -fill x
2573 bottom-buttons $w [list {Ok} [list protocol-setup-action $target $w] \
2574 {Delete} [list protocol-setup-delete $target $w] \
2575 {Advanced} [list advanced-setup $target $bno] \
2576 {Cancel} [list destroy $w]] 0
2579 # Procedure advanced-setup {target b}
2580 # target target to be defined
2581 # b window number of target top level
2582 # Makes a dialog in which the user may modify/view advanced settings
2583 # of a target definition (profile).
2584 proc advanced-setup {target b} {
2588 set w .advanced-setup-$b
2592 wm title $w "Advanced setup $target"
2596 if {![string length $target]} {
2601 frame $w.top.largeSetLowerBound
2602 frame $w.top.smallSetUpperBound
2603 frame $w.top.mediumSetPresentNumber
2604 frame $w.top.presentChunk
2605 frame $w.top.maximumRecordSize
2606 frame $w.top.preferredMessageSize
2608 pack $w.top.largeSetLowerBound $w.top.smallSetUpperBound \
2609 $w.top.mediumSetPresentNumber $w.top.presentChunk \
2610 $w.top.maximumRecordSize $w.top.preferredMessageSize \
2611 -side top -anchor e -pady 2
2613 entry-fields $w.top {largeSetLowerBound smallSetUpperBound \
2614 mediumSetPresentNumber presentChunk maximumRecordSize \
2615 preferredMessageSize} \
2616 {{Large Set Lower Bound:} {Small Set Upper Bound:} \
2617 {Medium Set Present Number:} {Present Chunk:} \
2618 {Maximum Record Size:} {Preferred Message Size:}} \
2619 [list advanced-setup-action $target $b] [list destroy $w]
2621 $w.top.largeSetLowerBound.entry configure -textvariable \
2622 profileS($target,largeSetLowerBound)
2623 $w.top.smallSetUpperBound.entry configure -textvariable \
2624 profileS($target,smallSetUpperBound)
2625 $w.top.mediumSetPresentNumber.entry configure -textvariable \
2626 profileS($target,mediumSetPresentNumber)
2627 $w.top.presentChunk.entry configure -textvariable \
2628 profileS($target,presentChunk)
2629 $w.top.maximumRecordSize.entry configure -textvariable \
2630 profileS($target,maximumRecordSize)
2631 $w.top.preferredMessageSize.entry configure -textvariable \
2632 profileS($target,preferredMessageSize)
2634 bottom-buttons $w [list {Ok} [list advanced-setup-action $target $b] \
2635 {Cancel} [list destroy $w]] 0
2638 # Procedure advanced-setup-action {target b}
2639 # target target to be defined
2640 # b window number of target top level
2641 # This procedure is called when the user hits Ok in the advanced target
2642 # setup dialog. The temporary result is stored in the $profileS - array.
2643 proc advanced-setup-action {target b} {
2644 set w .advanced-setup-$b
2647 set profileS($target,LSLB) [$w.top.largeSetLowerBound.entry get]
2648 set profileS($target,SSUB) [$w.top.smallSetUpperBound.entry get]
2649 set profileS($target,MSPN) [$w.top.mediumSetPresentNumber.entry get]
2650 set profileS($target,presentChunk) [$w.top.presentChunk.entry get]
2651 set profileS($target,MRS) [$w.top.maximumRecordSize.entry get]
2652 set profileS($target,PMS) [$w.top.preferredMessageSize.entry get]
2654 dputs "advanced-setup-action"
2658 # Procedure database-select-action
2659 # Called when the user commits a database select change. See procedure
2661 proc database-select-action {} {
2662 set w .database-select.top
2664 foreach indx [$w.databases.list curselection] {
2665 lappend b [$w.databases.list get $indx]
2668 z39 databaseNames $b
2670 destroy .database-select
2673 # Procedure database-select
2674 # Makes a dialog in which the user may select a database
2675 proc database-select {} {
2676 set w .database-select
2681 set oldFocus [focus]
2686 frame $w.top.databases -relief ridge -border 2
2688 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
2690 label $w.top.databases.label -text "List"
2691 listbox $w.top.databases.list -width 20 -height 6 \
2692 -yscrollcommand "$w.top.databases.scroll set"
2693 scrollbar $w.top.databases.scroll -orient vertical -border 1
2694 pack $w.top.databases.label -side top -fill x \
2696 pack $w.top.databases.list -side left -fill both -expand yes \
2698 pack $w.top.databases.scroll -side right -fill y \
2700 $w.top.databases.scroll config -command "$w.top.databases.list yview"
2702 foreach b $profile($hostid,databases) {
2703 $w.top.databases.list insert end $b
2705 top-down-ok-cancel $w {database-select-action} 1
2709 # Procedure cascase-dblist-select
2710 proc cascade-dblist-select {target db} {
2711 show-target $target $db
2712 z39 databaseNames $db
2715 # Procedure cascade-dblist
2716 # Makes the Service/database list with proper databases for the target
2717 proc cascade-dblist {target base} {
2720 set w .top.service.m.dblist
2722 if {[info exists profile($target,databases)]} {
2723 foreach db $profile($target,databases) {
2724 $w add command -label $db \
2725 -command [list cascade-dblist-select $target $db]
2730 # Procedure cascade-target-list
2731 # Makes all target/databases available in the Target|Connect
2732 # menu as well as all targets in the Target|Setup menu.
2733 # This procedure is called whenever target definitions occur.
2734 proc cascade-target-list {} {
2737 foreach sub [winfo children .top.target.m.clist] {
2740 .top.target.m.clist delete 0 last
2741 foreach nn [lsort [array names profile *,host]] {
2742 if {[string length $profile($nn)]} {
2743 set ll [expr [string length $nn] - 6]
2744 set n [string range $nn 0 $ll]
2746 set nl $profile($n,windowNumber)
2747 if {[info exists profile($n,databases)]} {
2748 set ndb [llength $profile($n,databases)]
2753 .top.target.m.clist add cascade -label $n \
2754 -menu .top.target.m.clist.$nl
2755 irmenu .top.target.m.clist.$nl
2756 foreach b $profile($n,databases) {
2757 .top.target.m.clist.$nl add command -label $b \
2758 -command [list reopen-target $n $b]
2760 } elseif {$ndb == 1} {
2761 .top.target.m.clist add command -label $n -command \
2762 [list reopen-target $n [lindex $profile($n,databases) 0]]
2764 .top.target.m.clist add command -label $n -command \
2765 [list reopen-target $n {}]
2769 .top.target.m.slist delete 0 last
2770 foreach nn [lsort [array names profile *,host]] {
2771 set ll [expr [string length $nn] - 6]
2772 set n [string range $nn 0 $ll]
2774 .top.target.m.slist add command -label $n \
2775 -command [list protocol-setup $n]
2779 # Procedure query-select {i}
2780 # i Query type number (integer)
2781 # This procedure is called when the user selects a Query type. The current
2782 # query type information given by the globals $queryButtonsFind and
2783 # $queryInfoFind are affected by this operation.
2784 proc query-select {i} {
2785 global queryButtonsFind
2786 global queryInfoFind
2790 set queryInfoFind [lindex $queryInfo $i]
2791 set queryButtonsFind [lindex $queryButtons $i]
2793 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2796 # Procedure query-new-action
2797 # Commits a new query type definition by extending the globals
2798 # $queryTypes, $queryButtons and $queryInfo.
2799 proc query-new-action {} {
2803 global settingsChanged
2805 set settingsChanged 1
2806 lappend queryTypes [.query-new.top.index.entry get]
2807 lappend queryButtons {}
2808 lappend queryInfo {}
2814 # Procedure query-new
2815 # Makes a dialog in which the user is requested to enter the name of a
2821 set oldFocus [focus]
2826 -side top -anchor e -pady 2
2827 entry-fields $w.top index \
2829 query-new-action {destroy .query-new}
2830 top-down-ok-cancel $w query-new-action 1
2834 # Procedure query-delete-action {queryNo}
2835 # queryNo query type number (integer)
2836 # Procedure that deletes the query type specified by $queryNo.
2837 proc query-delete-action {queryNo} {
2841 global settingsChanged
2843 set settingsChanged 1
2845 set queryTypes [lreplace $queryTypes $queryNo $queryNo]
2846 set queryButtons [lreplace $queryButtons $queryNo $queryNo]
2847 set queryInfo [lreplace $queryInfo $queryNo $queryNo]
2848 destroy .query-delete
2852 # Procedure query-delete {queryNo}
2853 # queryNo query type number (integer)
2854 # Asks if the user really want to delete a given query type; calls
2855 # query-delete-action if 'yes'.
2856 proc query-delete {queryNo} {
2864 set n [lindex $queryTypes $queryNo]
2866 label $w.top.warning -bitmap warning
2867 message $w.top.quest -text "Are you sure you want to delete the \
2868 query type $n ?" -aspect 300
2869 pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
2870 bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
2871 {Cancel} [list destroy $w]] 1
2874 # Procedure cascade-query-list
2875 # Updates the enties below Options|Query to list all query types.
2876 proc cascade-query-list {} {
2878 set w .top.options.m.query
2881 $w.slist delete 0 last
2882 foreach n $queryTypes {
2883 $w.slist add command -label $n -command [list query-setup $i]
2888 $w.clist delete 0 last
2889 foreach n $queryTypes {
2890 $w.clist add command -label $n -command [list query-select $i]
2894 $w.dlist delete 0 last
2895 foreach n $queryTypes {
2896 $w.dlist add command -label $n -command [list query-delete $i]
2901 # Procedure save-geometry
2902 # This procedure saves the per-user related settings in ~/.clientrc.tcl.
2903 # The geometry information stored in the global array $windowGeometry is
2904 # saved. Also a few other user settings, such as current display format, are
2906 proc save-geometry {} {
2907 global windowGeometry
2910 global displayFormat
2913 global elementSetNames
2916 set windowGeometry(.) [wm geometry .]
2917 puts "root=[wm geometry .]"
2919 if {[catch {set f [open ~/.clientrc.tcl w]}]} {
2922 if {$hostid != "Default"} {
2923 puts $f "set hostid [list $hostid]"
2924 set b [z39 databaseNames]
2925 puts $f "set hostbase [list $b]"
2927 puts $f "set hotTargets [list $hotTargets]"
2928 puts $f "set textWrap $textWrap"
2929 puts $f "set displayFormat $displayFormat"
2930 puts $f "set popupMarcdf $popupMarcdf"
2931 puts $f "set recordSyntax $recordSyntax"
2932 puts $f "set elementSetNames $elementSetNames"
2933 foreach n [array names windowGeometry] {
2934 puts -nonewline "set [list windowGeometry($n)] "
2935 puts [list $windowGeometry($n)]
2937 puts -nonewline $f "set [list windowGeometry($n)] "
2938 puts $f [list $windowGeometry($n)]
2943 # Procedure save-settings
2944 # This procedure saves the per-host related settings irtdb.tcl which
2945 # is normally kept in the directory /usr/local/lib/irtcl.
2946 # All query types and target defintion profiles are saved.
2947 proc save-settings {} {
2950 global settingsChanged
2955 if {[file writable "${libdir}/irtdb.tcl"]} {
2956 set f [open "${libdir}/irtdb.tcl" w]
2958 set f [open "irtdb.tcl" w]
2960 puts $f "# Setup file"
2962 foreach n [lsort [array names profile]] {
2963 puts $f "set [list profile($n)] [list $profile($n)]"
2965 puts $f "set queryTypes [list $queryTypes]"
2967 puts $f "set queryButtons [list $queryButtons]"
2969 puts $f "set queryInfo [list $queryInfo]"
2971 set settingsChanged 0
2974 # Procedure alert {ask}
2976 # Makes a grabbed dialog in which the user is requested to answer
2977 # "Ok" or "Cancel". This procedure returns 1 if the user hits "Ok"; 0
2982 global alertAnswer font
2985 set oldFocus [focus]
2989 label $w.top.warning -bitmap warning
2990 message $w.top.message -text $ask -aspect 300 -font $font(b,normal)
2992 pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
2995 top-down-ok-cancel $w {alert-action} 1
3000 # Procedure alert-action
3001 # Called when the user hits "Ok" in the .alert-window.
3002 proc alert-action {} {
3008 # Procedure exit-action
3009 # This procedure is called if the user exists the application
3010 proc exit-action {} {
3011 global settingsChanged
3013 if {$settingsChanged} {
3020 # Procedure listbuttonaction {w name h user i}
3021 # w menubutton widget
3022 # name name information
3023 # h handler to be invoked
3024 # user user information to be passed to handler $h
3025 # i index passed as second argument to handler $h
3026 # Utility function to emulate a listbutton. Called when the user
3027 # Modifies the listbutton. See procedure listbuttonx.
3028 proc listbuttonaction {w name h user i} {
3029 $w configure -text [lindex $name 0]
3030 $h [lindex $name 1] $user $i
3033 # Procedure listbuttonx {button no names handle user}
3034 # button menubutton widget
3035 # no initial value index (integer)
3036 # names list of name entries. The first entry in each name
3037 # entry is the actual name
3038 # handle user function to be called when the listbutton changes
3040 # user user argument to the $handle function
3041 # Makes an extended listbutton.
3042 proc listbuttonx {button no names handle user} {
3043 if {[winfo exists $button]} {
3044 $button configure -text [lindex [lindex $names $no] 0]
3045 ${button}.m delete 0 last
3047 menubutton $button -text [lindex [lindex $names $no] 0] \
3048 -width 10 -menu ${button}.m -relief raised -border 1
3051 ${button}.m configure -tearoff off
3055 foreach name $names {
3056 ${button}.m add command -label [lindex $name 0] \
3057 -command [list listbuttonaction ${button} $name \
3063 # Procedure listbutton {button no names}
3064 # button menubutton widget
3065 # no initial value index (integer)
3066 # names list of possible values.
3067 # Makes a listbutton. The functionality is emulated by the use menubutton-
3069 proc listbutton {button no names} {
3070 menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
3071 -relief raised -border 1
3074 ${button}.m configure -tearoff off
3076 foreach name $names {
3077 ${button}.m add command -label $name \
3078 -command [list ${button} configure -text $name]
3082 # Procedure listbuttonv-action {button var names i}
3083 # button menubutton widget
3084 # var global variable to be affected
3085 # names list of possible names and values
3086 # This procedure is called when the user alters a menu created by the
3087 # listbuttonv procedure. The global variable $var is updated.
3088 proc listbuttonv-action {button var names i} {
3091 set $var [lindex $names [expr $i+1]]
3092 $button configure -text [lindex $names $i]
3095 # Procedure listbuttonv {button var names}
3096 # button menubutton widget
3097 # var global variable to be affected
3098 # names List of name/value pairs, i.e. {n1 v1 n2 v2 ...}.
3099 # This procedure emulates a listbutton by means of menu/menubutton widgets.
3100 # The global variable $var is automatically updated and set to one of the
3101 # values v1, v2, ...
3102 proc listbuttonv {button var names} {
3106 eval "set val $$var"
3107 set l [llength $names]
3108 for {set i 1} {$i < $l} {incr i 2} {
3109 if {$val == [lindex $names $i]} {
3111 set n [lindex $names $i]
3115 if {[winfo exists $button]} {
3116 $button configure -text $n
3119 menubutton $button -text $n -menu ${button}.m \
3120 -relief raised -border 1
3123 ${button}.m configure -tearoff off
3125 for {set i 0} {$i < $l} {incr i 2} {
3126 ${button}.m add command -label [lindex $names $i] \
3127 -command [list listbuttonv-action $button $var $names $i]
3131 # Procedure query-add-index-action {queryNo}
3132 # queryNo query type number (integer)
3133 # Handler that makes a new query index.
3134 proc query-add-index-action {queryNo} {
3138 global queryButtonsTmp
3140 set newI [.query-add-index.top.index.entry get]
3141 lappend queryInfoTmp [list $newI {}]
3142 $w.top.index.list insert end $newI
3143 destroy .query-add-index
3144 #destroy $w.top.lines
3145 #frame $w.top.lines -relief ridge -border 2
3146 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3147 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
3150 # Procedure query-add-line
3151 # queryNo query type number (integer)
3152 # Handler that adds new query line.
3153 proc query-add-line {queryNo} {
3157 global queryButtonsTmp
3159 lappend queryButtonsTmp {I 0}
3161 #destroy $w.top.lines
3162 #frame $w.top.lines -relief ridge -border 2
3163 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3164 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
3167 # Procedure query-del-line
3168 # queryNo query type number (integer)
3169 # Handler that removes query line.
3170 proc query-del-line {queryNo} {
3174 global queryButtonsTmp
3176 set l [llength $queryButtonsTmp]
3181 set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
3182 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3185 # Procedure query-add-index
3186 # queryNo query type number (integer)
3187 # Handler that adds new query index.
3188 proc query-add-index {queryNo} {
3189 set w .query-add-index
3192 set oldFocus [focus]
3193 place-force $w .query-setup
3197 -side top -anchor e -pady 2
3198 entry-fields $w.top {index} \
3200 [list query-add-index-action $queryNo] [list destroy $w]
3201 top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
3205 # Procedure query-setup-action
3206 # queryNo query type number (integer)
3207 # Handler that updates the query information database stored in the
3208 # globals $queryInfo and $queryButtons. This procedure is executed when
3209 # the user commits the query setup changes by pressing button "Ok".
3210 proc query-setup-action {queryNo} {
3213 global queryButtonsTmp
3215 global queryButtonsFind
3216 global queryInfoFind
3218 global settingsChanged
3220 set settingsChanged 1
3222 set queryInfo [lreplace $queryInfo $queryNo $queryNo \
3224 set queryButtons [lreplace $queryButtons $queryNo $queryNo \
3226 set queryInfoFind $queryInfoTmp
3227 set queryButtonsFind $queryButtonsTmp
3229 destroy .query-setup
3230 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
3233 # Procedure activate-e-index {value no i}
3235 # no query index number
3236 # i menu index (integer)
3237 # Procedure called when listbutton is activated in the query type edit
3238 # window. The global $queryButtonsTmp is updated in this operation.
3239 proc activate-e-index {value no i} {
3240 global queryButtonsTmp
3241 global queryIndexTmp
3243 set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
3244 dputs $queryButtonsTmp
3245 set queryIndexTmp $i
3248 # Procedure activate-index {value no i}
3250 # no query index number
3251 # i menu index (integer)
3252 # Procedure called when listbutton is activated in the main query
3253 # window. The global $queryButtonsFind is updated in this operation.
3254 proc activate-index {value no i} {
3255 global queryButtonsFind
3257 set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
3259 dputs "queryButtonsFind $queryButtonsFind"
3262 # Procedure update-attr
3263 # This procedure creates listbuttons for all bib-1 attributes except
3264 # the use-attribute in the .index-setup window.
3265 # The globals $relationTmpValue, $positionTmpValue, $structureTmpValue,
3266 # $truncationTmpValue and $completenessTmpValue are maintainted by the
3268 proc update-attr {} {
3270 listbuttonv $w.top.relation.b relationTmpValue\
3271 {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
3272 {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
3273 {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
3274 listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
3275 {First in field} 1 {First in subfield} 2 {Any position in field} 3}
3276 listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
3277 {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list} 6 \
3278 {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
3279 {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
3280 {local-number} 107 {string} 108 {numeric string} 109}
3281 listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
3282 {Left} 2 {Left and right} 3 {No truncation} 100 \
3283 {Process #} 101 {Re-1} 102 {Re-2} 103}
3284 listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
3285 {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
3288 # Procedure use-attr {init}
3290 # This procedure creates a listbox with several Bib-1 use attributes.
3291 # If $init is 1 the listbox is created with the attributes. If $init
3292 # is 0 the current selection of the listbox is read and the global
3293 # $useTmpValue is set to the current use-value.
3294 proc use-attr {init} {
3306 {BNB card number} 10
3307 {BGF(sic) number} 11
3309 {Dewey classification} 13
3310 {UDC classification} 14
3311 {Bliss classification} 15
3313 {NLM call number} 17
3314 {NAL call number} 18
3315 {MOS call number} 19
3316 {Local classification} 20
3317 {Subject heading} 21
3319 {BDI-index-subject} 23
3323 {LC-subject-heading} 27
3324 {RVM-subject-heading} 28
3325 {Local subject index} 29
3327 {Date of publication} 31
3328 {Date of acquisition} 32
3330 {Title-collective} 34
3333 {Title-added-title-page} 37
3337 {Title-other-variant} 41
3339 {Title-abbreviated} 43
3343 {Subject-subdivision} 47
3344 {Number-natl-bibliography} 48
3345 {Number-legal-deposit} 49
3346 {Number-govt-publication} 50
3347 {Number-publisher-for-music} 51
3349 {Number-local-call} 53
3351 {Code-geographic-area} 55
3352 {Code-institution} 56
3354 {Name-geographic} 58
3355 {Place-publication} 59
3357 {Microform-generation} 61
3364 {Author-name-personal} 1004
3365 {Author-name-corporate} 1005
3366 {Author-name-conference} 1006
3367 {Identifier-standard} 1007
3368 {Subject-LC-children's} 1008
3369 {Subject-name-personal} 1009
3371 {Date/time added to database} 1011
3372 {Date/time last modified} 1012
3373 {Authority/format identifier} 1013
3375 {Concept-reference} 1015
3377 {Server choice} 1017
3379 {Record source} 1019
3382 {Geographic class} 1022
3386 {Related periodical} 1026
3387 {Report number} 1027
3389 {Thematic number} 1030
3390 {Material type} 1031
3395 {Author-Title-Subject} 1036
3399 set l [llength $attr]
3404 for {set i 0} {$i < $l} {incr i} {
3405 $w.top.use.list insert end [lindex $attr $i]
3407 if {$useTmpValue == [lindex $attr $i]} {
3413 $w.top.use.list selection clear 0 end
3414 $w.top.use.list selection set $s $s
3416 $w.top.use.list select from $s
3417 $w.top.use.list select to $s
3423 $w.top.use.list yview $s
3425 set lno [lindex [$w.top.use.list curselection] 0]
3426 set i [expr $lno+$lno+1]
3427 set useTmpValue [lindex $attr $i]
3428 dputs "useTmpValue=$useTmpValue"
3432 # Procedure index-setup-action {oldAttr queryNo indexNo}
3433 # oldAttr original attributes (?)
3434 # queryNo query number
3435 # indexNo index number
3436 # Commits setup of a query index. The mapping from the index to
3437 # the Bib-1 attributes are handled by this function.
3438 proc index-setup-action {oldAttr queryNo indexNo} {
3439 set attr [lindex $oldAttr 0]
3442 global relationTmpValue
3443 global structureTmpValue
3444 global truncationTmpValue
3445 global completenessTmpValue
3446 global positionTmpValue
3451 dputs "index-setup-action"
3452 dputs "queryNo $queryNo"
3453 dputs "indexNo $indexNo"
3454 if {$useTmpValue > 0} {
3455 lappend attr "1=$useTmpValue"
3457 if {$relationTmpValue > 0} {
3458 lappend attr "2=$relationTmpValue"
3460 if {$positionTmpValue > 0} {
3461 lappend attr "3=$positionTmpValue"
3463 if {$structureTmpValue > 0} {
3464 lappend attr "4=$structureTmpValue"
3466 if {$truncationTmpValue > 0} {
3467 lappend attr "5=$truncationTmpValue"
3469 if {$completenessTmpValue > 0} {
3470 lappend attr "6=$completenessTmpValue"
3472 dputs "new attr $attr"
3473 set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
3474 destroy .index-setup
3477 # Procedure index-setup {attr queryNo indexNo}
3478 # attr original attributes
3479 # queryNo query number
3480 # indexNo index number
3481 # Makes a window with settings of a given query index which the user
3482 # may inspect/modify.
3483 proc index-setup {attr queryNo indexNo} {
3486 global relationTmpValue
3487 global structureTmpValue
3488 global truncationTmpValue
3489 global completenessTmpValue
3490 global positionTmpValue
3492 set relationTmpValue 0
3493 set truncationTmpValue 0
3494 set structureTmpValue 0
3495 set positionTmpValue 0
3496 set completenessTmpValue 0
3502 set n [lindex $attr 0]
3503 wm title $w "Index setup $n"
3507 set len [llength $attr]
3508 for {set i 1} {$i < $len} {incr i} {
3509 set q [lindex $attr $i]
3510 set l [string first = $q]
3512 set t [string range $q 0 [expr $l - 1]]
3513 set v [string range $q [expr $l + 1] end]
3516 { set useTmpValue $v }
3518 { set relationTmpValue $v }
3520 { set positionTmpValue $v }
3522 { set structureTmpValue $v }
3524 { set truncationTmpValue $v }
3526 { set completenessTmpValue $v }
3531 frame $w.top.use -relief ridge -border 2
3532 frame $w.top.relation -relief ridge -border 2
3533 frame $w.top.position -relief ridge -border 2
3534 frame $w.top.structure -relief ridge -border 2
3535 frame $w.top.truncation -relief ridge -border 2
3536 frame $w.top.completeness -relief ridge -border 2
3542 pack $w.top.use -side left -pady 6 -padx 6 -fill y
3544 label $w.top.use.label -text "Use"
3546 listbox $w.top.use.list -width 26 \
3547 -yscrollcommand "$w.top.use.scroll set"
3549 listbox $w.top.use.list -geometry 26x10 \
3550 -yscrollcommand "$w.top.use.scroll set"
3552 scrollbar $w.top.use.scroll -orient vertical -border 1
3553 pack $w.top.use.label -side top -fill x \
3555 pack $w.top.use.list -side left -fill both -expand yes \
3557 pack $w.top.use.scroll -side right -fill y \
3559 $w.top.use.scroll config -command "$w.top.use.list yview"
3563 # Relation Attributes
3565 pack $w.top.relation -pady 6 -padx 6 -side top
3566 label $w.top.relation.label -text "Relation" -width 18
3568 pack $w.top.relation.label $w.top.relation.b -fill x
3570 # Position Attributes
3572 pack $w.top.position -pady 6 -padx 6 -side top
3573 label $w.top.position.label -text "Position" -width 18
3575 pack $w.top.position.label $w.top.position.b -fill x
3577 # Structure Attributes
3579 pack $w.top.structure -pady 6 -padx 6 -side top
3580 label $w.top.structure.label -text "Structure" -width 18
3582 pack $w.top.structure.label $w.top.structure.b -fill x
3584 # Truncation Attributes
3586 pack $w.top.truncation -pady 6 -padx 6 -side top
3587 label $w.top.truncation.label -text "Truncation" -width 18
3589 pack $w.top.truncation.label $w.top.truncation.b -fill x
3591 # Completeness Attributes
3593 pack $w.top.completeness -pady 6 -padx 6 -side top
3594 label $w.top.completeness.label -text "Completeness" -width 18
3596 pack $w.top.completeness.label $w.top.completeness.b -fill x
3599 bottom-buttons $w [list \
3600 {Ok} [list index-setup-action $attr $queryNo $indexNo] \
3601 {Cancel} [list destroy $w]] 0
3605 # Procedure query-edit-index {queryNo}
3606 # queryNo query number
3607 # Determines if a selection of an index is active. If one is selected
3608 # the index-setup dialog is started.
3609 proc query-edit-index {queryNo} {
3613 set i [lindex [$w.top.index.list curselection] 0]
3614 if {![string length $i]} {
3617 set attr [lindex $queryInfoTmp $i]
3618 dputs "Editing no $i $attr"
3619 index-setup $attr $queryNo $i
3622 # Procedure query-delete-index {queryNo}
3623 # queryNo query number
3624 # Determines if a selection of an index is active. If one is selected
3625 # the index is deleted.
3626 proc query-delete-index {queryNo} {
3628 global queryButtonsTmp
3631 set i [lindex [$w.top.index.list curselection] 0]
3632 if {![string length $i]} {
3635 set queryInfoTmp [lreplace $queryInfoTmp $i $i]
3636 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3637 $w.top.index.list delete $i
3640 # Procedure query-setup {queryNo}
3641 # queryNo query number
3642 # Makes a dialog in which a query type an be customized.
3643 proc query-setup {queryNo} {
3649 global queryButtonsTmp
3651 global queryIndexTmp
3654 set queryName [lindex $queryTypes $queryNo]
3655 set queryInfoTmp [lindex $queryInfo $queryNo]
3656 set queryButtonsTmp [lindex $queryButtons $queryNo]
3661 wm title $w "Query setup $queryName"
3665 frame $w.top.lines -relief ridge -border 2
3667 pack $w.top.lines -side left -pady 6 -padx 6 -fill y
3671 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
3673 button $w.top.lines.add -text "Add" \
3674 -command [list query-add-line $queryNo]
3675 button $w.top.lines.del -text "Remove" \
3676 -command [list query-del-line $queryNo]
3678 pack $w.top.lines.del -fill x -side bottom
3679 pack $w.top.lines.add -fill x -pady 10 -side bottom
3683 frame $w.top.index -relief ridge -border 2
3684 pack $w.top.index -pady 6 -padx 6 -side right -fill y
3686 listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
3687 scrollbar $w.top.index.scroll -orient vertical -border 1 \
3688 -command [list $w.top.index.list yview]
3689 bind $w.top.index.list <Double-1> [list query-edit-index $queryNo]
3691 pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
3692 pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
3695 $w.top.index.list selection clear 0 end
3696 $w.top.index.list selection set 0 0
3698 $w.top.index.list select from 0
3699 $w.top.index.list select to 0
3702 foreach x $queryInfoTmp {
3703 $w.top.index.list insert end [lindex $x 0]
3707 bottom-buttons $w [list \
3708 Ok [list query-setup-action $queryNo] \
3709 Add [list query-add-index $queryNo] \
3710 Edit [list query-edit-index $queryNo] \
3711 Delete [list query-delete-index $queryNo] \
3712 Cancel [list destroy $w]] 0
3715 # Procedure index-clear
3716 # Handler that clears the search entry fields.
3717 proc index-clear {} {
3718 global queryButtonsFind
3721 foreach b $queryButtonsFind {
3722 .lines.$i.e delete 0 end
3727 # Procedure index-query
3728 # The purpose of this function is to read the user's query and convert
3729 # it to the prefix query that IrTcl/YAZ uses to represent an RPN query.
3730 # Each entry in a search fields takes the form
3732 # Here, relOp is an optional relational operator and one of:
3734 # which sets the Bib-1 relation to greater-than, less-than, etc.
3735 # The ? (question-mark) is also optional. A (?) on left-side indicates
3736 # left truncation; (?) on right-side indicates right-truncation; (?)
3737 # on both sides indicates both-left-and-right truncation.
3738 proc index-query {} {
3739 global queryButtonsFind
3740 global queryInfoFind
3745 foreach b $queryButtonsFind {
3746 set term [string trim [.lines.$i.e get]]
3748 set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
3751 set len [string length $term]
3755 if {[string index $term 0] == ">"} {
3756 if {[string index $term 1] == "=" } {
3757 set term [string trim [string range $term 2 $len]]
3760 set term [string trim [string range $term 1 $len]]
3763 } elseif {[string index $term 0] == "<"} {
3764 if {[string index $term 1] == "=" } {
3765 set term [string trim [string range $term 2 $len]]
3767 } elseif {[string index $term 1] == ">"} {
3768 set term [string trim [string range $term 2 $len]]
3771 set term [string trim [string range $term 1 $len]]
3776 set len [string length $term]
3780 if {[string index $term $len] == "?"} {
3782 set term [string range $term 0 [expr $len - 1]]
3784 if {[string index $term 0] == "?"} {
3786 set term [string range $term 1 end]
3788 set term "\{${term}\}"
3789 if {$right && $left} {
3790 set term "@attr 5=3 ${term}"
3792 set term "@attr 5=1 ${term}"
3794 set term "@attr 5=2 ${term}"
3796 if {$relation != ""} {
3797 set term "@attr 2=${relation} ${term}"
3800 set term "@attr $a ${term}"
3803 set qs "@and ${qs} ${term}"
3814 # Procedure index-focus-in {w i}
3817 # This procedure handles <FocusIn> events. A red border is drawed
3818 # around the active search entry field when tk3.6 is used (tk4.X
3819 # makes a black focus border itself).
3820 proc index-focus-in {w i} {
3821 global curIndexEntry
3824 $w.$i configure -background red
3826 set curIndexEntry $i
3829 # Procedure index-lines {w readOp buttonInfo queryInfo handle}
3830 # w search fields entry frame
3831 # realOp if true, search-request bindings are bound to the entries.
3832 # buttonInfo query type button information
3833 # queryInfo query type field information
3834 # handle handler called a when a 'listbutton' changes its value
3835 # Makes one or more search areas - with listbuttons on the left
3836 # and entries on the right.
3837 proc index-lines {w realOp buttonInfo queryInfo handle} {
3839 foreach b $buttonInfo {
3840 if {! [winfo exists $w.$i]} {
3842 frame $w.$i -border 0
3844 frame $w.$i -background white -border 1
3847 listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
3850 if {! [winfo exists $w.$i.e]} {
3851 entry $w.$i.e -width 32 -relief sunken -border 1
3852 bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
3854 bind $w.$i.e <FocusOut> [list $w.$i configure \
3857 pack $w.$i.l -side left
3858 pack $w.$i.e -side left -fill x -expand yes
3859 pack $w.$i -side top -fill x -padx 2 -pady 2
3861 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
3862 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
3864 bind $w.$i.e <Return> {search-request 0}
3867 pack $w.$i.l -side left
3868 pack $w.$i -side top -fill x -padx 2 -pady 2
3873 while {[winfo exists $w.$j]} {
3885 bind $w.$j.e <Tab> "focus $w.$k.e"
3891 bind $w.$i.e <Tab> "focus $w.0.e"
3897 # Procedure search-fields {w buttondefs}
3898 # w search fields entry frame
3899 # buttondefs button definitions
3900 # Makes search entry fields and listbuttons.
3901 # Note: This procedure is not used elsewhere. The index-lines
3902 # procedure is used instead.
3903 proc search-fields {w buttondefs} {
3905 foreach buttondef $buttondefs {
3906 frame $w.$i -background white
3908 listbutton $w.$i.l 0 $buttondef
3909 entry $w.$i.e -width 32 -relief sunken
3911 pack $w.$i.l -side left
3912 pack $w.$i.e -side left -fill x -expand yes
3914 pack $w.$i -side top -fill x -padx 2 -pady 2
3916 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
3917 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
3925 bind $w.$j.e <Tab> "focus $w.$k.e \n
3926 $w.$k configure -background red \n
3927 $w.$j configure -background white"
3930 bind $w.$i.e <Tab> "focus $w.0.e \n
3931 $w.0 configure -background red \n
3932 $w.$i configure -background white"
3934 $w.0 configure -background red
3937 # Init: Presentation formats are read.
3940 # Init: The main window is defined.
3941 frame .top -border 1 -relief raised
3942 frame .lines -border 1 -relief raised
3943 frame .mid -border 1 -relief raised
3944 frame .data -border 1 -relief raised
3945 frame .bot -border 1 -relief raised
3946 pack .top .lines .mid -side top -fill x
3947 pack .data -side top -fill both -expand yes
3950 # Init: Definition of File menu.
3951 menubutton .top.file -text File -menu .top.file.m
3953 .top.file.m add command -label {Save settings} -command {save-settings}
3954 .top.file.m add separator
3955 .top.file.m add command -label Exit -command {exit-action}
3957 # Init: Definition of Target menu.
3958 menubutton .top.target -text Target -menu .top.target.m
3959 irmenu .top.target.m
3960 .top.target.m add cascade -label Connect -menu .top.target.m.clist
3961 .top.target.m add command -label Disconnect -command {close-target}
3962 .top.target.m add command -label About -command {about-target}
3963 .top.target.m add cascade -label Setup -menu .top.target.m.slist
3964 .top.target.m add command -label {Setup new} -command {define-target-dialog}
3965 .top.target.m add separator
3966 set-target-hotlist 0
3968 configure-disable-e .top.target.m 1
3969 configure-disable-e .top.target.m 2
3971 irmenu .top.target.m.clist
3972 irmenu .top.target.m.slist
3975 # Init: Definition of Service menu.
3976 menubutton .top.service -text Service -menu .top.service.m
3977 irmenu .top.service.m
3978 .top.service.m add cascade -label Database -menu .top.service.m.dblist
3979 .top.service.m add cascade -label Present -menu .top.service.m.present
3980 irmenu .top.service.m.present
3981 .top.service.m.present add command -label {50 More} \
3982 -command [list present-more 50]
3983 .top.service.m.present add command -label All \
3984 -command [list present-more {}]
3985 .top.service.m add command -label Search -command {search-request 0}
3986 .top.service.m add command -label Scan -command {scan-request}
3987 .top.service.m add command -label Explain -command \
3988 {explain-refresh $hostid {ready-response {}} }
3990 .top.service configure -state disabled
3992 irmenu .top.service.m.dblist
3994 # Init: Definition of Set menu.
3995 menubutton .top.rset -text Set -menu .top.rset.m
3997 .top.rset.m add command -label Load -command {load-set}
3998 .top.rset.m add separator
4000 # Init: Definition of the Options menu.
4001 menubutton .top.options -text Options -menu .top.options.m
4002 irmenu .top.options.m
4003 .top.options.m add cascade -label Query -menu .top.options.m.query
4004 .top.options.m add cascade -label Format -menu .top.options.m.formats
4005 .top.options.m add cascade -label Wrap -menu .top.options.m.wrap
4006 .top.options.m add cascade -label Syntax -menu .top.options.m.syntax
4007 .top.options.m add cascade -label Elements -menu .top.options.m.elements
4008 .top.options.m add radiobutton -label Debug -variable debugMode -value 1
4010 # Init: Definition of the Options|Query menu.
4011 irmenu .top.options.m.query
4012 .top.options.m.query add cascade -label Select \
4013 -menu .top.options.m.query.clist
4014 .top.options.m.query add cascade -label Edit \
4015 -menu .top.options.m.query.slist
4016 .top.options.m.query add command -label New \
4017 -command {query-new}
4018 .top.options.m.query add cascade -label Delete \
4019 -menu .top.options.m.query.dlist
4021 irmenu .top.options.m.query.slist
4022 irmenu .top.options.m.query.clist
4023 irmenu .top.options.m.query.dlist
4026 # Init: Definition of the Options|Formats menu.
4027 irmenu .top.options.m.formats
4029 foreach f $displayFormats {
4030 .top.options.m.formats add radiobutton -label $f -value $i \
4031 -command [list set-display-format $i] -variable displayFormat
4035 # Init: Definition of the Options|Wrap menu.
4036 irmenu .top.options.m.wrap
4037 .top.options.m.wrap add radiobutton -label Character \
4038 -value char -variable textWrap -command {set-wrap char}
4039 .top.options.m.wrap add radiobutton -label Word \
4040 -value word -variable textWrap -command {set-wrap word}
4041 .top.options.m.wrap add radiobutton -label None \
4042 -value none -variable textWrap -command {set-wrap none}
4044 # Init: Definition of the Options|Syntax menu.
4045 irmenu .top.options.m.syntax
4046 .top.options.m.syntax add radiobutton -label None \
4047 -value None -variable recordSyntax
4048 .top.options.m.syntax add separator
4049 .top.options.m.syntax add radiobutton -label USMARC \
4050 -value USMARC -variable recordSyntax
4051 .top.options.m.syntax add radiobutton -label UNIMARC \
4052 -value UNIMARC -variable recordSyntax
4053 .top.options.m.syntax add radiobutton -label UKMARC \
4054 -value UKMARC -variable recordSyntax
4055 .top.options.m.syntax add radiobutton -label DANMARC \
4056 -value DANMARC -variable recordSyntax
4057 .top.options.m.syntax add radiobutton -label FINMARC \
4058 -value FINMARC -variable recordSyntax
4059 .top.options.m.syntax add radiobutton -label NORMARC \
4060 -value NORMARC -variable recordSyntax
4061 .top.options.m.syntax add radiobutton -label PICAMARC \
4062 -value PICAMARC -variable recordSyntax
4063 .top.options.m.syntax add separator
4064 .top.options.m.syntax add radiobutton -label SUTRS \
4065 -value SUTRS -variable recordSyntax
4066 .top.options.m.syntax add separator
4067 .top.options.m.syntax add radiobutton -label GRS1 \
4068 -value GRS1 -variable recordSyntax
4070 # Init: Definition of the Options|Elements menu.
4071 irmenu .top.options.m.elements
4072 .top.options.m.elements add radiobutton -label Unspecified \
4073 -value None -variable elementSetNames
4074 .top.options.m.elements add radiobutton -label Full \
4075 -value F -variable elementSetNames
4076 .top.options.m.elements add radiobutton -label Brief \
4077 -value B -variable elementSetNames
4079 # Init: Definition of Help menu.
4080 menubutton .top.help -text "Help" -menu .top.help.m
4083 .top.help.m add command -label "About" -command {about-origin}
4085 # Init: Pack menu bar items.
4086 pack .top.file .top.target .top.service .top.rset .top.options -side left
4087 pack .top.help -side right
4089 # Init: Define query area.
4090 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
4092 button .mid.search -text Search -command {search-request 0} \
4094 button .mid.scan -text Scan \
4095 -command scan-request -state disabled
4096 button .mid.present -text {Present} -command [list present-more 50] \
4099 button .mid.clear -text Clear -command index-clear
4100 pack .mid.search .mid.scan .mid.present .mid.clear -side left \
4103 # Init: Define record area in main window.
4104 text .data.record -font fixed -height 2 -width 20 -wrap none -borderwidth 0 \
4105 -relief flat -yscrollcommand [list .data.scroll set] \
4106 -wrap $textWrap -background grey85
4107 scrollbar .data.scroll -command [list .data.record yview]
4109 .data.record configure -takefocus 0
4110 .data.scroll configure -takefocus 0
4113 pack .data.scroll -side right -fill y
4114 pack .data.record -expand yes -fill both
4117 # Init: Define standards tags. These are used in the display
4118 # format procedures.
4120 .data.record tag configure marc-tag -foreground blue
4121 .data.record tag configure marc-id -foreground red
4123 .data.record tag configure marc-tag -foreground black
4124 .data.record tag configure marc-id -foreground black
4126 .data.record tag configure marc-data -foreground black
4127 .data.record tag configure marc-head -font $font(n,normal) \
4128 -foreground brown -relief raised -borderwidth 1
4129 .data.record tag configure marc-small-head -foreground brown
4130 .data.record tag configure marc-pref \
4131 -font $font(n,normal) -foreground blue
4132 .data.record tag configure marc-text \
4133 -font $font(n,normal) -foreground black
4134 .data.record tag configure marc-it \
4135 -font $font(n,normal) -foreground black
4137 # Init: Define logo.
4138 button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
4140 .bot.logo configure -takefocus 0
4142 # Init: Define status information fields at the bottom.
4144 pack .bot.a -side left -fill x
4145 pack .bot.logo -side right -padx 2 -pady 2 -ipadx 1
4147 message .bot.a.target -text {} -aspect 2000 -border 1
4149 label .bot.a.status -text "Not connected" -width 15 -relief \
4150 sunken -anchor w -border 1
4151 label .bot.a.set -text "" -width 5 -relief \
4152 sunken -anchor w -border 1
4153 label .bot.a.message -text "" -width 15 -relief \
4154 sunken -anchor w -border 1
4156 pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
4157 pack .bot.a.status .bot.a.set .bot.a.message \
4158 -side left -padx 2 -pady 2 -ipadx 1 -ipady 1
4160 # Init: Determine if the IrTcl extension is already there. If
4161 # not, then dynamically load the IrTcl extension.
4163 if {[catch {ir-version}]} {
4164 set e [info sharedlibextension]
4165 catch {load ${libdir}/irtcl$e irtcl}
4166 if {[catch {ir-version}]} {
4167 catch {load irtcl$e irtcl}
4172 ir-log-init all {} irtcl.log
4174 ir-log-init none {} {}
4177 # Create Z Assocation
4180 if {[file exists ${libdir}/explain.tcl]} {
4181 source ${libdir}/explain.tcl
4184 if {[file exists ${libdir}/setup.tcl]} {
4185 source ${libdir}/setup.tcl
4188 after 10 activateMainWindow
4190 proc activateMainWindow {} {
4191 global hostid hostbase
4192 if {[string compare $hostid Default]} {
4193 catch {open-target $hostid $hostbase}