eeac5d8e5372ecc0c5bcd807c62581bb70ae4df1
[ir-tcl-moved-to-github.git] / client2 / client.tcl
1 wm title . "IrTcl Client"
2 wm iconname . "IrTcl Client"
3
4
5 # Procedure irmenu
6 proc irmenu {w} {
7         menu $w -tearoff off
8 }
9
10     
11 # Procedure configure-enable-e {w n}
12 #  w   is a menu
13 #  n   menu entry number (0 is first entry)
14 # Enables menu entry
15 proc configure-enable-e {w n} {
16         $w entryconfigure $n -state normal
17 }
18
19 # Procedure configure-disable-e {w n}
20 #  w   is a menu
21 #  n   menu entry number (0 is first entry)
22 # Disables menu entry
23 proc configure-disable-e {w n} {
24         $w entryconfigure $n -state disabled
25 }
26 set noFocus [list -takefocus 0]
27
28
29 # Define dummy clock function if it is not there.
30 if {[catch {clock seconds}]} {
31     proc clock {args} {
32         return {}
33     }
34 }
35
36 # Define libdir to the IrTcl configuration directory.
37 # In the line below LIBDIR will be modified during 'make install'.
38 set libdir LIBDIR
39
40 # If the bitmaps sub directory is present with a bitmap we assume 
41 # the client is run from the source directory in which case we
42 # set libdir the current directory.
43 if {[file readable bitmaps/book2]} {
44     set libdir .
45 }
46
47 # Make a final check to see if libdir was set ok.
48 if {! [file readable ${libdir}/bitmaps/book2]} {
49     puts "Cannot locate system files in ${libdir}. You must either run this"
50     puts "program from the source directory root of ir-tcl or you must assure"
51     puts "that it is installed - normally in /usr/local/lib/irtcl"
52     exit 1
53 }
54
55 # Initialize a lot of globals.
56 set hotTargets {}
57 set hotInfo {}
58 set busy 0
59
60 set profile(Default,description) {}
61 set profile(Default,host) {}
62 set profile(Default,port) 210
63 set profile(Default,authentication) {}
64 set profile(Default,maximumRecordSize) 50000
65 set profile(Default,preferredMessageSize) 30000
66 set profile(Default,comstack) tcpip
67 set profile(Default,namedResultSets) 1
68 set profile(Default,queryRPN) 1
69 set profile(Default,queryCCL) 0
70 set profile(Default,protocol) Z39
71 set profile(Default,windowNumber) 1
72 set profile(Default,largeSetLowerBound) 2
73 set profile(Default,smallSetUpperBound) 0
74 set profile(Default,mediumSetPresentNumber) 0
75 set profile(Default,presentChunk) 4
76 set profile(Default,timeDefine) {}
77 set profile(Default,timeLastInit) {}
78 set profile(Default,timeLastExplain) {}
79 set profile(Default,targetInfoName) {}
80 set profile(Default,recentNews) {}
81 set profile(Default,maxResultSets) {}
82 set profile(Default,maxResultSize) {}
83 set profile(Default,maxTerms) {}
84 set profile(Default,multipleDatabases) 0
85 set profile(Default,welcomeMessage) {}
86
87 set hostid Default
88 set currentDb Default
89 set settingsChanged 0
90 set setNo 0
91 set setNoLast 0
92 set cancelFlag 0
93 set scanEnable 0
94 set displayFormat 1
95 set popupMarcdf 0
96 set textWrap word
97 set recordSyntax None
98 set elementSetNames None
99 set delayRequest {}
100 set debugMode 0
101 set queryAutoOld 0
102
103 set queryTypes {Simple}
104 set queryButtons { { {I 0} {I 1} {I 2} } }
105 set queryInfo { { {Title {1=4 4=1}} {Author {1=1}} \
106         {Subject {1=21}} {Any {1=1016}} } }
107 set queryAuto 1
108 wm minsize . 0 0
109
110 set setOffset 0
111 set setMax 0
112
113 set syntaxList {None sep USMARC UNIMARC UKMARC DANMARC FINMARC NORMARC PICAMARC sep SUTRS sep GRS1}
114
115
116 set font(bb,normal) {Helvetica 24}
117 set font(bb,bold) {Helvetica 24 bold}
118 set font(b,normal) {Helvetica 24}
119 set font(b,bold) {Helvetica 18 bold}
120 set font(n,normal) {Helvetica 12}
121 set font(n,bold) {Helvetica 12 bold}
122 set font(s,bold) {Helvetica 10 bold}
123 set font(ss,bold) {Helvetica 8 bold}
124
125 # Procedure tkerror {err}
126 #   err   error message
127 # Override the Tk error handler function.
128 if {1} {
129     proc tkerror err {
130                 global font
131                 set w .tkerrorw
132                 
133                 if {[winfo exists $w]} {
134                     destroy $w
135                 }
136                 toplevel $w
137                 wm title $w "Error"
138                 
139                 place-force $w .
140                 top-down-window $w
141                 
142                 label $w.top.b -bitmap error
143                 message $w.top.t -aspect 300 -text "Error: $err" -font $font(b,bold)
144                 pack $w.top.b $w.top.t -side left -padx 10 -pady 10
145                 
146                 bottom-buttons $w [list {Close} [list destroy $w]] 1
147     }
148 }
149
150 # Read tag set file (if present)
151 if {[file readable "${libdir}/tagsets.tcl"]} {
152     source "${libdir}/tagsets.tcl"
153 }
154
155 # Read the global target configuration file.
156 if {[file readable "${libdir}/irtdb.tcl"]} {
157     source "${libdir}/irtdb.tcl"
158 }
159 # Read the local target configuration file.
160 if {[file readable "irtdb.tcl"]} {
161     source "irtdb.tcl"
162 }
163
164 # Read the user configuration file.
165 if {[file readable "${libdir}/.clientrc.tcl"]} {
166     source "${libdir}/.clientrc.tcl"
167 }
168
169 source "bib-1.tcl"
170
171 set queryAutoOld $queryAuto
172
173 # Convert old format to new format...
174 foreach target [array names profile] {
175     set timedef [clock seconds]
176     if {[string first , $target] == -1} {
177         if {![info exists profile($target,port)]} {
178             foreach n [array names profile Default,*] {
179                 set profile($target,[string range $n 8 end]) $profile($n)
180             }
181             set profile($target,description) [lindex $profile($target) 0]
182             set profile($target,host) [lindex $profile($target) 1]
183             set profile($target,port) [lindex $profile($target) 2]
184             set profile($target,authentication) [lindex $profile($target) 3]
185             set profile($target,maximumRecordSize) \
186                 [lindex $profile($target) 4]
187             set profile($target,preferredMessageSize) \
188                 [lindex $profile($target) 5]
189             set profile($target,comstack) [lindex $profile($target) 6]
190             set profile($target,databases) [lindex $profile($target) 7]
191             set profile($target,timeDefine) $timedef
192             set profile($target,windowNumber) 1
193         }
194         unset profile($target)
195     }
196 }
197
198 # Assign unique ID's to each target's window number
199 set wno 1
200 foreach n [array names profile *,windowNumber] {
201     set profile($n) $wno
202     incr wno
203 }
204 set profile(Default,windowNumber) $wno
205
206 # These globals describe the current query type. They are set to the
207 # first query type.
208 set queryButtonsFind [lindex $queryButtons 0]
209 set queryInfoFind [lindex $queryInfo 0]
210
211 # Procedure read-formats
212 # Read all Tcl source files in the subdirectory 'formats'.
213 # The name of each source will correspond to a display format.
214 proc read-formats {} {
215     global displayFormats
216     global libdir
217
218     set oldDir [pwd]
219     cd ${libdir}/formats
220     set formats [glob {*.[tT][cC][lL]}]
221     foreach f $formats {
222         if {[file readable $f]} {
223             source $f
224             set l [string length $f]
225             set f [string tolower [string range $f 0 [expr $l - 5]]]
226             lappend displayFormats $f
227         }
228     }
229     cd $oldDir
230 }
231
232 # Procedure set-wrap {m}
233 #  m    boolean wrap mode
234 # Handler to enable/disable text wrap in the main record window
235 proc set-wrap {m} {
236     global textWrap
237
238     set textWrap $m
239     .data.record configure -wrap $m
240 }
241
242 # Procedure dputs {m}
243 #  m    string to be printed
244 # puts utility for debugging.
245 proc dputs {m} {
246     global debugMode
247     if {$debugMode} {
248         puts $m
249     }
250 }
251
252 # Procedure apduDump {}
253 # Logs BER dump of last APDU in window if debugMode is true.
254 proc apduDump {} {
255     global debugMode
256
257     set w .apdu
258
259     if {$debugMode == 0} return
260     set x [z39 apduInfo]
261
262     set offset [lindex $x 1]
263     set length [lindex $x 0]
264
265     if {![winfo exists $w]} {
266         catch {destroy $w}
267         toplevelG $w
268
269         wm title $w "APDU information"       
270         wm minsize $w 0 0
271         
272         top-down-window $w
273         
274         text $w.top.t -font fixed -width 60 -height 12 -wrap word \
275                         -relief flat -borderwidth 0 \
276                         -yscrollcommand [list $w.top.s set] -background grey85
277         scrollbar $w.top.s -command [list $w.top.t yview]
278         pack $w.top.s -side right -fill y
279         pack $w.top.t -expand yes -fill both
280
281         bottom-buttons $w [list {Close} [list destroy $w]] 0
282     }
283     $w.top.t insert end "Length: ${length}\n"
284     if {$offset != -1} {
285         $w.top.t insert end "Offset: ${offset}\n"
286     }
287     $w.top.t insert end [lindex $x 2]
288     $w.top.t insert end "---------------------------------\n"
289
290 }
291
292 # Procedure set-display-format {f}
293 #  f    display format
294 # Reformats main record window to use display format given by f
295 proc set-display-format {f} {
296     global displayFormat setNo busy
297
298     set displayFormat $f
299     if {$setNo == 0} {
300         return
301     }
302     if {!$busy} {
303         .bot.a.status configure -text "Reformatting"
304     }
305     update idletasks
306     add-title-lines -1 10000 1
307 }
308
309 # Procedure initBindings
310 # Disables various default bindings for Text and Listbox widgets.
311 proc initBindings {} {
312     global TextBinding
313
314     foreach e [bind Text] {
315         set TextBinding($e) [bind Text $e]
316         bind Text $e {}
317     }
318     set w Listbox
319     bind $w <B1-Motion> {}
320     bind $w <Shift-B1-Motion> {}
321
322     set w Entry
323 }
324
325 # Procedure TextEditable 
326 # Apply "standard" events to a text widget. It should be editable now.
327 proc TextEditable {w} {
328     global TextBinding
329
330     foreach e [array names TextBinding] {
331         bind $w $e $TextBinding($e)
332     }
333 }
334
335 # Procedure post-menu {wbutton wmenu}
336 #   wbutton    button widget
337 #   wmenu      menu widget
338 # Post menu near button. Note: not used.
339 proc post-menu {wbutton wmenu} {
340     $wmenu activate none
341     focus $wmenu
342     $wmenu post [winfo rootx $wbutton] \
343             [expr [winfo rooty $wbutton]+[winfo height $wbutton]]
344
345 }
346
347 # Procedure destroyGW {w}
348 #   w     top level widget
349 # Saves geometry of widget w in windowGeometry array. This
350 # Procedure is used to save current geometry of a window before
351 # it is destroyed.
352 # See also topLevelG.
353 proc destroyGW {w} {
354     global windowGeometry
355     catch {set windowGeometry($w) [wm geometry $w]}
356 }    
357
358 # Procedure topLevelG
359 #   w     top level widget
360 # Makes a new top level widget named w; sets geometry of window if it 
361 # exists in windowGeometry array. The destroyGW procedure is set 
362 # to be called when the Destroy event occurs.
363 proc toplevelG {w} {
364     global windowGeometry
365
366     toplevel $w
367     if {[info exists windowGeometry($w)]} {
368         set g $windowGeometry($w)
369         if {$g != ""} {
370             wm geometry $w $g
371         }
372     }
373     bind $w <Destroy> [list destroyGW $w]
374 }
375
376 # Procedure top-down-window {w}
377 #  w    window (possibly top level)
378 # Makes two frames inside w called top and bot.
379 proc top-down-window {w} {
380     frame $w.top -relief raised -border 1
381     frame $w.bot -relief raised -border 1
382     pack  $w.top -side top -fill both -expand yes
383     pack  $w.bot -fill both
384 }
385
386 # Procedure top-down-ok-cancel {w ok-action g}
387 #  w          top level widget with $w.bot-frame
388 #  ok-action  ok script
389 #  g          grab flag
390 # Makes two buttons in the bot frame called Ok and Cancel. The
391 # ok-action is executed if Ok is pressed. If Cancel is activated
392 # The window is destroyed. If g is true a grab is performed on the
393 # window and the procedure waits until the window is destroyed.
394 proc top-down-ok-cancel {w ok-action g} {
395     frame $w.bot.left -relief sunken -border 1
396     pack $w.bot.left -side left -expand yes -ipadx 2 -ipady 2 -padx 1 -pady 1
397     button $w.bot.left.ok -width 4 -text {Ok} -command ${ok-action}
398     pack $w.bot.left.ok -expand yes -ipadx 1 -ipady 1 -padx 2 -pady 2
399     button $w.bot.cancel -width 5 -text {Cancel} -command [list destroy $w]
400     pack $w.bot.cancel -side left -expand yes    
401
402     if {$g} {
403         grab $w
404         tkwait window $w
405     }
406 }
407
408 # Procedure bottom-buttons {w buttonList g}
409 #  w          top level widget with $w.bot-frame
410 #  buttonList button specifications
411 #  g          grab flag
412 # Makes a list of buttons in the $w.bot frame. The buttonList is a list 
413 # of button specifications. Each button specification consists of two
414 # items; the first item is button label name; the second item is a script
415 # of be executed when that button is executed. A grab is performed if g 
416 # is true and it waits for the window to be destroyed.
417 proc bottom-buttons {w buttonList g} {
418     set i 0
419     set l [llength $buttonList]
420
421     frame $w.bot.$i -relief sunken -border 1
422     pack $w.bot.$i -side left -expand yes -padx 2 -pady 2
423     button $w.bot.$i.ok -text [lindex $buttonList $i] \
424                 -command [lindex $buttonList [expr $i+1]]
425     pack $w.bot.$i.ok -expand yes -padx 2 -pady 2 -side left
426
427     incr i 2
428     while {$i < $l} {
429         button $w.bot.$i -text [lindex $buttonList $i] \
430                 -command [lindex $buttonList [expr $i+1]]
431         pack $w.bot.$i -expand yes -padx 2 -pady 2 -side left
432         incr i 2
433     }
434     if {$g} {
435         # Grab ...
436         grab $w
437         tkwait window $w
438     }
439 }
440
441 # Procedure cancel-operation
442 # This handler is invoked when the user wishes to cancel an operation.
443 # If the system is currently busy a "Cancel" will be displayed in the
444 # status area and the cancelFlag is set to true indicating that future
445 # responses from the target should be ignored. The system is no longer
446 # busy when this procedure exists.
447 proc cancel-operation {} {
448     global cancelFlag busy delayRequest
449
450     if {$busy} {
451         set cancelFlag 1
452         set delayRequest {}
453         show-status Cancel 0 1
454     }
455 }
456
457 # Procedure show-target {target base}
458 #  target     name of target
459 #  base       name of database
460 # Displays target name and database name in the target status area.
461 proc show-target {target base} {
462     if {![string length $target]} {
463         .bot.a.target configure -text {}
464         return
465     }
466     if {![string length $base]} {
467                 .bot.a.target configure -text "$target"
468     } else {
469          .bot.a.target configure -text "$target - $base"
470     }
471 }
472
473 # Procedure show-logo {v1}
474 #  v1    integer level
475 # This procedure maintains the book logo in the bottom of the screen.
476 # It is invoked only once during initialization of windows, etc., and
477 # by itself. The global 'busy' variable determines whether the logo is
478 # moving or not.
479 proc show-logo {v1} {
480     global busy libdir
481
482     if {$busy != 0} {
483         incr v1
484         if {$v1==10} {
485             set v1 1
486         }
487         .bot.logo configure -bitmap @${libdir}/bitmaps/book${v1}
488         after 140 [list show-logo $v1]
489         return
490     }
491     while {1} {
492         .bot.logo configure -bitmap @${libdir}/bitmaps/book1
493         tkwait variable busy
494         if {$busy} {
495             show-logo 1
496             return
497         }
498     }
499 }
500
501 # Procedure show-status {status b sb}
502 #  status     status message string
503 #  b          busy indicator
504 #  sb         search busy indicator
505 # Display status information according to 'status' and sets the global
506 # busy flag 'busy' to b if b is non-empty. If sb is non-empty it indicates
507 # whether service buttons should be enabled or disabled.
508 proc show-status {status b sb} {
509     global busy scanEnable setOffset setMax setNo
510
511     .bot.a.status configure -text "$status"
512     if {$b == 1} {
513         if {$busy == 0} {set busy 1}
514     } else {
515         set busy 0
516     }
517     if {$sb == {}} {
518         return
519     }
520     if {$sb} {
521         .top.service configure -state normal
522         .mid.search configure -state normal
523         if {$scanEnable} {
524             .mid.scan configure -state normal
525         } else {
526             configure-disable-e .top.service.m 3
527         }
528         if {$setNo == 0} {
529             configure-disable-e .top.service.m 1
530         } elseif {[z39.$setNo nextResultSetPosition] > 0 && 
531             [z39.$setNo nextResultSetPosition] <= [z39.$setNo resultCount]} {
532             configure-enable-e .top.service.m 1
533             .mid.present configure -state normal
534         } else {
535             configure-disable-e .top.service.m 1
536             .mid.present configure -state disabled
537         }
538         if {[winfo exists .scan-window]} {
539             .scan-window.bot.2 configure -state normal
540             .scan-window.bot.4 configure -state normal
541         }
542     } else {
543         .top.service configure -state disabled
544         .mid.search configure -state disabled
545         .mid.scan configure -state disabled
546         .mid.present configure -state disabled
547
548         if {[winfo exists .scan-window]} {
549             .scan-window.bot.2 configure -state disabled
550             .scan-window.bot.4 configure -state disabled
551         }
552     }
553 }
554
555 # Procedure show-message {msg}
556 #  msg    message string
557 # Sets message the bottom of the screen to msg.
558 proc show-message {msg} {
559     .bot.a.message configure -text "$msg"
560 }
561
562 # Procedure insertWithTags {w text args}
563 #  w      text widget
564 #  text   string to be inserted
565 #  args   list of tags
566 # Inserts text at the insertion point in widget w. The text is tagged 
567 # with the tags in args.
568 proc insertWithTags {w text args} {
569     set start [$w index insert]
570     $w insert insert $text
571     foreach tag [$w tag names $start] {
572         $w tag remove $tag $start insert
573     }
574     foreach i $args {
575         $w tag add $i $start insert
576     }
577 }
578
579 # Procedure popup-license and displays LICENSE information.
580 proc popup-license {} {
581     global libdir
582     set w .popup-license
583     toplevel $w
584
585     wm title $w "License" 
586     wm minsize $w 0 0
587
588     top-down-window $w
589
590     text $w.top.t -width 80 -height 10 -wrap word -relief flat -borderwidth 0 \
591         -font fixed -yscrollcommand [list $w.top.s set]
592     scrollbar $w.top.s -command [list $w.top.t yview]
593     pack $w.top.s -side right -fill y
594     pack $w.top.t -expand yes -fill both
595
596     if {[file readable "${libdir}/LICENSE"]} {
597         set f [open "${libdir}/LICENSE" r]
598         while {[gets $f buf] != -1} {
599             $w.top.t insert end $buf
600             $w.top.t insert end "\n"
601         } 
602         close $f
603     }
604     bottom-buttons $w [list {Close} [list destroy $w]] 1
605 }
606
607 # Procedure about-target
608 # Displays various information about the current target, such
609 # as implementation-name, implementation-id, etc.
610 proc about-target {} {
611     set w .about-target-w
612     global hostid font
613
614     toplevel $w
615
616     wm title $w "About target"
617     place-force $w .
618     top-down-window $w
619
620     frame $w.top.a -relief ridge -border 2
621     frame $w.top.p -relief ridge -border 2
622     pack $w.top.a $w.top.p -side top -fill x
623
624     label $w.top.a.about -text "About"
625     label $w.top.a.irtcl -text $hostid -font $font(bb,bold)
626     pack $w.top.a.about $w.top.a.irtcl -side top
627
628     set i [z39 targetImplementationName]
629     label $w.top.p.in -text "Implementation name: $i"
630     set i [z39 targetImplementationId]
631     label $w.top.p.ii -text "Implementation id: $i"
632     set i [z39 targetImplementationVersion]
633     label $w.top.p.iv -text "Implementation version: $i"
634     set i [z39 options]
635     label $w.top.p.op -text "Protocol options: $i"
636     pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.op -side top -anchor nw
637
638     bottom-buttons $w [list {Close} [list destroy $w]] 1
639 }
640
641 # Procedure about-origin-logo {n}
642 #   n    integer level
643 # Displays book logo in the .about-origin-w widget
644 proc about-origin-logo {n} {
645     global libdir
646     set w .about-origin-w
647     if {![winfo exists $w]} {
648         return
649     }
650     incr n
651     if {$n==10} {
652         set n 1
653     }
654     $w.top.a.logo configure -bitmap @${libdir}/bitmaps/book$n
655     after 140 [list about-origin-logo $n]
656 }
657
658 # Procedure about-origin
659 # Display various information about origin (this client).
660 proc about-origin {} {
661     set w .about-origin-w
662     global libdir font tk_version
663     
664     if {[winfo exists $w]} {
665         destroy $w
666     }
667     toplevel $w
668
669     wm title $w "About IrTcl"
670     place-force $w .
671     top-down-window $w
672
673     frame $w.top.a -relief ridge -border 2
674     frame $w.top.p -relief ridge -border 2
675     pack $w.top.a $w.top.p -side top -fill x
676     
677     label $w.top.a.irtcl -text "IrTcl" -font $font(bb,bold)
678     label $w.top.a.logo -bitmap @${libdir}/bitmaps/book1 
679     pack $w.top.a.irtcl $w.top.a.logo -side left -expand yes
680
681     set i unknown
682     catch {set i [z39 implementationName]}
683     label $w.top.p.in -text "Implementation name: $i"
684     catch {set i [z39 implementationId]}
685     label $w.top.p.ii -text "Implementation id: $i"
686     catch {set i [z39 implementationVersion]}
687     label $w.top.p.iv -text "Implementation version: $i"
688     set i $tk_version
689     label $w.top.p.tk -text "Tk version: $i"
690     pack $w.top.p.in $w.top.p.ii $w.top.p.iv $w.top.p.tk -side top -anchor nw
691
692     about-origin-logo 1
693     bottom-buttons $w [list {Close} [list destroy $w] \
694                             {License} [list popup-license]] 0
695 }
696
697 # Procedure popup-marc {sno no b df}
698 #  sno     result set number
699 #  no      record position number
700 #  b       popup window number
701 #  df      display format
702 # Displays record in set $sno at position $no in window .full-marc$b.
703 # The global variable $popupMarcdf holds the current format method.
704 proc popup-marc {sno no b df} {
705     global font displayFormats popupMarcdf
706
707     if {[z39.$sno type $no] != "DB"} {
708         return
709     }
710     if {$b == -1} {
711         set b 0
712         while {[winfo exists .full-marc$b]} {
713             incr b
714         }
715     }
716     set df $popupMarcdf
717     set w .full-marc$b
718     if {![winfo exists $w]} {
719         toplevelG $w
720
721         wm minsize $w 0 0
722         
723         frame $w.top -relief raised -border 1
724         frame $w.bot -relief raised -border 1
725         pack  $w.top -side top -fill both -expand yes
726         pack  $w.bot -fill both
727
728         text $w.top.record -width 60 -height 5 -wrap word -relief flat \
729             -borderwidth 0 -font fixed \
730             -yscrollcommand [list $w.top.s set] -background grey85
731         scrollbar $w.top.s -command [list $w.top.record yview] 
732         $w.top.record tag configure marc-tag -foreground blue
733         $w.top.record tag configure marc-id -foreground red
734         $w.top.record tag configure marc-data -foreground black
735         $w.top.record tag configure marc-head -font $font(n,bold) \
736                 -background black -foreground white
737         $w.top.record tag configure marc-pref -font $font(n,normal) -foreground blue
738         $w.top.record tag configure marc-text -font $font(n,normal) -foreground black
739         $w.top.record tag configure marc-it -font $font(n,normal) -foreground black
740
741         pack $w.top.s -side right -fill y
742         pack $w.top.record -expand yes -fill both
743         
744         bottom-buttons $w [list \
745             {Close} [list destroy $w] \
746             {Prev} {} \
747             {Next} {} \
748             {Duplicate} {}] 0
749         menubutton $w.bot.formats -text "Format" -menu $w.bot.formats.m -relief raised
750         irmenu $w.bot.formats.m
751         pack $w.bot.formats -expand yes -ipadx 2 -ipady 2 -padx 3 -pady 3 -side left
752     } else {
753         $w.bot.formats.m delete 0 last
754     }
755     set i 0
756     foreach f $displayFormats {
757         $w.bot.formats.m add radiobutton -label $f -variable popupMarcdf -value $i \
758                 -command [list popup-marc $sno $no $b 0]
759         incr i
760     }
761     $w.top.record delete 0.0 end
762     set recordType [z39.$sno recordType $no]
763     wm title $w "$recordType record #$no"
764
765     $w.bot.2 configure -command [list popup-marc $sno [expr $no-1] $b $df]
766     $w.bot.4 configure -command [list popup-marc $sno [expr $no+1] $b $df]
767     if {$no == 1} {
768         $w.bot.2 configure -state disabled
769     } else {
770         $w.bot.2 configure -state normal
771     }
772     if {[z39.$sno type [expr $no+1]] != "DB"} {
773         $w.bot.4 configure -state disabled
774     } else {
775         $w.bot.4 configure -state normal
776     }
777     $w.bot.6 configure -command [list popup-marc $sno $no -1 0]
778     set ffunc [lindex $displayFormats $df]
779     set ffunc "display-$ffunc"
780
781     $ffunc $sno $no $w.top.record 0
782 }
783
784 # Procedure update-target-hotlist {target base}
785 #  target     current target name
786 #  base       current database name
787 # Updates the global $hotTargets so that $target and $base are
788 # moved to the front, i.e. they become the number 1 target/base.
789 # The target menu is updated by a call to set-target-hotlist.
790 proc update-target-hotlist {target base} {
791     global hotTargets
792
793     set olen [llength $hotTargets]
794     set i 0
795     foreach e $hotTargets {
796         if {$target == [lindex $e 0] && $base == [lindex $e 1]} {
797             set hotTargets [lreplace $hotTargets $i $i]
798             break
799         }
800         incr i    
801     }
802     set hotTargets [linsert $hotTargets 0 [list $target $base]]
803     set-target-hotlist $olen
804
805
806 # Procedure delete-target-hotlist {target}
807 #  target    target to be deleted
808 # Updates the global $hotTargets so that $target is removed.
809 # The target menu is updated by a call to set-target-hotlist.
810 proc delete-target-hotlist {target} {
811     global hotTargets
812
813     set olen [llength $hotTargets]
814     set i 0
815     foreach e $hotTargets {
816         if {$target == [lindex $e 0]} {
817             set hotTargets [lreplace $hotTargets $i $i]
818         }
819         incr i
820     }
821     set-target-hotlist $olen
822 }
823
824 # Procedure set-target-hotlist {olen}
825 #  olen     number of hot target entries to be deleted from menu
826 # Updates the target menu with the targets with the first 8 entries
827 # in the $hotTargets global.
828 proc set-target-hotlist {olen} {
829     global hotTargets
830    
831     if {$olen > 0} {
832        .top.target.m delete 6 [expr 6+$olen]
833     }
834     set i 1
835     foreach e $hotTargets {
836         set target [lindex $e 0]
837         set base [lindex $e 1]
838         if {![string length $base]} {
839             .top.target.m add command -label "$i $target" -command \
840                 [list reopen-target $target {}]
841         } else {
842             .top.target.m add command -label "$i $target - $base" -command \
843                 [list reopen-target $target $base]
844         }
845         incr i
846         if {$i > 8} {
847              break
848         }
849     }
850 }
851
852 # Procedure reopen-target {target base}
853 #  target    target to be opened
854 #  base      base to be used
855 # Closes connection with current target and opens a new connection
856 # with $target and database $base.
857 proc reopen-target {target base} {
858     close-target
859     open-target $target $base
860     update-target-hotlist $target $base
861 }
862
863 # Procedure define-target-action
864 # Prepares the setup of a new target. The name of the target
865 # is read from the dialog .target-define dialog (procedure
866 # define-target-dialog) and the target definition window is displayed by
867 # a call to protocol-setup.
868 proc define-target-action {} {
869     global profile
870     
871     set target [.target-define.top.target.entry get]
872     if {![string length $target]} {
873         return
874     }
875     foreach n [array names profile *,host] {
876         if {![string compare $n ${target},host]} {
877             destroy .target-define
878             protocol-setup $n
879             return
880         }
881     }
882     foreach n [array names profile Default,*] {
883         set profile($target,[string range $n 8 end]) $profile($n)
884
885     }
886     incr profile(Default,windowNumber)
887     
888     protocol-setup $target
889     destroy .target-define
890 }
891
892 # Procedure fail-response {target}
893 #  target   current target
894 # Error handler (IrTcl failback) that takes care of serious protocol
895 # errors, connection lost, etc.
896 proc fail-response {target} {
897     global debugMode
898
899     set c [lindex [z39 failInfo] 0]
900     set m [lindex [z39 failInfo] 1]
901     if {$c == 4 || $c == 5} {
902         set debugMode 1        
903         apduDump
904     }
905     close-target
906     tkerror "$m ($c)"
907 }
908
909 # Procedure connect-response {target base}
910 #  target   current target
911 #  base     current database
912 # IrTcl connect response handler.
913 proc connect-response {target base} {
914     dputs "connect-response"
915     init-request $target $base
916 }
917
918 # Procedure open-target {target base}
919 #  target   target to be opened
920 #  base     database to be used
921 # Opens a new connection with $target/$base.
922 proc open-target {target base} {
923     global profile hostid presentChunk currentDb
924
925     z39 disconnect
926     z39 comstack $profile($target,comstack)
927     z39 protocol $profile($target,protocol)
928     eval z39 idAuthentication $profile($target,authentication)
929     z39 maximumRecordSize $profile($target,maximumRecordSize)
930     z39 preferredMessageSize $profile($target,preferredMessageSize)
931     dputs "maximumRecordSize=[z39 maximumRecordSize]"
932     dputs "preferredMessageSize=[z39 preferredMessageSize]"
933     show-status Connecting 1 0
934     set x $profile($target,largeSetLowerBound)
935     if {![string length $x]} {
936         set x 2
937     }
938     z39 largeSetLowerBound $x
939     
940     set x $profile($target,smallSetUpperBound)
941     if {![string length $x]} {
942         set x 0
943     }
944     z39 smallSetUpperBound $x
945     
946     set x $profile($target,mediumSetPresentNumber)
947     if {![string length $x]} {
948         set x 0
949     }
950     z39 mediumSetPresentNumber $x
951
952     set presentChunk $profile($target,presentChunk)
953     if {![string length $presentChunk]} {
954         set presentChunk 4
955     }
956
957     z39 failback [list fail-response $target]
958     z39 callback [list connect-response $target $base]
959     show-target $target $base
960     update idletasks
961     set err [catch {
962         z39 connect $profile($target,host):$profile($target,port)
963     } errorMessage]
964     if {$err} {
965         set hostid Default
966         tkerror $errorMessage
967         show-status "Not connected" 0 {}
968         show-target {} {}
969         return
970     }
971     set hostid $target
972     set currentDb $base
973     configure-disable-e .top.target.m 0
974     configure-enable-e .top.target.m 1
975     configure-enable-e .top.target.m 2
976 }
977
978 # Procedure close-target
979 # Shuts down the connection with current target.
980 proc close-target {} {
981     global hostid cancelFlag setNo setNoLast currentDb
982
983     set cancelFlag 0
984     set setNo 0
985     set setNoLast 0
986     .bot.a.set configure -text ""
987     set hostid Default
988     set currentDb Default
989     z39 disconnect
990     show-target {} {}
991     show-status {Not connected} 0 0
992     .top.options.m.query.slist entryconfigure 2 -state disabled
993     init-title-lines
994     show-message {}
995     configure-disable-e .top.target.m 1
996     configure-disable-e .top.target.m 2
997     .top.rset.m delete 1 last
998     .top.rset.m add separator
999     configure-enable-e .top.target.m 0
1000 }
1001
1002 # Procedure load-set-action
1003 # Loads records from a file. The filename is read from the entry
1004 # .load-set.filename.entry (see function load-set)
1005 proc load-set-action {} {
1006     global setNoLast
1007
1008     incr setNoLast
1009     ir-set z39.$setNoLast z39
1010
1011     set fname [.load-set.top.filename.entry get]
1012     destroy .load-set
1013     if {$fname != ""} {
1014         show-status Loading 1 {}
1015         update
1016         z39.$setNoLast loadFile $fname
1017
1018         set no [z39.$setNoLast numberOfRecordsReturned]
1019         add-title-lines $setNoLast $no 1
1020     }
1021     set l [format "%-4d %7d" $setNoLast $no]
1022     .top.rset.m add command -label $l \
1023             -command [list add-title-lines $setNoLast 10000 1]
1024     show-status Ready 0 {}
1025 }
1026
1027 # Procedure load-set
1028 # Dialog that asks for a filename with records to be loaded
1029 # into a result set.
1030 proc load-set {} {
1031     set w .load-set
1032     toplevel $w
1033     set oldFocus [focus]
1034     place-force $w .
1035     top-down-window $w
1036
1037     frame $w.top.filename
1038     pack $w.top.filename -side top -anchor e -pady 2
1039     
1040     entry-fields $w.top {filename} \
1041             {{Filename:}} \
1042             {load-set-action} {destroy .load-set}
1043     
1044     top-down-ok-cancel $w {load-set-action} 1
1045     focus $oldFocus
1046 }
1047
1048 # Procedure init-request
1049 # Sends an initialize request to the target. This procedure is called
1050 # when a connect has been established.
1051 proc init-request {target base} {
1052     global cancelFlag
1053
1054     if {$cancelFlag} {
1055         close-target
1056         return
1057     }
1058     z39 callback [list init-response $target $base]
1059     show-status Initializing 1 {}
1060     set err [catch {z39 init} errorMessage]
1061     if {$err} {
1062         tkerror $errorMessage
1063         show-status Ready 0 {}
1064     }
1065 }
1066
1067 # Procedure init-response
1068 # Handles and incoming init-response. The service buttons
1069 # are enabled. The global $scanEnable indicates whether the target
1070 # supports scan.
1071 proc init-response {target base} {
1072     global cancelFlag profile scanEnable settingsChanged
1073
1074     dputs {init-response}
1075     apduDump
1076     if {$cancelFlag} {
1077         close-target
1078         return
1079     }
1080     if {![z39 initResult]} {
1081         set u [z39 userInformationField]
1082         close-target
1083         tkerror "Connection rejected by target: $u"
1084     } else {
1085                 z39 failback [list explain-crash $target $base]
1086         explain-check $target [list ready-response $base] $base
1087     }
1088 }
1089
1090 # Procedure explain-crash
1091 # Handles target that dies during explain.
1092 proc explain-crash {target base} {
1093     global profile settingsChanged
1094     
1095     set profile($target,timeLastInit) [clock seconds]
1096     set settingsChanged 1
1097
1098     show-message {}
1099     open-target $target $base
1100 }
1101
1102 # Procedure explain-check 
1103 # Stub function to check explain. May be overwritten later.
1104 #proc explain-check {target response} 
1105 #    eval $response [list $target]
1106
1107
1108 # Procedure ready-response
1109 # Called after a target has been initialized and, possibly, explained
1110 proc ready-response {base target} {
1111     global profile settingsChanged scanEnable queryAuto
1112     
1113     z39 failback [list fail-response $target]
1114     if {[string length $base]} {
1115         set profile($target,timeLastInit) [clock seconds]
1116         set settingsChanged 1
1117
1118         z39 databaseNames $base
1119         cascade-dblist $target $base
1120         show-target $target $base
1121     }
1122     if {[lsearch [z39 options] scan] >= 0} {
1123         set scanEnable 1
1124     } else {
1125         set scanEnable 0
1126     }
1127     .data.record delete 1.0 end
1128     set desc [string trim $profile($target,description)]
1129     if {[string length $desc]} {
1130         .data.record insert end "$desc\n\n"
1131     } else {
1132         .data.record insert end "$target\n\n"
1133     }
1134     set data [string trim $profile($target,welcomeMessage)]
1135     if {[string length $data]} {
1136                 .data.record insert end "Welcome Message:\n$data\n\n"
1137     }
1138     set data [string trim $profile($target,recentNews)]
1139     if {[string length $data]} {
1140         .data.record insert end "News:\n$data\n"
1141     }
1142     ready-response-actions $target $base
1143     show-message {}
1144     show-status Ready 0 1
1145 }
1146
1147 #proc ready-response-actions {target base}
1148 #This procedure take care of all the actions that should start if connect is succesfull.
1149 proc ready-response-actions {target base} {
1150         global profile queryAuto
1151 #       get-attributeDetails $target $base
1152         changeQueryButtons $target $base 
1153         configureOptionsSyntax $target $base
1154         if {[info exists profile($target,AttributeDetails,$base,Bib1Use)] && $queryAuto == 1} {
1155                 changeQueryButtons $target $base 
1156                 change-queryInfo $target $base
1157                 query-select 2
1158                 .top.options.m.query.slist entryconfigure 2 -state normal
1159         } else {
1160                 query-select 0
1161                 .top.options.m.query.slist entryconfigure 2 -state disabled
1162         }
1163 }
1164
1165 # Procedure search-request
1166 #  bflag     flag to indicate if this procedure calls itself
1167 # Performs a search. If $busy is 1, the search-request is performed
1168 # at a later time (when another response arrives). This procedure
1169 # sets many search-related Z39-settings. The global $setNo is set
1170 # to the result set number (z39.$setNo).
1171 proc search-request {bflag} {
1172     global setNo setNoLast profile hostid busy cancelFlag delayRequest recordSyntax elementSetNames
1173
1174     set target $hostid
1175     
1176     if {![string length [z39 connect]]} {
1177         return
1178     }
1179     dputs "search-request"
1180     show-message {}
1181     if {!$bflag && $busy} {
1182         dputs "busy: search-request ignored"
1183         return
1184     }
1185     if {$cancelFlag} {
1186         dputs "cancelFlag"
1187         show-status Searching 1 0
1188         set delayRequest {search-request 1}
1189         return
1190     }
1191     set delayRequest {} 
1192
1193     set query [index-query]
1194     if {![string length $query]} {
1195         return
1196     }
1197     incr setNoLast
1198     set setNo $setNoLast
1199     ir-set z39.$setNo z39
1200     
1201     if {$profile($target,namedResultSets)} {
1202         z39.$setNo setName $setNo
1203         dputs "setName=${setNo}"
1204     } else {
1205         z39.$setNo setName default
1206         dputs "setName=default"
1207     }
1208     if {$profile($target,queryRPN)} {
1209                 z39.$setNo queryType rpn
1210     } elseif {$profile($target,queryCCL)} {
1211                 z39.$setNo queryType ccl
1212     }
1213     dputs Setting
1214     dputs $recordSyntax
1215     if {![string compare $recordSyntax None]} {
1216         z39.$setNo preferredRecordSyntax {}
1217     } else {
1218         z39.$setNo preferredRecordSyntax $recordSyntax
1219     }
1220     if {![string compare $elementSetNames None]} {
1221         z39.$setNo elementSetNames {}
1222         z39.$setNo smallSetElementSetNames {}
1223         z39.$setNo mediumSetElementSetNames {}
1224     } else {
1225         z39.$setNo elementSetNames $elementSetNames
1226         z39.$setNo smallSetElementSetNames $elementSetNames
1227         z39.$setNo mediumSetElementSetNames $elementSetNames
1228     }
1229     z39 callback {search-response}
1230     z39.$setNo search $query
1231     show-status Searching 1 0
1232 }
1233
1234 # Procedure scan-copy {y entry}
1235 #  y       y-position of mouse pointer
1236 #  entry   a search entry in the top
1237 # Copies the term in the list nearest $y to the query entry specified
1238 # by $entry
1239 proc scan-copy {y entry} {
1240     set w .scan-window
1241     set no [$w.top.list nearest $y]
1242     dputs "no=$no"
1243     .lines.$entry.e delete 0 end
1244     .lines.$entry.e insert 0 [string range [$w.top.list get $no] 8 end]
1245 }
1246
1247 # Procedure scan-request
1248 # Performs a scan on term "0" with the current attributes in entry
1249 # specified by the global $curIndexEntry.
1250 proc scan-request {} {
1251     set w .scan-window
1252
1253     global profile hostid scanView scanTerm curIndexEntry queryButtonsFind \
1254                 queryInfoFind cancelFlag delayRequest
1255
1256     dputs "scan-request"
1257     if {$cancelFlag} {
1258         dputs "cancelFlag"
1259         show-status Scanning 1 0
1260         set delayRequest scan-request
1261         return
1262     }
1263     set delayRequest {} 
1264     set target $hostid
1265     set scanView 0
1266     set scanTerm {}
1267     set b [lindex $queryButtonsFind $curIndexEntry]
1268     set attr {}
1269     foreach a [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end] {
1270         set attr "@attr $a $attr"
1271     }
1272     set title [lindex [lindex $queryInfoFind [lindex $b 1]] 0]
1273     ir-scan z39.scan z39
1274
1275     if {![winfo exists $w]} {
1276         toplevelG $w
1277         
1278         wm minsize $w 0 0
1279
1280         top-down-window $w
1281
1282         entry $w.top.entry -relief sunken 
1283         pack $w.top.entry -fill x -padx 4 -pady 2
1284         bind $w.top.entry <KeyRelease> [list scan-term-h $attr]
1285         listbox $w.top.list -yscrollcommand [list $w.top.scroll set] -font fixed 
1286         scrollbar $w.top.scroll -orient vertical -border 1
1287         pack $w.top.list -side left -fill both -expand yes
1288         pack $w.top.scroll -side right -fill y
1289         $w.top.scroll config -command [list $w.top.list yview]
1290         
1291         bottom-buttons $w [list {Close} [list destroy $w] \
1292                 {Up} [list scan-up $attr] \
1293                 {Down} [list scan-down $attr]] 0
1294         bind $w.top.list <Up> [list scan-up $attr]
1295         bind $w.top.list <Down> [list scan-down $attr]
1296         focus $w.top.entry
1297     }
1298     bind $w.top.list <Double-Button-1> [list scan-copy %y $curIndexEntry]
1299     wm title $w "Scan $title"
1300         
1301     z39 callback [list scan-response $attr 0 35]
1302     z39.scan numberOfTermsRequested 5
1303     z39.scan preferredPositionInResponse 1
1304     z39.scan scan "${attr} 0"
1305     
1306     show-status Scanning 1 0
1307 }
1308
1309 # Procedure scan-term-h {attr} 
1310 # attr    attribute specification
1311 # This procedure is called whenever a key is released in the entry in the
1312 # scan window (.scan-window). A scan is then initiated with the new contents
1313 # of the entry as the starting term.
1314 proc scan-term-h {attr} {
1315     global busy scanTerm
1316
1317     if {$busy} {
1318         return
1319     }
1320     set w .scan-window
1321     set nScanTerm [$w.top.entry get]
1322     if {$nScanTerm == $scanTerm} {
1323         return
1324     }
1325     set scanTerm $nScanTerm
1326     z39 callback [list scan-response $attr 0 35]
1327     z39.scan numberOfTermsRequested 5
1328     z39.scan preferredPositionInResponse 1
1329     dputs "${attr} \{${scanTerm}\}"
1330     if {![string length $scanTerm]} {
1331         z39.scan scan "${attr} 0"
1332     } else {
1333         z39.scan scan "${attr} \{${scanTerm}\}"
1334     }
1335     show-status Scanning 1 0
1336 }
1337
1338 # Procedure scan-response {attr start toget}
1339 #  attr   attribute specification
1340 #  start  position of first term in the response
1341 #  toget  number of total terms to get
1342 # This procedure handles all scan-responses. $start specifies the list
1343 # entry number of the first incoming term. The $toget indicates the total
1344 # number of terms to be retrieved from the target. The $toget may be
1345 # negative in which case, scan is performed 'backwards' (- $toget is
1346 # the total number of terms in this case). This procedure usually calls
1347 # itself several times in order to get small scan-term-list chunks.
1348 proc scan-response {attr start toget} {
1349     global cancelFlag delayRequest scanTerm scanView
1350
1351     set w .scan-window
1352     dputs "In scan-response"
1353     apduDump
1354     set m [z39.scan numberOfEntriesReturned]
1355     dputs $m
1356     dputs attr=$attr
1357     dputs start=$start
1358     dputs toget=$toget
1359
1360     if {![winfo exists .scan-window]} {
1361         if {$cancelFlag} {
1362             set cancelFlag 0
1363             dputs "Handling cancel"
1364             if {$delayRequest != ""} {
1365                 eval $delayRequest
1366             }
1367             return
1368         }
1369         show-status Ready 0 1
1370         return
1371     }
1372     set nScanTerm [$w.top.entry get]
1373     if {$nScanTerm != $scanTerm} {
1374         z39 callback [list scan-response $attr 0 35]
1375         z39.scan numberOfTermsRequested 5
1376         z39.scan preferredPositionInResponse 1
1377         set scanTerm $nScanTerm
1378         dputs "${attr} \{${scanTerm}\}"
1379         if {![string length $scanTerm]} {
1380             z39.scan scan "${attr} 0"
1381         } else {
1382             z39.scan scan "${attr} \{${scanTerm}\}"
1383         }
1384         show-status Scanning 1 0
1385         return
1386     }
1387     set status [z39.scan scanStatus]
1388     if {$status == 6} {
1389         tkerror "Scan fail"
1390         show-status Ready 0 1
1391         set cancelFlag 0
1392         return
1393     }
1394     if {$toget < 0} {
1395         for {set i 0} {$i < $m} {incr i} {
1396             set term [lindex [z39.scan scanLine $i] 1]
1397             set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1398             $w.top.list insert $i "$nostr $term"
1399         }
1400         incr scanView $m
1401         $w.top.list yview $scanView
1402     } else {
1403         $w.top.list delete $start end
1404         for {set i 0} {$i < $m} {incr i} {
1405             set term [lindex [z39.scan scanLine $i] 1]
1406             set nostr [format " %-6d" [lindex [z39.scan scanLine $i] 2]]
1407             $w.top.list insert end "$nostr $term"
1408         }
1409     }
1410     if {$cancelFlag} {
1411         dputs "Handling cancel"
1412         set cancelFlag 0
1413         if {$delayRequest != ""} {
1414             eval $delayRequest
1415         }
1416         return
1417     }
1418     set delayRequest {}
1419     if {$toget > 0 && $m > 1 && $m < $toget} {
1420         set ntoget [expr $toget - $m + 1]
1421         dputs ntoget=$ntoget
1422         z39 callback [list scan-response $attr [expr $start + $m - 1] $ntoget]
1423         set q $term
1424         dputs "down continue: $q"
1425         if {$ntoget > 10} {
1426             z39.scan numberOfTermsRequested 10
1427         } else {
1428             z39.scan numberOfTermsRequested $ntoget
1429         }
1430         z39.scan preferredPositionInResponse 1
1431         dputs "${attr} \{$q\}"
1432         z39.scan scan "${attr} \{$q\}"
1433         return
1434     }
1435     if {$toget < 0 && $m > 1 && $m < [expr - $toget]} {
1436         set ntoget [expr - $toget - $m]
1437         dputs ntoget=$ntoget
1438         z39 callback [list scan-response $attr 0 -$ntoget]
1439         set q [string range [$w.top.list get 0] 8 end]
1440         dputs "up continue: $q"
1441         if {$ntoget > 10} {
1442             z39.scan numberOfTermsRequested 10
1443             z39.scan preferredPositionInResponse 11
1444         } else {
1445             z39.scan numberOfTermsRequested $ntoget
1446             z39.scan preferredPositionInResponse [incr ntoget]
1447         }
1448         dputs "${attr} \{$q\}"
1449         z39.scan scan "${attr} \{$q\}"
1450         return
1451     }
1452     show-status Ready 0 1
1453 }
1454
1455 # Procedure scan-down {attr}
1456 #  attr   attribute specification
1457 # This procedure is called when the user hits the Down button the scan
1458 # window. A new scan is initiated with a positive $toget passed to the
1459 # scan-response handler.
1460 proc scan-down {attr} {
1461     global scanView cancelFlag delayRequest
1462
1463     dputs {scan-down}
1464     if {$cancelFlag} {
1465         dputs "cancelFlag"
1466         show-status {Scanning down} 1 0
1467         set delayRequest [list scan-down $attr]
1468         return
1469     }
1470     set delayRequest {} 
1471
1472     set w .scan-window
1473     set scanView [expr $scanView + 5]
1474     set s [$w.top.list size]
1475     if {$scanView > $s} {
1476         z39 callback [list scan-response $attr [expr $s - 1] 25]
1477         set q [string range [$w.top.list get [expr $s - 1]] 8 end]
1478         dputs "down: $q"
1479         z39.scan numberOfTermsRequested 10
1480         z39.scan preferredPositionInResponse 1
1481         show-status Scanning 1 0
1482         dputs "${attr} \{$q\}"
1483         z39.scan scan "${attr} \{$q\}"
1484         return
1485     }
1486     $w.top.list yview $scanView
1487 }
1488
1489 # Procedure scan-up {attr}
1490 #  attr   attribute specification
1491 # This procedure is called when the user hits the Up button the scan
1492 # window. A new scan is initiated with a negative $toget passed to the
1493 # scan-response handler.
1494 proc scan-up {attr} {
1495     global scanView cancelFlag delayRequest
1496
1497     dputs {scan-up}
1498     if {$cancelFlag} {
1499         dputs "cancelFlag"
1500         show-status Scanning 1 0
1501         set delayRequest [list scan-up $attr]
1502         return
1503     }
1504     set delayRequest {} 
1505
1506     set w .scan-window
1507     set scanView [expr $scanView - 5]
1508     if {$scanView < 0} {
1509         z39 callback [list scan-response $attr 0 -25]
1510         set q [string range [$w.top.list get 0] 8 end]
1511         dputs "up: $q"
1512         z39.scan numberOfTermsRequested 10
1513         z39.scan preferredPositionInResponse 11
1514         show-status Scanning 1 0
1515         z39.scan scan "${attr} \{$q\}"
1516         return
1517     }
1518     $w.top.list yview $scanView
1519 }
1520
1521 # Procedure search-response
1522 # This procedure handles search-responses. If the search is successful
1523 # this procedure will try to retrieve a total of 20 records from the target;
1524 # however not more than $presentChunk records at a time. This procedure
1525 # affects the following globals:
1526 #   $setOffset        current record position offset
1527 #   $setMax           total number of records to be retrieved
1528 proc search-response {} {
1529     global setNo setOffset setMax cancelFlag busy delayRequest presentChunk
1530
1531     apduDump
1532     dputs "In search-response"
1533     if {$cancelFlag} {
1534         dputs "Handling cancel"
1535         set cancelFlag 0
1536         if {$delayRequest != ""} {
1537             eval $delayRequest
1538         }
1539         return
1540     }
1541     set setOffset 0
1542     set delayRequest {}
1543     init-title-lines
1544     set setMax [z39.$setNo resultCount]
1545     show-status Ready 0 1
1546     set status [z39.$setNo responseStatus]
1547     if {![string compare [lindex $status 0] NSD]} {
1548         z39.$setNo nextResultSetPosition 0
1549         set code [lindex $status 1]
1550         set msg [lindex $status 2]
1551         set addinfo [lindex $status 3]
1552         tkerror "NSD$code: $msg: $addinfo"
1553         return
1554     }
1555     show-message "${setMax} hits"
1556     if {$setMax == 0} {
1557         return
1558     }
1559     set setOffset 1
1560     show-status Ready 0 1
1561     set l [format "%-4d %7d" $setNo $setMax]
1562     .top.rset.m add command -label $l -command [list recall-set $setNo]
1563     if {$setMax > 20} {
1564         set setMax 20
1565     }
1566     set no [z39.$setNo numberOfRecordsReturned]
1567     dputs "Returned $no records, setOffset $setOffset"
1568     add-title-lines $setNo $no $setOffset
1569     set setOffset [expr $setOffset + $no]
1570
1571     set toGet [expr $setMax - $setOffset + 1]
1572     if {$toGet > 0} {
1573         if {$setOffset == 1} {
1574             set toGet 1
1575         } elseif {$toGet > $presentChunk} {
1576             set toGet $presentChunk
1577         }
1578         z39 callback {present-response}
1579         z39.$setNo present $setOffset $toGet
1580         show-status Retrieving 1 0
1581     }
1582 }
1583
1584 # Procedure present-more {number}
1585 #  number      number of records to be retrieved
1586 # This procedure starts a present-request. The $number variable indicates
1587 # the total number of records to be retrieved. The global $presentChunk
1588 # specifies the number of records to be retrieved at a time. If $number
1589 # is the empty string all remaining records in the result set are 
1590 # retrieved.
1591 proc present-more {number} {
1592     global setNo setOffset setMax busy cancelFlag delayRequest presentChunk
1593
1594     dputs "present-more"
1595     if {$cancelFlag} {
1596         show-status Retrieving 1 0
1597         set delayRequest "present-more $number"
1598         return
1599     }
1600     set delayRequest {}
1601
1602     if {$setNo == 0} {
1603         dputs "setNo=$setNo"
1604         return
1605     }
1606     set setOffset [z39.$setNo nextResultSetPosition]
1607     dputs "setOffest=${setOffset}"
1608     dputs "setNo=${setNo}"
1609     set max [z39.$setNo resultCount]
1610     if {$max < $setOffset} {
1611         dputs "max=$max"
1612         dputs "setOffset=$setOffset"
1613         show-status Ready 0 1
1614         return
1615     }
1616     if {![string length $number]} {
1617         set setMax $max
1618     } else {
1619         incr setMax $number
1620         if {$setMax > $max} {
1621             set setMax $max
1622         }
1623     }
1624     z39 callback {present-response}
1625     
1626     set toGet [expr $setMax - $setOffset + 1]
1627     if {$toGet <= 0} {
1628         return
1629     }
1630     if {$toGet > $presentChunk} {
1631         set toGet $presentChunk
1632     } 
1633     z39.$setNo present $setOffset $toGet
1634     show-status Retrieving 1 0
1635 }
1636
1637 # Procedure init-title-lines 
1638 # Utility that cleans the main record window.
1639 proc init-title-lines {} {
1640     .data.record delete 1.0 end
1641 }
1642
1643 # Procedure recall-set {setno}
1644 #  setno    Set number to recall
1645 proc recall-set {setno} {
1646     add-title-lines $setno 10000 1
1647 }
1648
1649 # Procedure add-title-lines {setno no offset}
1650 #  setno    Set number
1651 #  no       Number of records
1652 #  offset   Starting offset
1653 # This procedure displays the records $offset .. $offset+$no-1 in result
1654 # set $setno in the main record window by using the display format in the
1655 # global $displayFormat
1656 proc add-title-lines {setno no offset} {
1657     global displayFormats displayFormat setNo busy
1658
1659     dputs "add-title-lines offset=${offset} no=${no}"
1660     if {$setno != -1} {
1661         set setNo $setno
1662     } else {
1663         set setno $setNo
1664     }
1665     if {$offset == 1} {
1666         .bot.a.set configure -text $setno
1667         .data.record delete 1.0 end
1668     }
1669     set ffunc [lindex $displayFormats $displayFormat]
1670     dputs "ffunc=$ffunc"
1671     set ffunc "display-$ffunc"
1672     for {set i 0} {$i < $no} {incr i} {
1673         set o [expr $i + $offset]
1674         set type [z39.$setno type $o]
1675         if {![string length $type]} {
1676             dputs "no more at $o"
1677             break
1678         }
1679         .data.record tag bind r$o <Any-Enter> {}
1680         .data.record tag bind r$o <Any-Leave> {}
1681         set insert0 [.data.record index insert]
1682         $ffunc $setno $o .data.record 1
1683         .data.record tag add r$o $insert0 insert
1684         .data.record tag bind r$o <1> [list popup-marc $setno $o 0 0]
1685         update idletasks
1686     }
1687     if {!$busy} {
1688         show-status Ready 0 1
1689     }
1690 }
1691
1692 # Procedure present-response
1693 # Present-response handler. The incoming records are displayed and a new
1694 # present request is performed until all records ($setMax) is returned
1695 # from the target.
1696 proc present-response {} {
1697     global setNo setOffset setMax cancelFlag delayRequest presentChunk
1698
1699     dputs "In present-response"
1700     apduDump
1701     set no [z39.$setNo numberOfRecordsReturned]
1702     dputs "Returned $no records, setOffset $setOffset"
1703     add-title-lines $setNo $no $setOffset
1704     set setOffset [expr $setOffset + $no]
1705     if {$cancelFlag} {
1706         dputs "Handling cancel"
1707         set cancelFlag 0
1708         if {$delayRequest != ""} {
1709             eval $delayRequest
1710         }
1711         return
1712     }
1713     set status [z39.$setNo responseStatus]
1714     if {![string compare [lindex $status 0] NSD]} {
1715         show-status Ready 0 1
1716         set code [lindex $status 1]
1717         set msg [lindex $status 2]
1718         set addinfo [lindex $status 3]
1719         tkerror "NSD$code: $msg: $addinfo"
1720         return
1721     }
1722     if {$no > 0 && $setOffset <= $setMax} {
1723         dputs "present-request from ${setOffset}"
1724         set toGet [expr $setMax - $setOffset + 1]
1725         if {$toGet > $presentChunk} {
1726             set toGet $presentChunk
1727         }
1728         z39.$setNo present $setOffset $toGet
1729     } else {
1730         show-status Ready 0 1
1731     }
1732 }
1733
1734 # Procedure left-cursor {w}
1735 #  w    entry widget
1736 # Tries to move the cursor left in entry window $w
1737 proc left-cursor {w} {
1738     set i [$w index insert]
1739     if {$i > 0} {
1740         incr i -1
1741         $w icursor $i
1742     }
1743     dputs left
1744 }
1745
1746 # Procedure right-cursor {w}
1747 #  w    entry widget
1748 # Tries to move the cursor right in entry window $w
1749 proc right-cursor {w} {
1750     set i [$w index insert]
1751     incr i
1752     dputs right
1753     $w icursor $i
1754 }
1755
1756 # Procedure bind-fields {list returnAction escapeAction}
1757 #  list          list of entry widgets
1758 #  returnAction  return script
1759 #  escapeAction  escape script
1760 # Each widget in list are assigned bindings for <Tab>, <Left>, <Right>,
1761 # <Return> and <Escape>.
1762 proc bind-fields {list returnAction escapeAction} {
1763     set max [expr [llength $list]-1]
1764     for {set i 0} {$i < $max} {incr i} {
1765         bind [lindex $list $i] <Return> $returnAction
1766         bind [lindex $list $i] <Escape> $escapeAction
1767         bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
1768         bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1769         bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1770     }
1771     bind [lindex $list $i] <Return> $returnAction
1772     bind [lindex $list $i] <Escape> $escapeAction
1773     bind [lindex $list $i] <Tab>  [list focus [lindex $list 0]]
1774     bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
1775     bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
1776     focus [lindex $list 0]
1777 }
1778
1779 # Procedure entry-fields {parent list tlist returnAction escapeAction}
1780 #  list          list of frame widgets
1781 #  tlist         list of text to be used as lead of each entry
1782 #  returnAction  return script
1783 #  escapeAction  escape script
1784 # Makes label and entry widgets in each widget in $list.
1785 proc entry-fields {parent list tlist returnAction escapeAction} {
1786     set alist {}
1787     set i 0
1788     foreach field $list {
1789         set label ${parent}.${field}.label
1790         set entry ${parent}.${field}.entry
1791         label $label -text [lindex $tlist $i] -anchor e
1792         entry $entry -width 32 -relief sunken
1793         pack $label -side left
1794         pack $entry -side right
1795         lappend alist $entry
1796         incr i
1797     }
1798     bind-fields $alist $returnAction $escapeAction
1799 }
1800
1801 # Procedure define-target-dialog
1802 # Dialog that asks for new target to be defined.
1803 proc define-target-dialog {} {
1804     set w .target-define
1805
1806     toplevel $w
1807     place-force $w .
1808     top-down-window $w
1809     frame $w.top.target
1810     pack $w.top.target -side top -anchor e -pady 2 
1811     entry-fields $w.top {target} {{Target:}} \
1812             {define-target-action} {destroy .target-define}
1813     top-down-ok-cancel $w {define-target-action} 1
1814 }
1815
1816 # Procedure place-force {window parent}
1817 #  window      new top level widget
1818 #  parent      parent widget used as base
1819 # Sets geometry of $window relative to $parent window.
1820 proc place-force {window parent} {
1821     set g [wm geometry $parent]
1822     set p1 [string first + $g]
1823     set p2 [string last + $g]
1824     set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
1825     set y [expr 60+[string range $g [expr $p2 +1] end]]
1826     wm geometry $window +${x}+${y}
1827 }
1828
1829 # Procedure add-database-action {target w}
1830 #  target      target to be defined
1831 #  w           top level widget for the target definition
1832 # Adds the contents of .database-select.top.database.entry to list of
1833 # databases.
1834 proc add-database-action {target w} {
1835     global profile
1836
1837     $w.top.databases.list insert end [.database-select.top.database.entry get]
1838     destroy .database-select
1839 }
1840
1841 # Procedure add-database {target wp}
1842 #  target      target to be defined
1843 #  wp          top level widget for the target definition
1844 # Makes a dialog in which the user enters new database
1845 proc add-database {target wp} {
1846     global profile
1847
1848     set w .database-select
1849     toplevel $w
1850     set oldFocus [focus]
1851     place-force $w $wp
1852     top-down-window $w
1853     frame $w.top.database
1854     pack $w.top.database -side top -anchor e -pady 2
1855         entry-fields $w.top {database} {{Database to add:}} \
1856             [list add-database-action $target $wp] {destroy .database-select}
1857
1858     top-down-ok-cancel $w [list add-database-action $target $wp] 1
1859     focus $oldFocus
1860 }
1861
1862
1863 # Procedure delete-database {target w}
1864 #  target     target to be defined
1865 #  w          top level widget for the target definition
1866 # Asks the user if he/she really wishes to delete a database and removes
1867 # the database from the database-list if requested.
1868 proc delete-database {target w} {
1869     global profile
1870
1871     set l {}
1872     foreach i [$w.top.databases.list curselection] {
1873         set b [$w.top.databases.list get $i]
1874         set l "$l $b"
1875     }
1876     set a [alert "Are you sure you want to remove the database(s)${l}?"]
1877     if {$a} {
1878         foreach i [lsort -decreasing \
1879                 [$w.top.databases.list curselection]] {
1880             $w.top.databases.list delete $i
1881         }
1882     }
1883 }
1884
1885 # Procedure advanced-setup {target b}
1886 #  target     target to be defined
1887 #  b          window number of target top level
1888 # Makes a dialog in which the user may modify/view advanced settings
1889 # of a target definition (profile).
1890 proc advanced-setup {target b} {
1891     global profile profileS
1892
1893     set w .advanced-setup-$b
1894     toplevelG $w
1895     wm title $w "Advanced setup $target"
1896     top-down-window $w
1897      if {![string length $target]} {
1898         set target Default
1899     }
1900     dputs target
1901     
1902     frame $w.top.largeSetLowerBound
1903     frame $w.top.smallSetUpperBound
1904     frame $w.top.mediumSetPresentNumber
1905     frame $w.top.presentChunk
1906     frame $w.top.maximumRecordSize
1907     frame $w.top.preferredMessageSize
1908
1909     pack $w.top.largeSetLowerBound $w.top.smallSetUpperBound \
1910             $w.top.mediumSetPresentNumber $w.top.presentChunk \
1911             $w.top.maximumRecordSize $w.top.preferredMessageSize \
1912             -side top -anchor e -pady 2
1913     
1914     entry-fields $w.top {largeSetLowerBound smallSetUpperBound \
1915             mediumSetPresentNumber presentChunk maximumRecordSize \
1916             preferredMessageSize} \
1917             {{Large Set Lower Bound:} {Small Set Upper Bound:} \
1918             {Medium Set Present Number:} {Present Chunk:} \
1919             {Maximum Record Size:} {Preferred Message Size:}} \
1920             [list advanced-setup-action $target $b] [list destroy $w]
1921
1922     $w.top.largeSetLowerBound.entry configure -textvariable \
1923         profileS($target,largeSetLowerBound)
1924     $w.top.smallSetUpperBound.entry configure -textvariable \
1925         profileS($target,smallSetUpperBound)
1926     $w.top.mediumSetPresentNumber.entry configure -textvariable \
1927         profileS($target,mediumSetPresentNumber)
1928     $w.top.presentChunk.entry configure -textvariable \
1929         profileS($target,presentChunk)
1930     $w.top.maximumRecordSize.entry configure -textvariable \
1931         profileS($target,maximumRecordSize)
1932     $w.top.preferredMessageSize.entry configure -textvariable \
1933         profileS($target,preferredMessageSize)
1934     
1935     bottom-buttons $w [list {Ok} [list advanced-setup-action $target $b] \
1936             {Cancel} [list destroy $w]] 0   
1937 }
1938
1939 # Procedure advanced-setup-action {target b}
1940 #  target     target to be defined
1941 #  b          window number of target top level
1942 # This procedure is called when the user hits Ok in the advanced target
1943 # setup dialog. The temporary result is stored in the $profileS - array.
1944 proc advanced-setup-action {target b} {
1945     set w .advanced-setup-$b
1946     global profileS
1947     
1948     set profileS($target,LSLB) [$w.top.largeSetLowerBound.entry get]
1949     set profileS($target,SSUB) [$w.top.smallSetUpperBound.entry get]
1950     set profileS($target,MSPN) [$w.top.mediumSetPresentNumber.entry get]
1951     set profileS($target,presentChunk) [$w.top.presentChunk.entry get]
1952     set profileS($target,MRS) [$w.top.maximumRecordSize.entry get]
1953     set profileS($target,PMS) [$w.top.preferredMessageSize.entry get]
1954
1955     dputs "advanced-setup-action"
1956     destroy $w
1957 }
1958
1959 # Procedure database-select-action
1960 # Called when the user commits a database select change. See procedure
1961 # database-select.
1962 proc database-select-action {} {
1963     set w .database-select.top
1964     set b {}
1965     foreach indx [$w.databases.list curselection] {
1966         lappend b [$w.databases.list get $indx]
1967     }
1968     if {$b != ""} {
1969         z39 databaseNames $b
1970     }
1971     destroy .database-select
1972 }
1973
1974 # Procedure database-select
1975 # Makes a dialog in which the user may select a database
1976 proc database-select {} {
1977     set w .database-select
1978     global profile hostid
1979
1980     toplevel $w
1981     set oldFocus [focus]
1982     place-force $w .
1983     top-down-window $w
1984
1985     frame $w.top.databases -relief ridge -border 2
1986     pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
1987
1988     label $w.top.databases.label -text "List"
1989     listbox $w.top.databases.list -width 20 -height 6 \
1990             -yscrollcommand "$w.top.databases.scroll set"
1991     scrollbar $w.top.databases.scroll -orient vertical -border 1
1992     pack $w.top.databases.label -side top -fill x -padx 2 -pady 2
1993     pack $w.top.databases.list -side left -fill both -expand yes -padx 2 -pady 2
1994     pack $w.top.databases.scroll -side right -fill y -padx 2 -pady 2
1995     $w.top.databases.scroll config -command "$w.top.databases.list yview"
1996
1997     foreach b $profile($hostid,databases) {
1998         $w.top.databases.list insert end $b
1999     }
2000     top-down-ok-cancel $w {database-select-action} 1
2001     focus $oldFocus
2002 }
2003
2004 # Procedure cascase-dblist-select
2005 proc cascade-dblist-select {target db} {
2006     show-target $target $db
2007     z39 databaseNames $db
2008     ready-response-actions $target $db
2009 }
2010
2011 # Procedure cascade-dblist 
2012 # Makes the Service/database list with proper databases for the target
2013 proc cascade-dblist {target base} {
2014     global profile
2015
2016     set w .top.service.m.dblist
2017     $w delete 0 200
2018     if {[info exists profile($target,databases)]} {
2019                 foreach db $profile($target,databases) {
2020                     $w add command -label $db \
2021                         -command [list cascade-dblist-select $target $db]
2022                 }
2023     }
2024 }
2025
2026 # Procedure cascade-target-list
2027 # Makes all target/databases available in the Target|Connect
2028 # menu as well as all targets in the Target|Setup menu.
2029 # This procedure is called whenever target definitions occur.
2030 proc cascade-target-list {} {
2031     global profile
2032     
2033     foreach sub [winfo children .top.target.m.clist] {
2034         destroy $sub
2035     }
2036     .top.target.m.clist delete 0 last
2037     foreach nn [lsort [array names profile *,host]] {
2038                 if {[string length $profile($nn)]} {
2039                     set ll [expr [string length $nn] - 6]
2040                     set n [string range $nn 0 $ll]
2041                     
2042                     set nl $profile($n,windowNumber)
2043                     if {[info exists profile($n,databases)]} {
2044                                 set ndb [llength $profile($n,databases)]
2045                     } else {
2046                                 set ndb 0
2047                     }
2048                     if {$ndb > 1} {
2049                                 .top.target.m.clist add cascade -label $n \
2050                                     -menu .top.target.m.clist.$nl
2051                                 irmenu .top.target.m.clist.$nl
2052                                 foreach b $profile($n,databases) {
2053                                     .top.target.m.clist.$nl add command -label $b \
2054                                         -command [list reopen-target $n $b]
2055                                 }
2056                     } elseif {$ndb == 1} {
2057                                 .top.target.m.clist add command -label $n -command \
2058                                 [list reopen-target $n [lindex $profile($n,databases) 0]]
2059                     } else {
2060                                 .top.target.m.clist add command -label $n -command \
2061                                 [list reopen-target $n {}]
2062                     }
2063                 }
2064     }
2065     .top.target.m.slist delete 0 last
2066     foreach nn [lsort [array names profile *,host]] {
2067                 set ll [expr [string length $nn] - 6]
2068                 set n [string range $nn 0 $ll]
2069             .top.target.m.slist add command -label $n -command [list protocol-setup $n]
2070     }
2071 }
2072
2073 # Procedure query-select {i}
2074 #  i       Query type number (integer)
2075 # This procedure is called when the user selects a Query type. The current
2076 # query type information given by the globals $queryButtonsFind and
2077 # $queryInfoFind are affected by this operation.
2078 proc query-select {i} {
2079     global queryButtonsFind queryInfoFind queryButtons queryInfo queryAuto queryAutoOld hostid currentDb profile
2080     
2081     if {$queryAutoOld == 1 && $queryAuto == 0} {
2082         set queryAutoOld $queryAuto
2083         return
2084     }
2085     if {$queryAutoOld == 0 && $queryAuto == 1 && [info exists profile($hostid,AttributeDetails,$currentDb,Bib1Use)] == 0} {
2086         set queryAutoOld $queryAuto
2087         return
2088     }
2089     set queryInfoFind [lindex $queryInfo $i]
2090     set queryButtonsFind [lindex $queryButtons $i]
2091     index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2092 }
2093
2094 # Procedure query-new-action 
2095 # Commits a new query type definition by extending the globals
2096 # $queryTypes, $queryButtons and $queryInfo.
2097 proc query-new-action {} {
2098     global queryTypes queryButtons queryInfo settingsChanged
2099
2100     set settingsChanged 1
2101     lappend queryTypes [.query-new.top.index.entry get]
2102     lappend queryButtons {}
2103     lappend queryInfo {}
2104
2105     destroy .query-new
2106     cascade-query-list
2107 }
2108
2109 # Procedure query-new
2110 # Makes a dialog in which the user is requested to enter the name of a
2111 # new query type.
2112 proc query-new {} {
2113     set w .query-new
2114
2115     toplevel $w
2116     set oldFocus [focus]
2117     place-force $w .
2118     top-down-window $w
2119     frame $w.top.index
2120     pack $w.top.index -side top -anchor e -pady 2 
2121     entry-fields $w.top index {{Query Name:}} \
2122             query-new-action {destroy .query-new}
2123     top-down-ok-cancel $w query-new-action 1
2124     focus $oldFocus
2125 }
2126
2127 # Procedure query-delete-action {queryNo}
2128 #  queryNo     query type number (integer)
2129 # Procedure that deletes the query type specified by $queryNo.
2130 proc query-delete-action {queryNo} {
2131     global queryTypes queryButtons queryInfo settingsChanged
2132
2133     set settingsChanged 1
2134
2135     set queryTypes [lreplace $queryTypes $queryNo $queryNo]
2136     set queryButtons [lreplace $queryButtons $queryNo $queryNo]
2137     set queryInfo [lreplace $queryInfo $queryNo $queryNo]
2138     destroy .query-delete
2139     cascade-query-list
2140 }
2141
2142 # Procedure query-delete {queryNo}
2143 #  queryNo     query type number (integer)
2144 # Asks if the user really want to delete a given query type; calls
2145 # query-delete-action if 'yes'.
2146 proc query-delete {queryNo} {
2147     global queryTypes
2148
2149     set w .query-delete
2150
2151     toplevel $w
2152     place-force $w .
2153     top-down-window $w
2154     set n [lindex $queryTypes $queryNo]
2155
2156     label $w.top.warning -bitmap warning
2157     message $w.top.quest -text "Are you sure you want to delete the \
2158                 query type $n ?"  -aspect 300
2159     pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
2160     bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
2161                 {Cancel} [list destroy $w]] 1
2162 }
2163
2164 # Procedure cascade-query-list
2165 # Updates the entries below Options|Query to list all query types.
2166 proc cascade-query-list {} {
2167     global queryTypes hostid queryAuto
2168     set w .top.options.m.query
2169     set i 0
2170     $w.clist delete 0 last
2171     foreach n $queryTypes {
2172         if {$n == "Auto"} {
2173                 $w.clist add check -label $n -variable queryAuto -command [list query-select $i]
2174         } else {
2175                 $w.clist add command -label $n -command [list query-select $i]      
2176         }
2177         incr i
2178     }
2179     set i 0
2180     $w.slist delete 0 last
2181     foreach n $queryTypes {
2182         if {$n == "Auto"} {
2183                 if {$hostid == "Default"} {
2184                         $w.slist add command -label $n -state disabled -command [list query-setup $i]
2185                 } else {
2186                         $w.slist add command -label $n -command [list query-setup $i]
2187                 }
2188         } else {
2189                 $w.slist add command -label $n -command [list query-setup $i]
2190         }
2191         incr i
2192     }
2193     set i 0
2194     $w.dlist delete 0 last
2195     foreach n $queryTypes {
2196         $w.dlist add command -label $n -command [list query-delete $i]
2197         incr i
2198     }
2199 }
2200
2201 # Procedure save-geometry
2202 # This procedure saves the per-user related settings in ~/.clientrc.tcl.
2203 # The geometry information stored in the global array $windowGeometry is
2204 # saved. Also a few other user settings, such as current display format, are
2205 # saved.
2206 proc save-geometry {} {
2207     global windowGeometry hotTargets textWrap displayFormat popupMarcdf \
2208                 recordSyntax elementSetNames hostid
2209
2210     set windowGeometry(.) [wm geometry .]
2211
2212     if {[catch {set f [open ~/.clientrc.tcl w]}]} {
2213         return
2214     } 
2215     if {$hostid != "Default"} {
2216         puts $f "set hostid [list $hostid]"
2217         set b [z39 databaseNames]
2218         puts $f "set hostbase [list $b]"
2219     }
2220     puts $f "set hotTargets [list $hotTargets]"
2221     puts $f "set textWrap $textWrap"
2222     puts $f "set displayFormat $displayFormat"
2223     puts $f "set popupMarcdf $popupMarcdf"
2224     puts $f "set recordSyntax $recordSyntax"
2225     puts $f "set elementSetNames $elementSetNames"
2226     foreach n [array names windowGeometry] {
2227         puts -nonewline $f "set [list windowGeometry($n)] "
2228         puts $f [list $windowGeometry($n)]
2229     }
2230     close $f
2231 }
2232
2233 # Procedure save-settings
2234 # This procedure saves the per-host related settings irtdb.tcl which
2235 # is normally kept in the directory /usr/local/lib/irtcl.
2236 # All query types and target defintion profiles are saved.
2237 proc save-settings {} {
2238     global profile libdir settingsChanged queryTypes queryButtons queryInfo queryAuto
2239
2240     if {[file writable "${libdir}/irtdb.tcl"]} {
2241         set f [open "${libdir}/irtdb.tcl" w]
2242     } else {
2243         set f [open "irtdb.tcl" w]
2244     }
2245     puts $f "# Setup file"
2246     foreach n [lsort [array names profile]] {
2247         puts $f "set [list profile($n)] [list $profile($n)]"
2248     }
2249     puts $f "set queryTypes [list $queryTypes]"
2250     puts $f "set queryButtons [list $queryButtons]"
2251     puts $f "set queryInfo [list $queryInfo]"
2252     puts $f "set queryAuto [list $queryAuto]"
2253     close $f
2254     set settingsChanged 0
2255 }
2256
2257 # Procedure alert {ask}
2258 #  ask    prompt string
2259 # Makes a grabbed dialog in which the user is requested to answer
2260 # "Ok" or "Cancel". This procedure returns 1 if the user hits "Ok"; 0
2261 # otherwise.
2262 proc alert {ask} {
2263     set w .alert
2264
2265     global alertAnswer font
2266
2267     toplevel $w
2268     set oldFocus [focus]
2269     place-force $w .
2270     top-down-window $w
2271
2272     label $w.top.warning -bitmap warning
2273     message $w.top.message -text $ask -aspect 300 -font $font(b,normal)
2274     pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
2275   
2276     set alertAnswer 0
2277     top-down-ok-cancel $w {alert-action} 1
2278     focus $oldFocus
2279     return $alertAnswer
2280 }
2281
2282 # Procedure alert-action
2283 # Called when the user hits "Ok" in the .alert-window.
2284 proc alert-action {} {
2285     global alertAnswer
2286     set alertAnswer 1
2287     destroy .alert
2288 }
2289
2290 # Procedure exit-action
2291 # This procedure is called if the user exists the application
2292 proc exit-action {} {
2293     global settingsChanged
2294
2295     if {$settingsChanged} {
2296         save-settings
2297     }
2298     save-geometry
2299     exit 0
2300 }
2301
2302 # Procedure listbuttonaction {w name h user i}
2303 #  w       menubutton widget
2304 #  name    name information
2305 #  h       handler to be invoked
2306 #  user    user information to be passed to handler $h
2307 #  i       index passed as second argument to handler $h
2308 # Utility function to emulate a listbutton. Called when the user
2309 # Modifies the listbutton. See procedure listbuttonx.
2310 proc listbuttonaction {w name h user i} {
2311     $w configure -text [lindex $name 0]
2312     $h [lindex $name 1] $user $i
2313 }
2314
2315 # Procedure listbuttonx {button no names handle user}
2316 #  button  menubutton widget
2317 #  no      initial value index (integer)
2318 #  names   list of name entries. The first entry in each name
2319 #          entry is the actual name
2320 #  handle  user function to be called when the listbutton changes
2321 #          its value
2322 #  user    user argument to the $handle function
2323 # Makes an extended listbutton.
2324 proc listbuttonx {button no names handle user} {
2325     if {[winfo exists $button]} {
2326         $button configure -text [lindex [lindex $names $no] 0]
2327         ${button}.m delete 0 last
2328     } else {
2329         menubutton $button -text [lindex [lindex $names $no] 0] \
2330                         -width 15 -menu ${button}.m -relief raised -border 1
2331         irmenu ${button}.m
2332         ${button}.m configure -tearoff off
2333     }
2334     set i 0
2335     foreach name $names {
2336         ${button}.m add command -label [lindex $name 0] \
2337                         -command [list listbuttonaction ${button} $name $handle $user $i]
2338         incr i
2339     }
2340 }
2341
2342 # Procedure listbutton {button no names}
2343 #  button  menubutton widget
2344 #  no      initial value index (integer)
2345 #  names   list of possible values.
2346 # Makes a listbutton. The functionality is emulated by the use menubutton-
2347 # and menu widgets.
2348 proc listbutton {button no names} {
2349     menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
2350             -relief raised -border 1
2351     irmenu ${button}.m
2352     ${button}.m configure -tearoff off
2353     foreach name $names {
2354         ${button}.m add command -label $name \
2355                 -command [list ${button} configure -text $name]
2356     }
2357 }
2358
2359 # Procedure listbuttonv-action {button var names i}
2360 #  button   menubutton widget
2361 #  var      global variable to be affected
2362 #  names    list of possible names and values
2363 # This procedure is called when the user alters a menu created by the
2364 # listbuttonv procedure. The global variable $var is updated.
2365 proc listbuttonv-action {button var names i} {
2366     global $var
2367
2368     set $var [lindex $names [expr $i+1]]
2369     $button configure -text [lindex $names $i]
2370 }
2371
2372 # Procedure listbuttonv {button var names}
2373 #  button   menubutton widget
2374 #  var      global variable to be affected
2375 #  names    List of name/value pairs, i.e. {n1 v1 n2 v2 ...}.
2376 # This procedure emulates a listbutton by means of menu/menubutton widgets.
2377 # The global variable $var is automatically updated and set to one of the
2378 # values v1, v2, ...
2379 proc listbuttonv {button var names} {
2380     global $var
2381
2382     set n "-"
2383     eval "set val $$var"
2384     set l [llength $names]
2385     for {set i 1} {$i < $l} {incr i 2} {
2386         if {$val == [lindex $names $i]} {
2387             incr i -1
2388             set n [lindex $names $i]
2389             break
2390         }
2391     }
2392     if {[winfo exists $button]} {
2393         $button configure -text $n
2394         return
2395     }
2396     menubutton $button -text $n -menu ${button}.m -relief raised -border 1
2397     irmenu ${button}.m
2398     ${button}.m configure -tearoff off
2399     for {set i 0} {$i < $l} {incr i 2} {
2400         ${button}.m add command -label [lindex $names $i] \
2401                 -command [list listbuttonv-action $button $var $names $i]
2402     }
2403 }
2404
2405 # Procedure query-add-index-action {queryNo}
2406 #  queryNo       query type number (integer)
2407 # Handler that makes a new query index.
2408 proc query-add-index-action {queryNo} {
2409     set w .query-setup
2410
2411     global queryInfoTmp queryButtonsTmp
2412
2413     set newI [.query-add-index.top.index.entry get]
2414     lappend queryInfoTmp [list $newI {}]
2415     $w.top.index.list insert end $newI
2416     destroy .query-add-index
2417     index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2418 }
2419
2420 # Procedure query-add-line
2421 #  queryNo      query type number (integer)
2422 # Handler that adds new query line.
2423 proc query-add-line {queryNo} {
2424     set w .query-setup
2425
2426     global queryInfoTmp queryButtonsTmp
2427
2428     lappend queryButtonsTmp {I 0}
2429
2430     index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2431 }
2432
2433 # Procedure query-del-line
2434 #  queryNo      query type number (integer)
2435 # Handler that removes query line.
2436 proc query-del-line {queryNo} {
2437     set w .query-setup
2438
2439     global queryInfoTmp queryButtonsTmp
2440
2441     set l [llength $queryButtonsTmp]
2442     if {$l <= 0} {
2443         return
2444     }
2445     incr l -1
2446     set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
2447     index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2448 }
2449
2450 # Procedure query-add-index
2451 #  queryNo      query type number (integer)
2452 # Handler that adds new query index.
2453 proc query-add-index {queryNo} {
2454     set w .query-add-index
2455
2456     toplevel $w
2457     set oldFocus [focus]
2458     place-force $w .query-setup
2459     top-down-window $w
2460     frame $w.top.index
2461     pack $w.top.index -side top -anchor e -pady 2 
2462     entry-fields $w.top {index} {{Index Name:}} \
2463             [list query-add-index-action $queryNo] [list destroy $w]
2464     top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
2465     focus $oldFocus
2466 }
2467
2468 # Procedure query-setup-action
2469 #  queryNo      query type number (integer)
2470 # Handler that updates the query information database stored in the
2471 # globals $queryInfo and $queryButtons. This procedure is executed when
2472 # the user commits the query setup changes by pressing button "Ok".
2473 proc query-setup-action {queryNo} {
2474     global queryButtons queryInfo queryButtonsTmp queryInfoTmp queryButtonsFind \
2475                 queryInfoFind settingsChanged hostid currentDb profile
2476     set settingsChanged 1
2477     set queryInfo [lreplace $queryInfo $queryNo $queryNo $queryInfoTmp]
2478     set queryButtons [lreplace $queryButtons $queryNo $queryNo $queryButtonsTmp]
2479     if {[info exists profile($hostid,AttributeDetails,$currentDb,Bib1Use)]} {
2480         set profile($hostid,queryButtons,$currentDb) $queryButtonsTmp
2481     }
2482     set queryInfoFind $queryInfoTmp
2483     set queryButtonsFind $queryButtonsTmp
2484     destroy .query-setup
2485     index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
2486 }
2487
2488 #proc changeQueryButtons {target base}
2489 #target         target name
2490 #base           database name
2491 #Substitutes the third element (the Auto element) in queryButtons with 
2492 #profile(target,queryButtons,base). The third element in queryInfo is also substituted with
2493 #profile(target,AttributeDetails,base,Bib1Use)
2494 proc changeQueryButtons {target base} {
2495         source bib-1.tcl
2496         global profile queryButtons queryInfo
2497         if {[info exists profile($target,queryButtons,$base)]} {
2498                 set queryButtons [lreplace $queryButtons 2 2 $profile($target,queryButtons,$base)]
2499                 foreach tag $profile($target,AttributeDetails,$base,Bib1Use) {
2500                         if {$tag < 1037} {
2501                                 lappend tempList [list $bib1($tag) 1=$tag]
2502                         }
2503                 }
2504                 set queryInfo [lreplace $queryInfo 2 2 $tempList]
2505         }
2506 }
2507
2508 # Procedure activate-e-index {value no i}
2509 #   value   menu name
2510 #   no      query index number
2511 #   i       menu index (integer)
2512 # Procedure called when listbutton is activated in the query type edit
2513 # window. The global $queryButtonsTmp is updated in this operation.
2514 proc activate-e-index {value no i} {
2515     global queryButtonsTmp queryIndexTmp
2516     set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
2517     dputs $queryButtonsTmp
2518     set queryIndexTmp $i
2519 }
2520
2521 # Procedure activate-index {value no i}
2522 #   value   menu name
2523 #   no      query index number
2524 #   i       menu index (integer)
2525 # Procedure called when listbutton is activated in the main query 
2526 # window. The global $queryButtonsFind is updated in this operation.
2527 proc activate-index {value no i} {
2528     global queryButtonsFind
2529
2530     set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
2531     dputs "queryButtonsFind $queryButtonsFind"
2532 }
2533
2534 # Procedure update-attr
2535 # This procedure creates listbuttons for all bib-1 attributes except
2536 # the use-attribute in the .index-setup window.
2537 # The globals $relationTmpValue, $positionTmpValue, $structureTmpValue,
2538 # $truncationTmpValue and $completenessTmpValue are maintainted by the
2539 # listbuttons.
2540 proc update-attr {} {
2541     set w .index-setup
2542     listbuttonv $w.top.relation.b relationTmpValue\
2543             {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
2544             {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
2545             {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
2546     listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
2547             {First in field} 1 {First in subfield} 2 {Any position in field} 3}
2548     listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
2549             {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list}  6 \
2550             {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
2551             {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
2552             {local-number} 107 {string} 108 {numeric string} 109}
2553     listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
2554             {Left} 2 {Left and right} 3 {No truncation} 100 \
2555             {Process #} 101 {Re-1} 102 {Re-2} 103}
2556     listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
2557             {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
2558 }
2559
2560 # Procedure use-attr {init}
2561 #  init      init flag
2562 # This procedure creates a listbox with several Bib-1 use attributes.
2563 # If $init is 1 the listbox is created with the attributes. If $init
2564 # is 0 the current selection of the listbox is read and the global
2565 # $useTmpValue is set to the current use-value.
2566 proc use-attr {init} {
2567     set attr {
2568         {None}                           0
2569         {Personal name}                  1 
2570         {Corporate name}                 2 
2571         {Conference name}                3 
2572         {Title}                          4 
2573         {Title-series}                   5 
2574         {Title-uniform}                  6 
2575         {ISBN}                           7 
2576         {ISSN}                           8 
2577         {LC card number}                 9 
2578         {BNB card number}                10
2579         {BGF(sic) number}                11 
2580         {Local number}                   12 
2581         {Dewey classification}           13 
2582         {UDC classification}             14 
2583         {Bliss classification}           15 
2584         {LC call number}                 16 
2585         {NLM call number}                17 
2586         {NAL call number}                18 
2587         {MOS call number}                19 
2588         {Local classification}           20 
2589         {Subject heading}                21 
2590         {Subject-RAMEAU}                 22 
2591         {BDI-index-subject}              23 
2592         {INSPEC-subject}                 24 
2593         {MESH-subject}                   25 
2594         {PA-subject}                     26 
2595         {LC-subject-heading}             27 
2596         {RVM-subject-heading}            28 
2597         {Local subject index}            29 
2598         {Date}                           30 
2599         {Date of publication}            31 
2600         {Date of acquisition}            32 
2601         {Title-key}                      33 
2602         {Title-collective}               34 
2603         {Title-parallel}                 35 
2604         {Title-cover}                    36 
2605         {Title-added-title-page}         37 
2606         {Title-caption}                  38 
2607         {Title-running}                  39 
2608         {Title-spine}                    40 
2609         {Title-other-variant}            41 
2610         {Title-former}                   42 
2611         {Title-abbreviated}              43 
2612         {Title-expanded}                 44 
2613         {Subject-PRECIS}                 45 
2614         {Subject-RSWK}                   46 
2615         {Subject-subdivision}            47 
2616         {Number-natl-bibliography}       48 
2617         {Number-legal-deposit}           49 
2618         {Number-govt-publication}        50 
2619         {Number-publisher-for-music}     51 
2620         {Number-DB}                      52 
2621         {Number-local-call}              53 
2622         {Code-language}                  54 
2623         {Code-geographic-area}           55 
2624         {Code-institution}               56 
2625         {Name and title}                 57 
2626         {Name-geographic}                58 
2627         {Place-publication}              59 
2628         {CODEN}                          60 
2629         {Microform-generation}           61 
2630         {Abstract}                       62 
2631         {Note}                           63 
2632         {Author-title}                 1000 
2633         {Record type}                  1001 
2634         {Name}                         1002 
2635         {Author}                       1003 
2636         {Author-name-personal}         1004 
2637         {Author-name-corporate}        1005 
2638         {Author-name-conference}       1006 
2639         {Identifier-standard}          1007 
2640         {Subject-LC-children's}        1008 
2641         {Subject-name-personal}        1009 
2642         {Body of text}                 1010 
2643         {Date/time added to database}  1011 
2644         {Date/time last modified}      1012 
2645         {Authority/format identifier}  1013 
2646         {Concept-text}                 1014 
2647         {Concept-reference}            1015 
2648         {Any}                          1016 
2649         {Server choice}                1017 
2650         {Publisher}                    1018 
2651         {Record source}                1019 
2652         {Editor}                       1020 
2653         {Bib-level}                    1021 
2654         {Geographic class}             1022 
2655         {Indexed by}                   1023 
2656         {Map scale}                    1024 
2657         {Music key}                    1025 
2658         {Related periodical}           1026 
2659         {Report number}                1027 
2660         {Stock number}                 1028 
2661         {Thematic number}              1030 
2662         {Material type}                1031 
2663         {Doc ID}                       1032 
2664         {Host item}                    1033 
2665         {Content type}                 1034 
2666         {Anywhere}                     1035 
2667     }
2668     set w .index-setup
2669     global useTmpValue
2670     set l [llength $attr]
2671
2672     if {$init} {
2673         set s 0
2674         set lno 0
2675         for {set i 0} {$i < $l} {incr i} {
2676             $w.top.use.list insert end [lindex $attr $i]
2677             incr i
2678             if {$useTmpValue == [lindex $attr $i]} {
2679                 set s $lno
2680             }
2681             incr lno
2682         }
2683         $w.top.use.list selection clear 0 end
2684         $w.top.use.list selection set $s $s
2685         incr s -3
2686         if {$s < 0} {
2687             set s 0
2688         }
2689         $w.top.use.list yview $s
2690     } else {
2691         set lno [lindex [$w.top.use.list curselection] 0]
2692         set i [expr $lno+$lno+1]
2693         set useTmpValue [lindex $attr $i]
2694         dputs "useTmpValue=$useTmpValue"
2695     }
2696 }
2697
2698 # Procedure index-setup-action {oldAttr queryNo indexNo}
2699 #  oldAttr     original attributes (?)
2700 #  queryNo     query number
2701 #  indexNo     index number
2702 # Commits setup of a query index. The mapping from the index to 
2703 # the Bib-1 attributes are handled by this function.
2704 proc index-setup-action {oldAttr queryNo indexNo} {
2705     set attr [lindex $oldAttr 0]
2706
2707     global useTmpValue relationTmpValue structureTmpValue truncationTmpValue \
2708         completenessTmpValue positionTmpValue queryInfoTmp
2709
2710     use-attr 0
2711
2712     dputs "index-setup-action"
2713     dputs "queryNo $queryNo"
2714     dputs "indexNo $indexNo"
2715     if {$useTmpValue > 0} {
2716         lappend attr "1=$useTmpValue"
2717     }
2718     if {$relationTmpValue > 0} {
2719         lappend attr "2=$relationTmpValue"
2720     }
2721     if {$positionTmpValue > 0} {
2722         lappend attr "3=$positionTmpValue"
2723     }
2724     if {$structureTmpValue > 0} {
2725         lappend attr "4=$structureTmpValue"
2726     }
2727     if {$truncationTmpValue > 0} {
2728         lappend attr "5=$truncationTmpValue"
2729     }
2730     if {$completenessTmpValue > 0} {
2731         lappend attr "6=$completenessTmpValue"
2732     }
2733     dputs "new attr $attr"
2734     set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
2735     destroy .index-setup
2736 }
2737
2738 # Procedure index-setup {attr queryNo indexNo}
2739 #  attr        original attributes
2740 #  queryNo     query number
2741 #  indexNo     index number
2742 # Makes a window with settings of a given query index which the user
2743 # may inspect/modify.
2744 proc index-setup {attr queryNo indexNo} {
2745     set w .index-setup
2746
2747     global relationTmpValue structureTmpValue truncationTmpValue \
2748                 completenessTmpValue positionTmpValue useTmpValue
2749     set relationTmpValue 0
2750     set truncationTmpValue 0
2751     set structureTmpValue 0
2752     set positionTmpValue 0
2753     set completenessTmpValue 0
2754     set useTmpValue 0
2755
2756     catch {destroy $w}
2757     toplevelG $w
2758
2759     set n [lindex $attr 0]
2760     wm title $w "Index setup $n"
2761
2762     top-down-window $w
2763
2764     set len [llength $attr]
2765     for {set i 1} {$i < $len} {incr i} {
2766         set q [lindex $attr $i]
2767         set l [string first = $q]
2768         if {$l > 0} {
2769             set t [string range $q 0 [expr $l - 1]]
2770             set v [string range $q [expr $l + 1] end]
2771             switch $t {
2772                 1
2773                 { set useTmpValue $v }
2774                 2
2775                 { set relationTmpValue $v }
2776                 3
2777                 { set positionTmpValue $v }
2778                 4
2779                 { set structureTmpValue $v }
2780                 5
2781                 { set truncationTmpValue $v }
2782                 6
2783                 { set completenessTmpValue $v }
2784             }
2785         }
2786     }
2787
2788     frame $w.top.use -relief ridge -border 2
2789     frame $w.top.relation -relief ridge -border 2
2790     frame $w.top.position -relief ridge -border 2
2791     frame $w.top.structure -relief ridge -border 2
2792     frame $w.top.truncation -relief ridge -border 2
2793     frame $w.top.completeness -relief ridge -border 2
2794
2795     update-attr
2796
2797     # Use Attributes
2798
2799     pack $w.top.use -side left -pady 6 -padx 6 -fill y
2800
2801     label $w.top.use.label -text "Use"
2802         listbox $w.top.use.list -width 26 -yscrollcommand "$w.top.use.scroll set"
2803     scrollbar $w.top.use.scroll -orient vertical -border 1
2804     pack $w.top.use.label -side top -fill x -padx 2 -pady 2
2805     pack $w.top.use.list -side left -fill both -expand yes -padx 2 -pady 2
2806     pack $w.top.use.scroll -side right -fill y -padx 2 -pady 2
2807     $w.top.use.scroll config -command "$w.top.use.list yview"
2808
2809     use-attr 1
2810
2811     # Relation Attributes
2812
2813     pack $w.top.relation -pady 6 -padx 6 -side top
2814     label $w.top.relation.label -text "Relation" -width 18
2815     
2816     pack $w.top.relation.label $w.top.relation.b -fill x 
2817
2818     # Position Attributes
2819
2820     pack $w.top.position -pady 6 -padx 6 -side top
2821     label $w.top.position.label -text "Position" -width 18
2822
2823     pack $w.top.position.label $w.top.position.b -fill x
2824
2825     # Structure Attributes
2826
2827     pack $w.top.structure -pady 6 -padx 6 -side top
2828     label $w.top.structure.label -text "Structure" -width 18
2829
2830     pack $w.top.structure.label $w.top.structure.b -fill x
2831
2832     # Truncation Attributes
2833
2834     pack $w.top.truncation -pady 6 -padx 6 -side top
2835     label $w.top.truncation.label -text "Truncation" -width 18
2836
2837     pack $w.top.truncation.label $w.top.truncation.b -fill x
2838
2839     # Completeness Attributes
2840
2841     pack $w.top.completeness -pady 6 -padx 6 -side top
2842     label $w.top.completeness.label -text "Completeness" -width 18
2843
2844     pack $w.top.completeness.label $w.top.completeness.b -fill x
2845
2846     # Ok-cancel
2847     bottom-buttons $w [list \
2848             {Ok} [list index-setup-action $attr $queryNo $indexNo] \
2849             {Cancel} [list destroy $w]] 0
2850
2851 }
2852
2853 # Procedure query-edit-index {queryNo}
2854 #  queryNo     query number
2855 # Determines if a selection of an index is active. If one is selected
2856 # the index-setup dialog is started.
2857 proc query-edit-index {queryNo} {
2858     global queryInfoTmp
2859     set w .query-setup
2860
2861     set i [lindex [$w.top.index.list curselection] 0]
2862     if {![string length $i]} {
2863         return
2864     }
2865     set attr [lindex $queryInfoTmp $i]
2866     dputs "Editing no $i $attr"
2867     index-setup $attr $queryNo $i
2868 }
2869
2870 # Procedure query-delete-index {queryNo}
2871 #  queryNo     query number
2872 # Determines if a selection of an index is active. If one is selected
2873 # the index is deleted.
2874 proc query-delete-index {queryNo} {
2875     global queryInfoTmp queryButtonsTmp
2876     set w .query-setup
2877
2878     set i [lindex [$w.top.index.list curselection] 0]
2879     if {![string length $i]} {
2880         return
2881     }
2882     set queryInfoTmp [lreplace $queryInfoTmp $i $i]
2883     index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2884     $w.top.index.list delete $i
2885 }
2886     
2887 # Procedure query-setup {queryNo}
2888 #  queryNo     query number
2889 # Makes a dialog in which a query type an be customized.
2890 proc query-setup {queryNo} {
2891     set w .query-setup
2892
2893     global queryTypes queryButtons queryInfo queryButtonsTmp queryInfoTmp queryIndexTmp
2894     
2895     set queryIndexTmp 0
2896     set queryName [lindex $queryTypes $queryNo]
2897     set queryInfoTmp [lindex $queryInfo $queryNo]
2898     set queryButtonsTmp [lindex $queryButtons $queryNo]
2899
2900     toplevelG $w
2901
2902     wm minsize $w 0 0
2903     wm title $w "Query setup $queryName"
2904
2905     top-down-window $w
2906
2907     frame $w.top.lines -relief ridge -border 2
2908     pack $w.top.lines -side left -pady 6 -padx 6 -fill y
2909
2910     # Index Lines
2911
2912     index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
2913
2914     button $w.top.lines.add -text "Add" -command [list query-add-line $queryNo]
2915     button $w.top.lines.del -text "Remove" -command [list query-del-line $queryNo]
2916     pack $w.top.lines.del -fill x -side bottom
2917     pack $w.top.lines.add -fill x -pady 10 -side bottom
2918
2919     # Indexes
2920
2921     frame $w.top.index -relief ridge -border 2
2922     pack $w.top.index -pady 6 -padx 6 -side right -fill y
2923
2924     listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
2925     scrollbar $w.top.index.scroll -orient vertical -border 1 \
2926         -command [list $w.top.index.list yview]
2927     bind $w.top.index.list <Double-1> [list query-edit-index $queryNo]
2928
2929     pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
2930     pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
2931
2932     $w.top.index.list selection clear 0 end
2933     $w.top.index.list selection set 0 0
2934     foreach x $queryInfoTmp {
2935     $w.top.index.list insert end [lindex $x 0]
2936     }
2937
2938     # Bottom
2939     bottom-buttons $w [list \
2940             Ok [list query-setup-action $queryNo] \
2941             Add [list query-add-index $queryNo] \
2942             Edit [list query-edit-index $queryNo] \
2943             Delete [list query-delete-index $queryNo] \
2944             Cancel [list destroy $w]] 0
2945 }
2946
2947 # Procedure index-clear
2948 # Handler that clears the search entry fields.
2949 proc index-clear {} {
2950     global queryButtonsFind
2951
2952     set i 0
2953     foreach b $queryButtonsFind {
2954         .lines.$i.e delete 0 end
2955         incr i
2956     }
2957 }
2958
2959 # Procedure index-query
2960 # The purpose of this function is to read the user's query and convert
2961 # it to the prefix query that IrTcl/YAZ uses to represent an RPN query.
2962 # Each entry in a search fields takes the form
2963 #    [relOp][?]term[?]
2964 #  Here, relOp is an optional relational operator and one of:
2965 #      >  < >= <=  <>
2966 #    which sets the Bib-1 relation to greater-than, less-than, etc.
2967 #  The ? (question-mark) is also optional. A (?) on left-side indicates
2968 #    left truncation; (?) on right-side indicates right-truncation; (?)
2969 #    on both sides indicates both-left-and-right truncation.
2970 proc index-query {} {
2971     global queryButtonsFind queryInfoFind
2972
2973     set i 0
2974     set qs {}
2975
2976     foreach b $queryButtonsFind {
2977         set term [string trim [.lines.$i.e get]]
2978         if {$term != ""} {
2979             set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
2980
2981             set relation ""
2982             set len [string length $term]
2983             incr len -1
2984
2985             if {$len > 1} {
2986                 if {[string index $term 0] == ">"} {
2987                     if {[string index $term 1] == "=" } {
2988                         set term [string trim [string range $term 2 $len]]
2989                         set relation 4
2990                     } else {
2991                         set term [string trim [string range $term 1 $len]]
2992                         set relation 5
2993                     }
2994                 } elseif {[string index $term 0] == "<"} {
2995                     if {[string index $term 1] == "=" } {
2996                         set term [string trim [string range $term 2 $len]]
2997                         set relation 2
2998                     } elseif {[string index $term 1] == ">"} {
2999                         set term [string trim [string range $term 2 $len]]
3000                         set relation 6
3001                     } else {
3002                         set term [string trim [string range $term 1 $len]]
3003                         set relation 1
3004                     }
3005                 }
3006             } 
3007             set len [string length $term]
3008             incr len -1
3009             set left 0
3010             set right 0
3011             if {[string index $term $len] == "?"} {
3012                 set right 1
3013                 set term [string range $term 0 [expr $len - 1]]
3014             }
3015             if {[string index $term 0] == "?"} {
3016                 set left 1
3017                 set term [string range $term 1 end]
3018             }
3019             set term "\{${term}\}"
3020             if {$right && $left} {
3021                 set term "@attr 5=3 ${term}"
3022             } elseif {$right} {
3023                 set term "@attr 5=1 ${term}"
3024             } elseif {$left} {
3025                 set term "@attr 5=2 ${term}"
3026             }
3027             if {$relation != ""} {
3028                 set term "@attr 2=${relation} ${term}"
3029             }
3030             foreach a $attr {
3031                 set term "@attr $a ${term}"
3032             }
3033             if {$qs != ""} {
3034                 set qs "@and ${qs} ${term}"
3035             } else {
3036                 set qs $term
3037             }
3038         }
3039         incr i
3040     }
3041     dputs "qs=  $qs"
3042     return $qs
3043 }
3044
3045 # Procedure index-focus-in {w i}
3046 #  w    index frame
3047 #  i    index number
3048 # This procedure handles <FocusIn> events. A red border is drawed
3049 # around the active search entry field when tk3.6 is used (tk4.X
3050 # makes a black focus border itself).
3051 proc index-focus-in {w i} {
3052     global curIndexEntry
3053     $w.$i configure -background red
3054     set curIndexEntry $i
3055 }
3056
3057 # Procedure index-lines {w readOp buttonInfo queryInfo handle}
3058 #  w          search fields entry frame
3059 #  realOp     if true, search-request bindings are bound to the entries.
3060 #  buttonInfo query type button information
3061 #  queryInfo  query type field information
3062 #  handle     handler called a when a 'listbutton' changes its value
3063 # Makes one or more search areas - with listbuttons on the left
3064 # and entries on the right. 
3065 proc index-lines {w realOp buttonInfo queryInfo handle} {
3066     set i 0
3067     foreach b $buttonInfo {
3068         if {! [winfo exists $w.$i]} {
3069             frame $w.$i -border 0
3070         }
3071         listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
3072
3073         if {$realOp} {
3074             if {! [winfo exists $w.$i.e]} {
3075                 entry $w.$i.e -width 32 -relief sunken -border 1
3076                 bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
3077                                 bind $w.$i.e <FocusOut> [list $w.$i configure -background white]
3078                 pack $w.$i.l -side left
3079                 pack $w.$i.e -side left -fill x -expand yes
3080                 pack $w.$i -side top -fill x -padx 2 -pady 2
3081                 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
3082                 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
3083                 bind $w.$i.e <Return> {search-request 0}
3084             }
3085         } else {
3086             pack $w.$i.l -side left
3087             pack $w.$i -side top -fill x -padx 2 -pady 2
3088         }
3089         incr i
3090     }
3091     set j $i
3092     while {[winfo exists $w.$j]} {
3093         destroy $w.$j
3094         incr j
3095     }
3096     if {! $realOp} {
3097         return
3098     }
3099     set j 0
3100     incr i -1
3101     while {$j < $i} {
3102         set k [expr $j+1]
3103         bind $w.$j.e <Tab> "focus $w.$k.e"
3104         set j $k
3105     }
3106     if {$i >= 0} {
3107                 bind $w.$i.e <Tab> "focus $w.0.e"
3108         focus $w.0.e
3109     }
3110 }
3111
3112 # Procedure search-fields {w buttondefs}
3113 #  w           search fields entry frame
3114 #  buttondefs  button definitions
3115 # Makes search entry fields and listbuttons. 
3116 # Note: This procedure is not used elsewhere. The index-lines
3117 #       procedure is used instead.
3118 proc search-fields {w buttondefs} {
3119     set i 0
3120     foreach buttondef $buttondefs {
3121         frame $w.$i -background white
3122         
3123         listbutton $w.$i.l 0 $buttondef
3124         entry $w.$i.e -width 32 -relief sunken
3125         
3126         pack $w.$i.l -side left
3127         pack $w.$i.e -side left -fill x -expand yes
3128         pack $w.$i -side top -fill x -padx 2 -pady 2
3129
3130         bind $w.$i.e <Left> [list left-cursor $w.$i.e]
3131         bind $w.$i.e <Right> [list right-cursor $w.$i.e]
3132
3133         incr i
3134     }
3135     set j 0
3136     incr i -1
3137     while {$j < $i} {
3138         set k [expr $j+1]
3139         bind $w.$j.e <Tab> "focus $w.$k.e \n
3140         $w.$k configure -background red \n
3141         $w.$j configure -background white"
3142         set j $k
3143     }
3144     bind $w.$i.e <Tab> "focus $w.0.e \n
3145         $w.0 configure -background red \n
3146         $w.$i configure -background white"
3147     focus $w.0.e
3148     $w.0 configure -background red
3149 }
3150
3151 #Procedure configureOptionsSyntax {target base}
3152 #target         target name
3153 #base           database name
3154 #Changes the Options|Syntax menu acording to the information obtained via explain.
3155 proc configureOptionsSyntax {target base} {
3156         global profile syntaxList recordSyntax syntax
3157         set activate 0
3158         set i -1
3159         if {[info exists profile($target,RecordSyntaxes,$base)]} {
3160                 foreach syntax $syntaxList {
3161                         incr i
3162                         if {$syntax == "sep"} {continue}
3163                         .top.options.m.syntax entryconfigure $i -variable 0
3164                         if {[lsearch $profile($target,RecordSyntaxes,$base) $syntax] != -1} {
3165                                 configure-enable-e .top.options.m.syntax $i
3166                                 if {$activate == 0} {
3167                                         .top.options.m.syntax invoke $i
3168                                         set recordSyntax $syntax
3169 #                                       .debug-window.top.t insert end $recordSyntax\n
3170 #                                       .debug-window.top.t insert end $syntax
3171                                         set activate 1
3172                                 }
3173                         } else {
3174                                 configure-disable-e .top.options.m.syntax $i
3175                         }
3176                 }
3177         } else {
3178                 foreach syntax $syntaxList {
3179                         incr i
3180                         if {$syntax == "sep"} {continue}
3181                         configure-enable-e .top.options.m.syntax $i
3182                 }
3183                 .top.options.m.syntax invoke 0
3184         }
3185 }
3186
3187 # Init: The geometry information for the main window is set - either
3188 # to a default value or to the value in windowGeometry(.)
3189 if {[catch {set g $windowGeometry(.)}]} {
3190     wm geometry . 420x340
3191 } else {
3192     wm geometry . $g
3193 }
3194
3195 # Init: Presentation formats are read.
3196 read-formats
3197
3198 # Init: The main window is defined.
3199 frame .top  -border 1 -relief raised
3200 frame .lines  -border 1 -relief raised
3201 frame .mid  -border 1 -relief raised
3202 frame .data -border 1 -relief raised
3203 frame .bot  -border 1 -relief raised
3204 pack .top .lines .mid -side top -fill x
3205 pack .data -side top -fill both -expand yes
3206 pack .bot -fill x
3207
3208 # Init: Definition of File menu.
3209 menubutton .top.file -text File -menu .top.file.m
3210 irmenu .top.file.m
3211 .top.file.m add command -label {Save settings} -command {save-settings}
3212 .top.file.m add separator
3213 .top.file.m add command -label Exit -command {exit-action}
3214
3215 # Init: Definition of Target menu.
3216 menubutton .top.target -text Target -menu .top.target.m
3217 irmenu .top.target.m
3218 .top.target.m add cascade -label Connect -menu .top.target.m.clist
3219 .top.target.m add command -label Disconnect -command {close-target}
3220 .top.target.m add command -label About -command {about-target}
3221 .top.target.m add cascade -label Setup -menu .top.target.m.slist
3222 .top.target.m add command -label {Setup new} -command {define-target-dialog}
3223 .top.target.m add separator
3224 set-target-hotlist 0
3225
3226 configure-disable-e .top.target.m 1
3227 configure-disable-e .top.target.m 2
3228
3229 irmenu .top.target.m.clist
3230 irmenu .top.target.m.slist
3231 cascade-target-list
3232
3233 # Init: Definition of Service menu.
3234 menubutton .top.service -text Service -menu .top.service.m
3235 irmenu .top.service.m
3236 .top.service.m add cascade -label Database -menu .top.service.m.dblist
3237 .top.service.m add cascade -label Present -menu .top.service.m.present
3238 irmenu .top.service.m.present
3239 .top.service.m.present add command -label {10 More} -command [list present-more 10]
3240 .top.service.m.present add command -label All -command [list present-more {}]
3241 .top.service.m add command -label Search -command {search-request 0}
3242 .top.service.m add command -label Scan -command {scan-request}
3243 .top.service.m add command -label Explain -command \
3244     {explain-refresh $hostid {ready-response {}} }
3245
3246 .top.service configure -state disabled
3247
3248 irmenu .top.service.m.dblist
3249
3250 # Init: Definition of Set menu.
3251 menubutton .top.rset -text Set -menu .top.rset.m
3252 irmenu .top.rset.m
3253 .top.rset.m add command -label Load -command {load-set}
3254 .top.rset.m add separator
3255
3256 # Init: Definition of the Options menu.
3257 menubutton .top.options -text Options -menu .top.options.m
3258 irmenu .top.options.m
3259 .top.options.m add cascade -label Query -menu .top.options.m.query
3260 .top.options.m add cascade -label Format -menu .top.options.m.formats
3261 .top.options.m add cascade -label Wrap -menu .top.options.m.wrap
3262 .top.options.m add cascade -label Syntax -menu .top.options.m.syntax
3263 .top.options.m add cascade -label Elements -menu .top.options.m.elements
3264 .top.options.m add radiobutton -label Debug -variable debugMode -value 1
3265
3266 # Init: Definition of the Options|Query menu.
3267 irmenu .top.options.m.query
3268 .top.options.m.query add cascade -label Select -menu .top.options.m.query.clist
3269 .top.options.m.query add cascade -label Edit -menu .top.options.m.query.slist
3270 .top.options.m.query add command -label New -command {query-new}
3271 .top.options.m.query add cascade -label Delete -menu .top.options.m.query.dlist
3272
3273 irmenu .top.options.m.query.slist
3274 irmenu .top.options.m.query.clist
3275 irmenu .top.options.m.query.dlist
3276 cascade-query-list
3277
3278 # Init: Definition of the Options|Formats menu.
3279 irmenu .top.options.m.formats
3280 set i 0
3281 foreach f $displayFormats {
3282     .top.options.m.formats add radiobutton -label $f -value $i \
3283             -command [list set-display-format $i] -variable displayFormat
3284     incr i
3285 }
3286
3287 # Init: Definition of the Options|Wrap menu.
3288 irmenu .top.options.m.wrap
3289 .top.options.m.wrap add radiobutton -label Character \
3290         -value char -variable textWrap -command {set-wrap char}
3291 .top.options.m.wrap add radiobutton -label Word \
3292         -value word -variable textWrap -command {set-wrap word}
3293 .top.options.m.wrap add radiobutton -label None \
3294         -value none -variable textWrap -command {set-wrap none}
3295
3296 # Init: Definition of the Options|Syntax menu.
3297 proc initOptionsSyntax {} {
3298         global syntaxList 
3299         set w .top.options.m.syntax
3300         irmenu $w
3301         foreach syntax $syntaxList {
3302                 if {$syntax == "sep"} {
3303                         $w add separator
3304                 } else {
3305                         $w add radiobutton -label $syntax -value $syntax -variable recordSyntax
3306                 }
3307         }
3308 }
3309 initOptionsSyntax
3310
3311 # Init: Definition of the Options|Elements menu.
3312 irmenu .top.options.m.elements
3313 .top.options.m.elements add radiobutton -label Unspecified \
3314         -value None -variable elementSetNames
3315 .top.options.m.elements add radiobutton -label Full \
3316         -value F -variable elementSetNames
3317 .top.options.m.elements add radiobutton -label Brief -value B -variable elementSetNames
3318
3319 # Init: Definition of Help menu.
3320 menubutton .top.help -text "Help" -menu .top.help.m
3321 irmenu .top.help.m
3322
3323 .top.help.m add command -label "Help on help" \
3324         -command {tkerror "Help on help not available. Sorry"}
3325 .top.help.m add command -label "About" -command {about-origin}
3326
3327 # Init: Pack menu bar items.
3328 pack .top.file .top.target .top.service .top.rset .top.options -side left
3329 pack .top.help -side right
3330
3331 # Init: Define query area.
3332 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
3333 image create photo scan -file ${libdir}/bitmaps/a-z.gif
3334 image create photo clear -file ${libdir}/bitmaps/trash.gif
3335 image create photo present -file ${libdir}/bitmaps/page.gif
3336 image create photo search -file ${libdir}/bitmaps/search.gif
3337 button .mid.search -image search -command {search-request 0} -state disabled -relief flat
3338 button .mid.scan -image scan -command scan-request -state disabled -relief flat
3339 button .mid.present -image present -command [list present-more 10] -state disabled -relief flat
3340 button .mid.clear -image clear -command index-clear -relief flat
3341 pack .mid.search .mid.scan .mid.present .mid.clear -side left -fill y -pady 1
3342
3343 # Init: Define record area in main window.
3344 text .data.record -font fixed -height 2 -width 20 -wrap none -borderwidth 0 \
3345         -relief flat -yscrollcommand [list .data.scroll set] -wrap $textWrap
3346 scrollbar .data.scroll -command [list .data.record yview]
3347 .data.record configure -takefocus 0
3348 .data.scroll configure -takefocus 0
3349
3350 pack .data.scroll -side right -fill y
3351 pack .data.record -expand yes -fill both
3352 initBindings
3353
3354 # Init: Define standards tags. These are used in the display
3355 # format procedures.
3356
3357 .data.record tag configure marc-tag -foreground blue
3358 .data.record tag configure marc-id -foreground red
3359 .data.record tag configure marc-data -foreground black
3360 .data.record tag configure marc-head -font $font(n,normal) \
3361         -foreground brown -relief raised -borderwidth 1
3362 .data.record tag configure marc-small-head -foreground brown
3363 .data.record tag configure marc-pref -font $font(n,normal) -foreground blue
3364 .data.record tag configure marc-text -font $font(n,normal) -foreground black
3365 .data.record tag configure marc-it -font $font(n,normal) -foreground black
3366
3367 # Init: Define logo.
3368 button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
3369 .bot.logo configure -takefocus 0
3370
3371 # Init: Define status information fields at the bottom.
3372 frame .bot.a
3373 pack .bot.a -side left -fill x
3374 pack .bot.logo -side right -padx 2 -pady 2 -ipadx 1
3375
3376 message .bot.a.target -text {} -aspect 2000 -border 1
3377
3378 label .bot.a.status -text "Not connected" -width 15 -relief sunken -anchor w -border 1
3379 label .bot.a.set -text "" -width 5 -relief sunken -anchor w -border 1
3380 label .bot.a.message -text "" -width 15 -relief sunken -anchor w -border 1
3381
3382 pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
3383 pack .bot.a.status .bot.a.set .bot.a.message -side left -padx 2 -pady 2 -ipadx 1 -ipady 1
3384
3385 # Init: Determine if the IrTcl extension is already there. If
3386 #  not, then dynamically load the IrTcl extension.
3387 if {[catch {ir z39}]} {
3388     set e [info sharedlibextension]
3389     puts -nonewline "Loading irtcl$e ..."
3390     load ${libdir}/irtcl$e irtcl
3391     ir z39
3392     puts "ok"
3393 }
3394
3395 if {[file exists ${libdir}/explain.tcl]} {
3396     source ${libdir}/explain.tcl
3397 }
3398
3399 #if {[file exists ${libdir}/setup.tcl]} 
3400     source ${libdir}/setup.tcl
3401
3402
3403 # Init: Uncomment this line if you wan't to enable logging.
3404 ir-log-init all irtcl irtcl.log
3405
3406 # Init: If hostid is a valid target, a new connection will be established
3407 # immediately.
3408 if {[string compare $hostid Default]} {
3409     catch {open-target $hostid $hostbase}
3410 }
3411
3412 # Init: Enable the logo.
3413 show-logo 1
3414