X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=www%2Fz39util.tcl;h=3a2c69482c9a0e243bb1443fa1c46631f31072e6;hb=df7b985601de6c729147a6fd6588adba6f905480;hp=4322d2c8d8f456f6afa25f92d40c283c46bc17ce;hpb=74a4580ba9945fc86b47654230865a68089245b6;p=egate.git diff --git a/www/z39util.tcl b/www/z39util.tcl index 4322d2c..3a2c694 100644 --- a/www/z39util.tcl +++ b/www/z39util.tcl @@ -1,5 +1,5 @@ # -# $Id: z39util.tcl,v 1.7 1995/11/10 14:47:32 adam Exp $ +# $Id: z39util.tcl,v 1.15 1996/01/02 10:52:32 adam Exp $ # proc saveState {} { uplevel #0 { @@ -26,16 +26,29 @@ proc saveState {} { } } -proc search-response {sno} { +proc search-response {zz} { global sessionWait - set status [z39.$sno responseStatus] + set status [$zz responseStatus] if {[lindex $status 0] == "NSD"} { - z39.$sno nextResultSetPosition 0 + $zz nextResultSetPosition 0 set code [lindex $status 1] set msg [lindex $status 2] set addinfo [lindex $status 3] - html "

Error NSD$code: $msg: $addinfo


\n" + displayError "Diagnostic message" \ + "$msg: $addinfo
\n(error code $code)" + set sessionWait -2 + } else { + set sessionWait 1 + } +} + +proc scan-response {zz} { + global sessionWait + + set status [$zz scanStatus] + if {$status == 6} { + displayError "Scan fail" "" set sessionWait -2 } else { set sessionWait 1 @@ -117,7 +130,7 @@ proc display-raw {zset no tno} { set indicator [lindex $line 1] set fields [lindex $line 2] set l [string length $indicator] - html "$tag " + html "$tag " if {$l > 0} { for {set i 0} {$i < $l} {incr i} { if {[string index $indicator $i] == " "} { @@ -127,6 +140,7 @@ proc display-raw {zset no tno} { } } } + html "" foreach field $fields { set id [lindex $field 0] set data [lindex $field 1] @@ -154,7 +168,7 @@ proc put-marc-contents {cc} { } html $cc if {$ref != ""} { - html {">} $urltype { reference} + html {">} $cc {} } } @@ -317,7 +331,7 @@ proc display-full {zset no tno} { if {"x$url" != "x"} { html "
URL\n" if {"x$sp" == "x"} { - set sp reference + set sp $url } html {
} [join $sp] "\n" } @@ -347,12 +361,30 @@ proc display-rec {from to dfunc tno} { } } -proc build-query {t} { +proc build-scan {t ilines} { + global targets + + for {set i 1} {$i <= $ilines} {incr i} { + set term [wform entry$i] + if {$term != ""} { + set field [wform menu$i] + foreach x [lindex $targets($t) 2] { + if {[lindex $x 0] == $field} { + set attr [lindex $x 1] + } + } + return [list $term $attr] + } + } + return "" +} + +proc build-query {t ilines} { global targets set op {} set q {} - for {set i 1} {$i < 4} {incr i} { + for {set i 1} {$i <= $ilines} {incr i} { set term [wform entry$i] if {$term != ""} { set field [wform menu$i] @@ -363,13 +395,13 @@ proc build-query {t} { } switch $op { And - { set q "@and $q ${attr} \{${term}\}" } + { set q "@and $q ${attr} ${term}" } Or - { set q "@or $q ${attr} \{${term}\}" } + { set q "@or $q ${attr} ${term}" } {And not} - { set q "@not $q ${attr} \{${term}\}" } + { set q "@not $q ${attr} ${term}" } {} - { set q "${attr} \{${term}\}" } + { set q "${attr} ${term}" } } set op [wform logic$i] } @@ -377,9 +409,138 @@ proc build-query {t} { return $q } -proc z39search {setNo piggy tno} { +proc z39scan {setNo scanNo tno scanLines scanPos} { + global hist + global sessionWait + global targets + + if {$tno > 0} { + set zz z39$tno + set host $hist($setNo,$tno,host) + set idAuth $hist($setNo,$tno,idAuthentication) + set database $hist($setNo,$tno,database) + set scanAttr $hist($setNo,$tno,scanAttr) + set scanTerm $hist($setNo,$tno,$scanNo,scanTerm) + } else { + set zz z39 + set host $hist($setNo,host) + set idAuth $hist($setNo,idAuthentication) + set database $hist($setNo,database) + set scanAttr $hist($setNo,scanAttr) + set scanTerm $hist($setNo,$scanNo,scanTerm) + } + if {[catch [list $zz failback fail-response]]} { + ir $zz + } + if {[catch [list set oldHost [$zz connect]]]} { + set oldHost "" + } + set zs $zz.s$scanNo.$setNo + $zz callback ok-response + $zz failback fail-response + if {$oldHost != $host} { + catch [list $zz disconnect] + + set sessionWait 0 + if {[catch [list $zz connect $host]]} { + displayError "Cannot connect to target" $host + return 0 + } elseif {$sessionWait == 0} { + if {[catch {zwait sessionWait 300}]} { + $zz disconnect + displayError "Cannot connect to target" $host + return 0 + } + if {$sessionWait != 1} { + displayError "Cannot connect to target" $host + return 0 + } + } + $zz idAuthentication $idAuth + set sessionWait 0 + if {[catch {$zz init}]} { + displayError "Cannot initialize target" $host + $zz disconnect + return 0 + } + if {[catch {zwait sessionWait 60}]} { + displayError "Cannot initialize target" $host + $zz disconnect + return 0 + } + if {$sessionWait != "1"} { + displayError "Cannot initialize target" $host + $zz disconnect + return 0 + } + if {![$zz initResult]} { + set u [$zz userInformationField] + $zz disconnect + displayError "Cannot initialize target $host" $u + return 0 + } + } else { + if {![catch [list $zs numberOfTermsRequested 5]]} { + return 1 + } + } + eval $zz databaseNames $database + + ir-scan $zs $zz + + $zs numberOfTermsRequested $scanLines + $zs preferredPositionInResponse $scanPos + + $zz callback [list scan-response $zs] + + set sessionWait 0 + $zs scan "${scanAttr} ${scanTerm}" + + if {[catch {zwait sessionWait 600}]} { + wlog debug "timeout/cancel in scan" + displayError "Timeout in scan" {} + html "\n" + $zz disconnect + return 0 + } + if {$sessionWait == -1} { + displayError "Scan fail" "Connection closed" + html "\n" + $zz disconnect + } + if {$sessionWait != 1} { + return 0 + } + return 1 +} + +proc display-scan {setNo scanNo tno} { + global hist + global targets + + if {$tno > 0} { + set zz z39$tno + } else { + set zz z39 + } + set zs $zz.s$scanNo.$setNo + set m [$zs numberOfEntriesReturned] + + html "
\n" + for {set i 0} {$i < $m} {incr i} { + html "
" + html [lindex [$zs scanLine $i] 1] + html ": " + html [lindex [$zs scanLine $i] 2] + html "\n" + } + html "
\n" +} + +proc z39search {setNo piggy tno elements} { global hist global sessionWait + global targets if {$tno > 0} { set zz z39$tno @@ -405,50 +566,66 @@ proc z39search {setNo piggy tno} { if {$oldHost != $host} { catch [list $zz disconnect] - html "Connecting to target " $host "
\n" set sessionWait 0 if {[catch [list $zz connect $host]]} { - html "Cannot connect to target ${host}
\n" + displayError "Cannot connect to target" $host return 0 } elseif {$sessionWait == 0} { - zwait sessionWait + if {[catch {zwait sessionWait 300}]} { + $zz disconnect + displayError "Cannot connect to target" $host + return 0 + } if {$sessionWait != 1} { - html "Cannot connect to target ${host}
\n" + displayError "Cannot connect to target" $host return 0 } } $zz idAuthentication $idAuth set sessionWait 0 - if {[catch [list $zz init]]} { - html "Cannot initialize with target ${host}
\n" + if {[catch {$zz init}]} { + displayError "Cannot initialize target" $host + $zz disconnect return 0 } if {[catch {zwait sessionWait 60}]} { - html "Cannot initialize with target ${host}
\n" + displayError "Cannot initialize target" $host $zz disconnect return 0 } if {$sessionWait != "1"} { - html "Cannot initialize with target ${host}
\n" + displayError "Cannot initialize target" $host $zz disconnect return 0 } if {![$zz initResult]} { set u [$zz userInformationField] $zz disconnect - html "Connection rejected by target: $u
\n" + displayError "Cannot initialize target $host" $u return 0 } - } - if {![catch [list $zz.$setNo smallSetUpperBound 0]]} { - return 1 + } else { + if {[info exists hist($setNo,hits)] && \ + ![catch [list $zz.$setNo smallSetUpperBound 0]]} { + return 1 + } + } ir-set $zz.$setNo $zz + + if {![lindex $targets($host) 5]} { + set elements {} + } + $zz.$setNo smallSetElementSetNames $elements + $zz.$setNo mediumSetElementSetNames $elements + $zz.$setNo recordElements $elements + + wlog debug "database=$database" eval $zz.$setNo databaseNames $database $zz.$setNo preferredRecordSyntax USMARC - $zz callback search-response $setNo + $zz callback [list search-response $zz.$setNo] if {$piggy} { $zz.$setNo largeSetLowerBound 999999 $zz.$setNo smallSetUpperBound 0 @@ -462,23 +639,20 @@ proc z39search {setNo piggy tno} { $zz.$setNo search $query if {[catch {zwait sessionWait 600}]} { + wlog debug "timeout/cancel in search" + displayError "Timeout in search" {} html "\n" $zz disconnect return 0 } - if {$sessionWait != 1} { + if {$sessionWait == -1} { + displayError "Search fail" "Connection closed" html "\n" $zz disconnect - return 0 } - set status [$zz.$setNo responseStatus] - if {[lindex $status 0] == "NSD"} { - set code [lindex $status 1] - set msg [lindex $status 2] - set addinfo [lindex $status 3] - html "

Error NSD$code: $msg: $addinfo


\n" - return 0 + if {$sessionWait != 1} { + return 0 } set hist($setNo,hits) [$zz.$setNo resultCount] return 1 @@ -523,10 +697,11 @@ proc search-m-response {setNo i} { set zstatus($i) 2 } -proc z39msearch {setNo piggy} { +proc z39msearch {setNo piggy elements} { global zleft global zstatus global hist + global targets set not $hist($setNo,0,host) @@ -552,6 +727,7 @@ proc z39msearch {setNo piggy} { set zstatus($i) 1 continue } + z39$i idAuthentication $hist($setNo,$i,idAuthentication) html "Connecting to target " $host "
\n" set zstatus($i) -1 if {![catch {z39$i connect $host}]} { @@ -572,6 +748,16 @@ proc z39msearch {setNo piggy} { ir-set z39$i.$setNo z39$i set hist($setNo,$i,offset) 0 eval z39$i.$setNo databaseNames $hist($setNo,$i,database) + + if {![lindex $targets($hist($setNo,$i,host)) 5]} { + set thisElements {} + } else { + set thisElements $elements + } + z39$i.$setNo smallSetElementSetNames $thisElements + z39$i.$setNo mediumSetElementSetNames $thisElements + z39$i.$setNo recordElements $thisElements + z39$i.$setNo preferredRecordSyntax USMARC z39$i callback [list search-m-response $setNo $i] @@ -607,17 +793,29 @@ proc z39msearch {setNo piggy} { } } -proc z39present {setNo tno setOffset setMax dfunc} { +proc z39present {setNo tno setOffset setMax dfunc elements} { global hist global sessionWait + global targets if {$tno > 0} { set zz z39$tno + set host $hist($setNo,$tno,host) } else { set zz z39 + set host $hist($setNo,host) } + if {![lindex $targets($host) 5]} { + set elements {} + } + + $zz.$setNo elementSetNames $elements + $zz.$setNo recordElements $elements set toGet [expr 1 + $setMax - $setOffset] + + $zz callback [list search-response $zz.$setNo] + while {$setMax > 0 && $toGet > 0} { for {set got 0} {$got < $toGet} {incr got} { if {[$zz.$setNo type [expr $setOffset + $got]] == ""} { @@ -628,9 +826,13 @@ proc z39present {setNo tno setOffset setMax dfunc} { set sessionWait 0 $zz.$setNo present $setOffset $toGet if {[catch {zwait sessionWait 300}]} { + wlog debug "timeout/cancel in present" $zz disconnect break } + if {$sessionWait == "0"} { + $zz disconnect + } if {$sessionWait != "1"} { break } @@ -656,11 +858,11 @@ proc z39history {} { if {![info exists nextSetNo]} { return } - html "

History

\n" + html "

History


\n" for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} { html {
} [lindex $targets($hist($setNo,host)) 0] if {[llength $hist($setNo,database)] > 1} { html ": " @@ -679,3 +881,15 @@ proc z39history {} { } html "
\n" } + +proc displayError {msga msgb} { + html "

\n" + html {Error} + html "

" $msga "

\n" + if {$msgb != ""} { + html "

" $msgb "

\n" + } + html "

\n" +} + +set useIcons 1