+ set settingsChanged 1
+
+ set queryTypes [lreplace $queryTypes $queryNo $queryNo]
+ set queryButtons [lreplace $queryButtons $queryNo $queryNo]
+ set queryInfo [lreplace $queryInfo $queryNo $queryNo]
+ destroy .query-delete
+ cascade-query-list
+}
+
+proc query-delete {queryNo} {
+ global queryTypes
+
+ set w .query-delete
+
+ toplevel $w
+ place-force $w .
+ top-down-window $w
+ set n [lindex $queryTypes $queryNo]
+
+ label $w.top.warning -bitmap warning
+ message $w.top.quest -text "Are you sure you want to delete the \
+query type $n ?" -aspect 300
+ pack $w.top.warning $w.top.quest -side left -expand yes -padx 10 -pady 5
+ bottom-buttons $w [list {Ok} [list query-delete-action $queryNo] \
+ {Cancel} [list destroy $w]] 1
+}
+
+proc cascade-query-list {} {
+ global queryTypes
+ set w .top.options.m.query
+
+ set i 0
+ $w.slist delete 0 last
+ foreach n $queryTypes {
+ $w.slist add command -label $n -command [list query-setup $i]
+ incr i
+ }
+
+ set i 0
+ $w.clist delete 0 last
+ foreach n $queryTypes {
+ $w.clist add command -label $n -command [list query-select $i]
+ incr i
+ }
+ set i 0
+ $w.dlist delete 0 last
+ foreach n $queryTypes {
+ $w.dlist add command -label $n -command [list query-delete $i]
+ incr i
+ }
+}
+
+proc save-geometry {} {
+ global windowGeometry
+ global hotTargets
+ global textWrap
+ global displayFormat
+ global popupMarcdf
+ global recordSyntax
+
+ set windowGeometry(.) [wm geometry .]
+
+ if {[catch {set f [open ~/.clientrc.tcl w]}]} {
+ return
+ }
+ puts $f "set hotTargets \{ $hotTargets \}"
+ puts $f "set textWrap $textWrap"
+ puts $f "set displayFormat $displayFormat"
+ puts $f "set popupMarcdf $popupMarcdf"
+ puts $f "set recordSyntax $recordSyntax"
+ foreach n [array names windowGeometry] {
+ puts -nonewline $f "set \{windowGeometry($n)\} \{"
+ puts -nonewline $f $windowGeometry($n)
+ puts $f "\}"
+ }
+ close $f
+}
+
+proc save-settings {} {
+ global profile
+ global libdir
+ global settingsChanged
+ global queryTypes
+ global queryButtons
+ global queryInfo
+
+ if {![file writable "${libdir}/clientrc.tcl"]} {
+ set a [alert "Cannot open ${libdir}/clientrc.tcl for writing. Do you \
+ wish to save clientrc.tcl in the current directory instead?"]
+ if {! $a} {
+ return
+ }
+ set f [open "clientrc.tcl" w]
+ } else {
+ set f [open "${libdir}/clientrc.tcl" w]
+ }
+ puts $f "# Setup file"
+
+ foreach n [array names profile] {
+ puts -nonewline $f "set \{profile($n)\} \{"
+ puts -nonewline $f $profile($n)
+ puts $f "\}"
+ }
+ puts -nonewline $f "set queryTypes \{"
+ puts -nonewline $f $queryTypes
+ puts $f "\}"
+
+ puts -nonewline $f "set queryButtons \{"
+ puts -nonewline $f $queryButtons
+ puts $f "\}"
+
+ puts -nonewline $f "set queryInfo \{"
+ puts -nonewline $f $queryInfo
+ puts $f "\}"
+ close $f
+ set settingsChanged 0
+}
+
+proc alert {ask} {
+ set w .alert
+
+ global alertAnswer
+
+ toplevel $w
+ set oldFocus [focus]
+ place-force $w .
+ top-down-window $w
+
+ label $w.top.warning -bitmap warning
+ message $w.top.message -text $ask -aspect 300 \
+ -font -Adobe-Times-Medium-R-Normal-*-180-*
+
+ pack $w.top.warning $w.top.message -side left -pady 5 -padx 10 -expand yes
+
+ set alertAnswer 0
+ top-down-ok-cancel $w {alert-action} 1
+ focus $oldFocus
+ return $alertAnswer
+}
+
+proc alert-action {} {
+ global alertAnswer
+ set alertAnswer 1
+ destroy .alert
+}
+
+proc exit-action {} {
+ global settingsChanged
+
+ if {$settingsChanged} {
+ set a [alert "you haven't saved your settings. Do you wish to save?"]
+ if {$a} {
+ save-settings
+ }
+ }
+ save-geometry
+ exit 0
+}
+
+proc listbuttonaction {w name h user i} {
+ $w configure -text [lindex $name 0]
+ $h [lindex $name 1] $user $i
+}
+
+proc listbuttonx {button no names handle user} {
+ if {[winfo exists $button]} {
+ $button configure -text [lindex [lindex $names $no] 0]
+ ${button}.m delete 0 last
+ } else {
+ menubutton $button -text [lindex [lindex $names $no] 0] \
+ -width 10 -menu ${button}.m -relief raised -border 1
+ menu ${button}.m
+ }
+ set i 0
+ foreach name $names {
+ ${button}.m add command -label [lindex $name 0] \
+ -command [list listbuttonaction ${button} $name \
+ $handle $user $i]
+ incr i
+ }
+}
+
+proc listbutton {button no names} {
+ menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
+ -relief raised -border 1
+ menu ${button}.m
+ foreach name $names {
+ ${button}.m add command -label $name \
+ -command [list ${button} configure -text $name]
+ }
+}
+
+proc listbuttonv-action {button var names i} {
+ global $var
+
+ set $var [lindex $names [expr $i+1]]
+ $button configure -text [lindex $names $i]
+}
+
+proc listbuttonv {button var names} {
+ global $var
+
+ set n "-"
+ eval "set val $$var"
+ set l [llength $names]
+ for {set i 1} {$i < $l} {incr i 2} {
+ if {$val == [lindex $names $i]} {
+ incr i -1
+ set n [lindex $names $i]
+ break
+ }
+ }
+ if {[winfo exists $button]} {
+ $button configure -text $n
+ return
+ }
+ menubutton $button -text $n -menu ${button}.m \
+ -relief raised -border 1
+ menu ${button}.m
+ for {set i 0} {$i < $l} {incr i 2} {
+ ${button}.m add command -label [lindex $names $i] \
+ -command [list listbuttonv-action $button $var $names $i]
+ }
+}
+
+proc query-add-index-action {queryNo} {
+ set w .query-setup
+
+ global queryInfoTmp
+ global queryButtonsTmp
+
+ set newI [.query-add-index.top.index.entry get]
+ lappend queryInfoTmp [list $newI {}]
+ $w.top.index.list insert end $newI
+ destroy .query-add-index
+ #destroy $w.top.lines
+ #frame $w.top.lines -relief ridge -border 2
+ index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
+ #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
+}
+
+proc query-add-line {queryNo} {
+ set w .query-setup
+
+ global queryInfoTmp
+ global queryButtonsTmp
+
+ lappend queryButtonsTmp {I 0}
+
+ #destroy $w.top.lines
+ #frame $w.top.lines -relief ridge -border 2
+ index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
+ #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
+}
+
+proc query-del-line {queryNo} {
+ set w .query-setup
+
+ global queryInfoTmp
+ global queryButtonsTmp
+
+ set l [llength $queryButtonsTmp]
+ if {$l <= 0} {
+ return
+ }
+ incr l -1
+ set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
+ index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
+}
+
+proc query-add-index {queryNo} {
+ set w .query-add-index
+
+ toplevel $w
+ set oldFocus [focus]
+ place-force $w .query-setup
+ top-down-window $w
+ frame $w.top.index
+ pack $w.top.index \
+ -side top -anchor e -pady 2
+ entry-fields $w.top {index} \
+ {{Index Name:}} \
+ [list query-add-index-action $queryNo] [list destroy $w]
+ top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
+ focus $oldFocus
+}
+
+proc query-setup-action {queryNo} {
+ global queryButtons
+ global queryInfo
+ global queryButtonsTmp
+ global queryInfoTmp
+ global queryButtonsFind
+ global queryInfoFind
+
+ global settingsChanged
+
+ set settingsChanged 1
+
+ set queryInfo [lreplace $queryInfo $queryNo $queryNo \
+ $queryInfoTmp]
+ set queryButtons [lreplace $queryButtons $queryNo $queryNo \
+ $queryButtonsTmp]
+ set queryInfoFind $queryInfoTmp
+ set queryButtonsFind $queryButtonsTmp
+
+ destroy .query-setup
+ index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
+}
+
+proc activate-e-index {value no i} {
+ global queryButtonsTmp
+ global queryIndexTmp
+
+ set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
+ dputs $queryButtonsTmp
+ set queryIndexTmp $i
+}
+
+proc activate-index {value no i} {
+ global queryButtonsFind
+
+ set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
+
+ dputs "queryButtonsFind $queryButtonsFind"
+}
+
+proc update-attr {} {
+ set w .index-setup
+ listbuttonv $w.top.relation.b relationTmpValue\
+ {{None} 0 {Less than} 1 {Greater than or equal} 2 {Equal} 3 \
+ {Greater than or equal} 4 {Greater than} 5 {Not equal} 6 \
+ {Phonetic} 100 {Stem} 101 {Relevance} 102 {AlwaysMatches} 103}
+ listbuttonv $w.top.position.b positionTmpValue {{None} 0 \
+ {First in field} 1 {First in subfield} 2 {Any position in field} 3}
+ listbuttonv $w.top.structure.b structureTmpValue {{None} 0 {Phrase} 1 \
+ {Word} 2 {Key} 3 {Year} 4 {Date (norm)} 5 {Word list} 6 \
+ {Date (un-norm)} 100 {Name (norm)} 101 {Date (un-norm)} 102 \
+ {Structure} 103 {urx} 104 {free-form} 105 {doc-text} 106 \
+ {local-number} 107 {string} 108 {numeric string} 109}
+ listbuttonv $w.top.truncation.b truncationTmpValue {{Auto} 0 {Right} 1 \
+ {Left} 2 {Left and right} 3 {No truncation} 100 \
+ {Process #} 101 {Re-1} 102 {Re-2} 103}
+ listbuttonv $w.top.completeness.b completenessTmpValue {{None} 0 \
+ {Incomplete subfield} 1 {Complete subfield} 2 {Complete field} 3}
+}
+
+proc use-attr {init} {
+ set attr {
+ {None} 0
+ {Personal name} 1
+ {Corporate name} 2
+ {Conference name} 3
+ {Title} 4
+ {Title-series} 5
+ {Title-uniform} 6
+ {ISBN} 7
+ {ISSN} 8
+ {LC card number} 9
+ {BNB card number} 10
+ {BGF(sic) number} 11
+ {Local number} 12
+ {Dewey classification} 13
+ {UDC classification} 14
+ {Bliss classification} 15
+ {LC call number} 16
+ {NLM call number} 17
+ {NAL call number} 18
+ {MOS call number} 19
+ {Local classification} 20
+ {Subject heading} 21
+ {Subject-RAMEAU} 22
+ {BDI-index-subject} 23
+ {INSPEC-subject} 24
+ {MESH-subject} 25
+ {PA-subject} 26
+ {LC-subject-heading} 27
+ {RVM-subject-heading} 28
+ {Local subject index} 29
+ {Date} 30
+ {Date of publication} 31
+ {Date of acquisition} 32
+ {Title-key} 33
+ {Title-collective} 34
+ {Title-parallel} 35
+ {Title-cover} 36
+ {Title-added-title-page} 37
+ {Title-caption} 38
+ {Title-running} 39
+ {Title-spine} 40
+ {Title-other-variant} 41
+ {Title-former} 42
+ {Title-abbreviated} 43
+ {Title-expanded} 44
+ {Subject-PRECIS} 45
+ {Subject-RSWK} 46
+ {Subject-subdivision} 47
+ {Number-natl-bibliography} 48
+ {Number-legal-deposit} 49
+ {Number-govt-publication} 50
+ {Number-publisher-for-music} 51
+ {Number-DB} 52
+ {Number-local-call} 53
+ {Code-language} 54
+ {Code-geographic-area} 55
+ {Code-institution} 56
+ {Name and title} 57
+ {Name-geographic} 58
+ {Place-publication} 59
+ {CODEN} 60
+ {Microform-generation} 61
+ {Abstract} 62
+ {Note} 63
+ {Author-title} 1000
+ {Record type} 1001
+ {Name} 1002
+ {Author} 1003
+ {Author-name-personal} 1004
+ {Author-name-corporate} 1005
+ {Author-name-conference} 1006
+ {Identifier-standard} 1007
+ {Subject-LC-children's} 1008
+ {Subject-name-personal} 1009
+ {Body of text} 1010
+ {Date/time added to database} 1011
+ {Date/time last modified} 1012
+ {Authority/format identifier} 1013
+ {Concept-text} 1014
+ {Concept-reference} 1015
+ {Any} 1016
+ {Server choice} 1017
+ {Publisher} 1018
+ {Record source} 1019
+ {Editor} 1020
+ {Bib-level} 1021
+ {Geographic class} 1022
+ {Indexed by} 1023
+ {Map scale} 1024
+ {Music key} 1025
+ {Related periodical} 1026
+ {Report number} 1027
+ {Stock number} 1028
+ {Thematic number} 1030
+ {Material type} 1031
+ {Doc ID} 1032
+ {Host item} 1033
+ {Content type} 1034
+ {Anywhere} 1035
+ }
+ set w .index-setup
+ global useTmpValue
+ set l [llength $attr]
+
+ if {$init} {
+ set s 0
+ set lno 0
+ for {set i 0} {$i < $l} {incr i} {
+ $w.top.use.list insert end [lindex $attr $i]
+ incr i
+ if {$useTmpValue == [lindex $attr $i]} {
+ set s $lno
+ }
+ incr lno
+ }
+ if {[tk4]} {
+ $w.top.use.list selection clear 0 end
+ $w.top.use.list selection set $s $s
+ } else {
+ $w.top.use.list select from $s
+ $w.top.use.list select to $s
+ }
+ incr s -3
+ if {$s < 0} {
+ set s 0
+ }
+ $w.top.use.list yview $s
+ } else {
+ set lno [lindex [$w.top.use.list curselection] 0]
+ set i [expr $lno+$lno+1]
+ set useTmpValue [lindex $attr $i]
+ dputs "useTmpValue=$useTmpValue"
+ }
+}
+
+proc index-setup-action {oldAttr queryNo indexNo} {
+ set attr [lindex $oldAttr 0]
+
+ global useTmpValue
+ global relationTmpValue
+ global structureTmpValue
+ global truncationTmpValue
+ global completenessTmpValue
+ global positionTmpValue
+ global queryInfoTmp
+
+ use-attr 0
+
+ dputs "index-setup-action"
+ dputs "queryNo $queryNo"
+ dputs "indexNo $indexNo"
+ if {$useTmpValue > 0} {
+ lappend attr "1=$useTmpValue"
+ }
+ if {$relationTmpValue > 0} {
+ lappend attr "2=$relationTmpValue"
+ }
+ if {$positionTmpValue > 0} {
+ lappend attr "3=$positionTmpValue"
+ }
+ if {$structureTmpValue > 0} {
+ lappend attr "4=$structureTmpValue"
+ }
+ if {$truncationTmpValue > 0} {
+ lappend attr "5=$truncationTmpValue"
+ }
+ if {$completenessTmpValue > 0} {
+ lappend attr "6=$completenessTmpValue"
+ }
+ dputs "new attr $attr"
+ set queryInfoTmp [lreplace $queryInfoTmp $indexNo $indexNo $attr]
+ destroy .index-setup
+}
+
+proc index-setup {attr queryNo indexNo} {
+ set w .index-setup
+
+ global relationTmpValue
+ global structureTmpValue
+ global truncationTmpValue
+ global completenessTmpValue
+ global positionTmpValue
+ global useTmpValue
+ set relationTmpValue 0
+ set truncationTmpValue 0
+ set structureTmpValue 0
+ set positionTmpValue 0
+ set completenessTmpValue 0
+ set useTmpValue 0
+
+ set len [llength $attr]
+ for {set i 1} {$i < $len} {incr i} {
+ set q [lindex $attr $i]
+ set l [string first = $q]
+ if {$l > 0} {
+ set t [string range $q 0 [expr $l - 1]]
+ set v [string range $q [expr $l + 1] end]
+ switch $t {
+ 1
+ { set useTmpValue $v }
+ 2
+ { set relationTmpValue $v }
+ 3
+ { set positionTmpValue $v }
+ 4
+ { set structureTmpValue $v }
+ 5
+ { set truncationTmpValue $v }
+ 6
+ { set completenessTmpValue $v }
+ }
+ }
+ }
+ if {[winfo exists $w]} {
+ destroy $w
+ }
+ toplevelG $w
+
+ set n [lindex $attr 0]
+ wm title $w "Index setup $n"
+
+ top-down-window $w
+
+ frame $w.top.use -relief ridge -border 2
+ frame $w.top.relation -relief ridge -border 2
+ frame $w.top.position -relief ridge -border 2
+ frame $w.top.structure -relief ridge -border 2
+ frame $w.top.truncation -relief ridge -border 2
+ frame $w.top.completeness -relief ridge -border 2
+
+ update-attr
+
+ # Use Attributes
+
+ pack $w.top.use -side left -pady 6 -padx 6 -fill y
+
+ label $w.top.use.label -text "Use"
+ if {[tk4]} {
+ listbox $w.top.use.list -width 26 \
+ -yscrollcommand "$w.top.use.scroll set"
+ } else {
+ listbox $w.top.use.list -geometry 26x10 \
+ -yscrollcommand "$w.top.use.scroll set"
+ }
+ scrollbar $w.top.use.scroll -orient vertical -border 1
+ pack $w.top.use.label -side top -fill x \
+ -padx 2 -pady 2
+ pack $w.top.use.list -side left -fill both -expand yes \
+ -padx 2 -pady 2
+ pack $w.top.use.scroll -side right -fill y \
+ -padx 2 -pady 2
+ $w.top.use.scroll config -command "$w.top.use.list yview"
+
+ use-attr 1
+
+ # Relation Attributes
+
+ pack $w.top.relation -pady 6 -padx 6 -side top
+ label $w.top.relation.label -text "Relation" -width 18
+
+ pack $w.top.relation.label $w.top.relation.b -fill x
+
+ # Position Attributes
+
+ pack $w.top.position -pady 6 -padx 6 -side top
+ label $w.top.position.label -text "Position" -width 18
+
+ pack $w.top.position.label $w.top.position.b -fill x
+
+ # Structure Attributes
+
+ pack $w.top.structure -pady 6 -padx 6 -side top
+ label $w.top.structure.label -text "Structure" -width 18
+
+ pack $w.top.structure.label $w.top.structure.b -fill x
+
+ # Truncation Attributes
+
+ pack $w.top.truncation -pady 6 -padx 6 -side top
+ label $w.top.truncation.label -text "Truncation" -width 18
+
+ pack $w.top.truncation.label $w.top.truncation.b -fill x
+
+ # Completeness Attributes
+
+ pack $w.top.completeness -pady 6 -padx 6 -side top
+ label $w.top.completeness.label -text "Completeness" -width 18
+
+ pack $w.top.completeness.label $w.top.completeness.b -fill x
+
+ # Ok-cancel
+ bottom-buttons $w [list \
+ {Ok} [list index-setup-action $attr $queryNo $indexNo] \
+ {Cancel} [list destroy $w]] 0
+
+}
+
+proc query-edit-index {queryNo} {
+ global queryInfoTmp
+ set w .query-setup
+
+ set i [lindex [$w.top.index.list curselection] 0]
+ if {$i == ""} {
+ return
+ }
+ set attr [lindex $queryInfoTmp $i]
+ dputs "Editing no $i $attr"
+ index-setup $attr $queryNo $i
+}
+
+proc query-delete-index {queryNo} {
+ global queryInfoTmp
+ global queryButtonsTmp
+ set w .query-setup
+
+ set i [lindex [$w.top.index.list curselection] 0]
+ if {$i == ""} {
+ return
+ }
+ set queryInfoTmp [lreplace $queryInfoTmp $i $i]
+ index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
+ $w.top.index.list delete $i
+}
+
+proc query-setup {queryNo} {
+ set w .query-setup
+
+ global queryTypes
+ global queryButtons
+ global queryInfo
+ global queryButtonsTmp
+ global queryInfoTmp
+ global queryIndexTmp
+
+ set queryIndexTmp 0
+ set queryName [lindex $queryTypes $queryNo]
+ set queryInfoTmp [lindex $queryInfo $queryNo]
+ set queryButtonsTmp [lindex $queryButtons $queryNo]
+
+ toplevelG $w
+
+ wm minsize $w 0 0
+ wm title $w "Query setup $queryName"
+
+ top-down-window $w
+
+ frame $w.top.lines -relief ridge -border 2
+
+ pack $w.top.lines -side left -pady 6 -padx 6 -fill y
+
+ # Index Lines
+
+ index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
+
+ button $w.top.lines.add -text "Add" \
+ -command [list query-add-line $queryNo]
+ button $w.top.lines.del -text "Remove" \
+ -command [list query-del-line $queryNo]
+
+ pack $w.top.lines.del -fill x -side bottom
+ pack $w.top.lines.add -fill x -pady 10 -side bottom
+
+ # Indexes
+
+ frame $w.top.index -relief ridge -border 2
+ pack $w.top.index -pady 6 -padx 6 -side right -fill y
+
+ listbox $w.top.index.list -yscrollcommand [list $w.top.index.scroll set]
+ scrollbar $w.top.index.scroll -orient vertical -border 1 \
+ -command [list $w.top.index.list yview]
+ bind $w.top.index.list <2> [list query-edit-index $queryNo]
+
+ pack $w.top.index.list -side left -fill both -expand yes -padx 2 -pady 2
+ pack $w.top.index.scroll -side right -fill y -padx 2 -pady 2
+
+ if {[tk4]} {
+ $w.top.index.list selection clear 0 end
+ $w.top.index.list selection set 0 0
+ } else {
+ $w.top.index.list select from 0
+ $w.top.index.list select to 0
+ }
+
+ foreach x $queryInfoTmp {
+ $w.top.index.list insert end [lindex $x 0]
+ }
+ # Bottom
+ bottom-buttons $w [list \
+ {Ok} [list query-setup-action $queryNo] \
+ {Add index} [list query-add-index $queryNo] \
+ {Edit index} [list query-edit-index $queryNo] \
+ {Delete index} [list query-delete-index $queryNo] \
+ {Cancel} [list destroy $w]] 0
+}
+
+proc index-clear {} {
+ global queryButtonsFind
+
+ set i 0
+ foreach b $queryButtonsFind {
+ .lines.$i.e delete 0 end
+ incr i
+ }
+}
+
+proc index-query {} {
+ global queryButtonsFind
+ global queryInfoFind
+
+ set i 0
+ set qs {}
+
+ foreach b $queryButtonsFind {
+ set term [string trim [.lines.$i.e get]]
+ if {$term != ""} {
+ set attr [lrange [lindex $queryInfoFind [lindex $b 1]] 1 end]
+
+ set len [string length $term]
+ incr len -1
+ set left 0
+ set right 0
+ if {[string index $term $len] == "?"} {
+ set right 1
+ set term [string range $term 0 [expr $len - 1]]
+ }
+ if {[string index $term 0] == "?"} {
+ set left 1
+ set term [string range $term 1 end]
+ }
+ set term "\{${term}\}"
+ if {$right && $left} {
+ set term "@attr 5=3 ${term}"
+ } elseif {$right} {
+ set term "@attr 5=1 ${term}"
+ } elseif {$left} {
+ set term "@attr 5=2 ${term}"
+ }
+ foreach a $attr {
+ set term "@attr $a ${term}"
+ }
+ if {$qs != ""} {
+ set qs "@and ${qs} ${term}"
+ } else {
+ set qs $term
+ }
+ }
+ incr i
+ }
+ dputs "qs= $qs"
+ return $qs
+}
+
+proc index-focus-in {w i} {
+ global curIndexEntry
+
+ if {! [tk4]} {
+ $w.$i configure -background red
+ }
+ set curIndexEntry $i
+}
+
+proc index-lines {w realOp buttonInfo queryInfo handle} {
+ set i 0
+ foreach b $buttonInfo {
+ if {! [winfo exists $w.$i]} {
+ if {[tk4]} {
+ frame $w.$i -border 0
+ } else {
+ frame $w.$i -background white -border 1
+ }
+ }
+ listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
+
+ if {$realOp} {
+ if {! [winfo exists $w.$i.e]} {
+ entry $w.$i.e -width 32 -relief sunken -border 1
+ bind $w.$i.e <FocusIn> [list index-focus-in $w $i]
+ bind $w.$i.e <FocusOut> [list $w.$i configure \
+ -background white]
+ pack $w.$i.l -side left
+ pack $w.$i.e -side left -fill x -expand yes
+ pack $w.$i -side top -fill x -padx 2 -pady 2
+ if {![tk4]} {
+ bind $w.$i.e <Left> [list left-cursor $w.$i.e]
+ bind $w.$i.e <Right> [list right-cursor $w.$i.e]
+ }
+ bind $w.$i.e <Return> {search-request 0}
+ }
+ } else {
+ pack $w.$i.l -side left
+ pack $w.$i -side top -fill x -padx 2 -pady 2
+ }
+ incr i
+ }
+ set j $i
+ while {[winfo exists $w.$j]} {
+ destroy $w.$j
+ incr j
+ }
+ if {! $realOp} {
+ return
+ }
+ if {! [tk4]} {
+ set j 0
+ incr i -1
+ while {$j < $i} {
+ set k [expr $j+1]
+ bind $w.$j.e <Tab> "focus $w.$k.e"
+ set j $k
+ }
+ }
+ if {$i >= 0} {
+ if {! [tk4]} {
+ bind $w.$i.e <Tab> "focus $w.0.e"
+ }
+ focus $w.0.e
+ }
+}
+
+proc search-fields {w buttondefs} {
+ set i 0
+ foreach buttondef $buttondefs {
+ frame $w.$i -background white
+
+ listbutton $w.$i.l 0 $buttondef
+ entry $w.$i.e -width 32 -relief sunken
+
+ pack $w.$i.l -side left
+ pack $w.$i.e -side left -fill x -expand yes
+
+ pack $w.$i -side top -fill x -padx 2 -pady 2
+
+ bind $w.$i.e <Left> [list left-cursor $w.$i.e]
+ bind $w.$i.e <Right> [list right-cursor $w.$i.e]
+
+ incr i
+ }
+ set j 0
+ incr i -1
+ while {$j < $i} {
+ set k [expr $j+1]
+ bind $w.$j.e <Tab> "focus $w.$k.e \n
+ $w.$k configure -background red \n
+ $w.$j configure -background white"
+ set j $k
+ }
+ bind $w.$i.e <Tab> "focus $w.0.e \n
+ $w.0 configure -background red \n
+ $w.$i configure -background white"
+ focus $w.0.e
+ $w.0 configure -background red
+}
+
+if {[info exists windowGeometry(.)]} {
+ set g $windowGeometry(.)
+ if {$g != ""} {
+ wm geometry . $g
+ }
+}
+
+read-formats
+
+frame .top -border 1 -relief raised
+frame .lines -border 1 -relief raised
+frame .mid -border 1 -relief raised
+frame .data -border 1 -relief raised
+frame .bot -border 1 -relief raised
+pack .top .lines .mid -side top -fill x
+pack .data -side top -fill both -expand yes
+pack .bot -fill x
+
+menubutton .top.file -text "File" -menu .top.file.m
+menu .top.file.m
+.top.file.m add command -label "Save settings" -command {save-settings}
+.top.file.m add separator
+.top.file.m add command -label "Exit" -command {exit-action}
+
+menubutton .top.target -text "Target" -menu .top.target.m
+menu .top.target.m
+.top.target.m add cascade -label "Connect" -menu .top.target.m.clist
+.top.target.m add command -label "Disconnect" -command {close-target}
+.top.target.m add command -label "About" -command {about-target}
+.top.target.m add cascade -label "Setup" -menu .top.target.m.slist
+.top.target.m add command -label "Setup new" -command {define-target-dialog}
+.top.target.m add separator
+set-target-hotlist 0
+
+configure-disable-e .top.target.m 1
+configure-disable-e .top.target.m 2
+
+menu .top.target.m.clist
+menu .top.target.m.slist
+cascade-target-list
+
+menubutton .top.service -text "Service" -menu .top.service.m
+menu .top.service.m
+.top.service.m add command -label "Database" -command {database-select}
+.top.service.m add cascade -label "Present" -menu .top.service.m.present
+menu .top.service.m.present
+.top.service.m.present add command -label "10 More" \
+ -command [list present-more 10]
+.top.service.m.present add command -label "All" \
+ -command [list present-more {}]
+.top.service.m add command -label "Search" -command {search-request 0}
+.top.service.m add command -label "Scan" -command {scan-request}
+
+.top.service configure -state disabled
+
+menubutton .top.rset -text "Set" -menu .top.rset.m
+menu .top.rset.m
+.top.rset.m add command -label "Load" -command {load-set}
+.top.rset.m add separator
+
+menubutton .top.options -text "Options" -menu .top.options.m
+menu .top.options.m
+.top.options.m add cascade -label "Query" -menu .top.options.m.query
+.top.options.m add cascade -label "Format" -menu .top.options.m.formats
+.top.options.m add cascade -label "Wrap" -menu .top.options.m.wrap
+.top.options.m add cascade -label "Syntax" -menu .top.options.m.syntax
+
+menu .top.options.m.query
+.top.options.m.query add cascade -label "Select" \
+ -menu .top.options.m.query.clist
+.top.options.m.query add cascade -label "Edit" \
+ -menu .top.options.m.query.slist
+.top.options.m.query add command -label "New" \
+ -command {query-new}
+.top.options.m.query add cascade -label "Delete" \
+ -menu .top.options.m.query.dlist
+
+menu .top.options.m.query.slist
+menu .top.options.m.query.clist
+menu .top.options.m.query.dlist
+cascade-query-list
+
+menu .top.options.m.formats
+set i 0
+foreach f $displayFormats {
+ .top.options.m.formats add radiobutton -label $f -value $i \
+ -command [list set-display-format $i] -variable displayFormat
+ incr i
+}
+
+menu .top.options.m.wrap
+.top.options.m.wrap add radiobutton -label "Character" \
+ -value char -variable textWrap -command {set-wrap char}
+.top.options.m.wrap add radiobutton -label "Word" \
+ -value word -variable textWrap -command {set-wrap word}
+.top.options.m.wrap add radiobutton -label "None" \
+ -value none -variable textWrap -command {set-wrap none}
+
+menu .top.options.m.syntax
+.top.options.m.syntax add radiobutton -label "None" \
+ -value None -variable recordSyntax
+.top.options.m.syntax add separator
+.top.options.m.syntax add radiobutton -label "USMARC" \
+ -value USMARC -variable recordSyntax
+.top.options.m.syntax add radiobutton -label "UNIMARC" \
+ -value UNIMARC -variable recordSyntax
+.top.options.m.syntax add radiobutton -label "UKMARC" \
+ -value UKMARC -variable recordSyntax
+.top.options.m.syntax add radiobutton -label "DANMARC" \
+ -value DANMARC -variable recordSyntax
+.top.options.m.syntax add radiobutton -label "FINMARC" \
+ -value FINMARC -variable recordSyntax
+.top.options.m.syntax add radiobutton -label "NORMARC" \
+ -value NORMARC -variable recordSyntax
+.top.options.m.syntax add radiobutton -label "PICAMARC" \
+ -value PICAMARC -variable recordSyntax
+.top.options.m.syntax add separator
+.top.options.m.syntax add radiobutton -label "SUTRS" \
+ -value SUTRS -variable recordSyntax
+.top.options.m.syntax add separator
+.top.options.m.syntax add radiobutton -label "GRS1" \
+ -value GRS1 -variable recordSyntax
+
+menubutton .top.help -text "Help" -menu .top.help.m
+menu .top.help.m
+
+.top.help.m add command -label "Help on help" \
+ -command {tkerror "Help on help not available. Sorry"}
+.top.help.m add command -label "About" -command {about-origin}
+
+pack .top.file .top.target .top.service .top.rset .top.options -side left
+pack .top.help -side right
+
+index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
+
+button .mid.search -text Search -command {search-request 0} \
+ -state disabled
+button .mid.scan -text Scan \
+ -command scan-request -state disabled
+button .mid.present -text {Present} -command [list present-more 10] \
+ -state disabled
+
+button .mid.clear -text Clear -command index-clear
+pack .mid.search .mid.scan .mid.present .mid.clear -side left \
+ -fill y -pady 1
+
+text .data.record -height 2 -width 20 -wrap none \
+ -yscrollcommand [list .data.scroll set] -wrap $textWrap
+scrollbar .data.scroll -command [list .data.record yview]
+if {[tk4]} {
+ .data.record configure -takefocus 0
+ .data.scroll configure -takefocus 0
+}
+pack .data.scroll -side right -fill y
+pack .data.record -expand yes -fill both
+initBindings
+
+if {! $monoFlag} {
+ .data.record tag configure marc-tag -foreground blue
+ .data.record tag configure marc-id -foreground red
+} else {
+ .data.record tag configure marc-tag -foreground black
+ .data.record tag configure marc-id -foreground black
+}
+.data.record tag configure marc-data -foreground black
+.data.record tag configure marc-head \
+ -font -Adobe-Times-Medium-R-Normal-*-180-* \
+ -foreground white -background black
+
+button .bot.logo -bitmap @${libdir}/bitmaps/book1 -command cancel-operation
+if {[tk4]} {
+ .bot.logo configure -takefocus 0
+}
+frame .bot.a
+pack .bot.a -side left -fill x
+pack .bot.logo -side right -padx 2 -pady 2 -ipadx 1
+
+message .bot.a.target -text "" -aspect 1000 -border 1
+
+label .bot.a.status -text "Not connected" -width 15 -relief \
+ sunken -anchor w -border 1
+label .bot.a.set -text "" -width 5 -relief \
+ sunken -anchor w -border 1
+label .bot.a.message -text "" -width 15 -relief \
+ sunken -anchor w -border 1
+
+pack .bot.a.target -side top -anchor nw -padx 2 -pady 2
+pack .bot.a.status .bot.a.set .bot.a.message \
+ -side left -padx 2 -pady 2 -ipadx 1 -ipady 1
+
+if {[catch {ir z39}]} {
+ set e [info sharedlibextension]
+ puts -nonewline "Loading irtcl$e ..."
+ load irtcl$e irtcl
+ ir z39
+ puts "ok"
+}
+#z39 logLevel all
+show-logo 1