#
-# $Id: z39util.tcl,v 1.2 1995/11/07 14:57:00 adam Exp $
+# $Id: z39util.tcl,v 1.6 1995/11/09 15:24:37 adam Exp $
#
proc saveState {} {
uplevel #0 {
if {$var == "f"} continue
if {$var == "sessionId"} continue
if {$var == "errorInfo"} continue
- set names [array names $var]
- if {$names != ""} {
+ if {[catch {set names [array names $var]}]} {
+ eval "set v \$${var}"
+ puts $f "set ${var} \{$v\}"
+ } else {
foreach n $names {
eval "set v \$${var}(\$n)"
puts $f "set ${var}($n) \{$v\}"
}
- } else {
- eval "set v \$${var}"
- puts $f "set ${var} \{$v\}"
+ catch {
+ eval "set v \$${var}"
+ puts $f "set ${var} \{$v\}"
+ }
}
}
close $f
set rtype [$zset recordType $no]
if {$rtype == "SUTRS"} {
html [join [$zset getSutrs $no]]
- htmlr {<br>}
+ html "<br>\n"
return
}
if {![catch {
set title [lindex [$zset getMarc $no field 245 * a] 0]
set year [lindex [$zset getMarc $no field 260 * c] 0]
} ] } {
- html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME) /
- html $sessionId {/showfull.egw/} $setNo + $no {"> } $title {</a>}
- html " <i> ${year} </i>"
+ html {<a href="http:} $env(SCRIPT_NAME) /
+ html $sessionId {/showfull.egw/} $setNo + $no + full
+ html {"> } $title {</a>} " <i> ${year} </i>"
}
- htmlr {<br>}
+ html "<br>\n"
}
-proc display-full {zset no} {
+proc display-raw {zset no} {
set type [$zset type $no]
if {$type == "SD"} {
set err [lindex [$zset diag $no] 1]
if {$add != {}} {
set add " :${add}"
}
- htmlr "<hr> ${no} <br>"
- htmlr "Error ${err}${add} <br>"
+ html "<h3>${no}</h3>\n"
+ html "Error ${err}${add} <br>\n"
return
}
if {$type != "DB"} {
return
}
- htmlr "<hr> ${no} <br>"
set rtype [$zset recordType $no]
if {$rtype == "SUTRS"} {
- htmlr [join [$zset getSutrs $no]]
+ html [join [$zset getSutrs $no]] "<br>\n"
return
}
if {[catch {set r [$zset getMarc $no line * * *]}]} {
- htmlr "Unknown record type: $rtype"
+ html "Unknown record type: $rtype <br>\n"
return
}
foreach line $r {
html "$tag "
if {$l > 0} {
for {set i 0} {$i < $l} {incr i} {
- if {[string index $tag $i] == " "} {
- html "_"
+ if {[string index $indicator $i] == " "} {
+ html "-"
} else {
html [string index $tag $i]
}
}
}
+proc put-marc-contents {cc} {
+ set ref ""
+ if {[string first :// $cc] > 0} {
+ foreach urltype {gopher http ftp mailto} {
+ if {[string first ${urltype}:// $cc] == 0} {
+ set ref $urltype
+ break
+ }
+ }
+ }
+ if {$ref != ""} {
+ html {<a href="}
+ }
+ html $cc
+ if {$ref != ""} {
+ html {">} $urltype { reference</a>}
+ }
+}
+
+proc dl-marc-field {zset no tag id la lb sep} {
+ set n 0
+ set c [$zset getMarc $no field $tag * $id]
+ set len [llength $c]
+ if {$len == 0} {
+ return 0
+ }
+ if {$len > 1 && "x$lb" != "x"} {
+ html "<dt><b>$lb</b>\n<dd>"
+ } else {
+ html "<dt><b>$la</b>\n<dd>"
+ }
+ foreach cc $c {
+ if {$n > 0} {
+ html $sep
+ }
+ put-marc-contents $cc
+ incr n
+ }
+ return $n
+}
+
+proc dd-marc-field {zset no tag id start stop} {
+ set n 0
+ set c [$zset getMarc $no field $tag * $id]
+ set len [llength $c]
+ if {$len == 0} {
+ return 0
+ }
+ foreach cc $c {
+ html $start
+ put-marc-contents $cc
+ html $stop
+ incr n
+ }
+ return $n
+}
+
+proc dl-marc-field-rec {zset no tag lead start stop startid sep} {
+ set n 0
+ set lines [$zset getMarc $no line $tag * *]
+ foreach line $lines {
+ foreach field [lindex $line 2] {
+ if {$n == 0} {
+ html "<dt><b>$lead</b>"
+ html "\n<dd>"
+ }
+ set id [lindex $field 0]
+ if {$id == $startid} {
+ if {$n > 0} {
+ html $stop
+ }
+ html $start
+ incr n
+ html [lindex $field 1]
+ } else {
+ html $sep
+ html [lindex $field 1]
+ }
+ }
+ }
+ if {$n > 0} {
+ html $stop
+ }
+}
+
+proc display-full {zset no} {
+ set type [$zset type $no]
+ if {$type == "SD"} {
+ set err [lindex [$zset diag $no] 1]
+ set add [lindex [$zset diag $no] 2]
+ if {$add != {}} {
+ set add " :${add}"
+ }
+ html "Error ${err}${add} <br>\n"
+ return
+ }
+ if {$type != "DB"} {
+ return
+ }
+ set rtype [$zset recordType $no]
+ if {$rtype == "SUTRS"} {
+ html [join [$zset getSutrs $no]] "<br>\n"
+ return
+ }
+ if {[catch {set r [$zset getMarc $no line * * *]}]} {
+ html "Unknown record type: $rtype <br>\n"
+ return
+ }
+ html "<dl>\n"
+ set n [dl-marc-field $zset $no 700 a "Author" "Authors" "<br>\n"]
+ if {$n == 0} {
+ set n [dl-marc-field $zset $no 100 a "Author" "Authors" "<br>\n"]
+ }
+ set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
+ if {$n == 0} {
+ set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
+ }
+ set n [dl-marc-field $zset $no 245 {a} "Title" {} " "]
+ if {$n > 0} {
+ dd-marc-field $zset $no 245 b "<em>" "</em>"
+ dd-marc-field $zset $no 245 c " " ""
+ } else {
+ dl-marc-field $zset $no 245 {[ab]} "Title" {} " "
+ }
+ dl-marc-field $zset $no 520 a "Abstract" {} ", "
+ dl-marc-field $zset $no 072 * "Subject code" "Subject codes" ", "
+ dl-marc-field $zset $no 650 * "Subject" {} ", "
+ dl-marc-field $zset $no 260 * "Publisher" {} " "
+ dl-marc-field $zset $no 300 * "Physical Description" {} " "
+
+ dl-marc-field $zset $no 500 a "Notes" {} ", "
+
+ dl-marc-field-rec $zset $no 510 "References" "" "<br>\n" "a" ", "
+
+ dl-marc-field $zset $no 350 a "Price" {} ", "
+ dl-marc-field $zset $no 362 a "Dates of publication" {} ", "
+ dl-marc-field $zset $no 850 a "Holdings" {} ", "
+
+ dl-marc-field $zset $no 010 a "LC control number" {} ", "
+ dl-marc-field $zset $no 010 b "NUCMC control number" {} ", "
+ dl-marc-field $zset $no 020 a "ISBN" {} ", "
+ dl-marc-field $zset $no 022 a "ISSN" {} ", "
+ set url [$zset getMarc $no field 856 * u]
+ set sp [$zset getMarc $no field 856 * 3]
+ if {"x$url" != "x"} {
+ html "<dt><b>URL</b>\n"
+ if {"x$sp" == "x"} {
+ set sp reference
+ }
+ html {<dd><a href="} $url {">} [join $sp] "</a>\n"
+ }
+ dl-marc-field $zset $no 037 * "Acquisition" {} "<br>\n"
+ dl-marc-field $zset $no 787 {[rstw6]} "Related information" {} "<br>\n"
+ dl-marc-field $zset $no 001 * "Local control number" {} ", "
+ html "</dl>\n"
+}
+
+
proc display-rec {from to dfunc zz} {
global setNo
return 0
}
}
+ z39 idAuthentication $hist($setNo,idAuthentication)
set sessionWait 0
if {[catch {z39 init}]} {
html "Cannot initialize with target ${host} <br>\n"
return 0
}
- zwait sessionWait
+ if {[catch {zwait sessionWait 60}]} {
+ html "Cannot initialize with target ${host} <br>\n"
+ z39 disconnect
+ return 0
+ }
if {$sessionWait != "1"} {
html "Cannot initialize with target ${host} <br>\n"
+ z39 disconnect
return 0
}
}
set sessionWait 0
z39.$setNo search $hist($setNo,query)
- zwait sessionWait
+ if {[catch {zwait sessionWait 600}]} {
+ html "</body></html>\n"
+ z39 disconnect
+ return 0
+ }
+
if {$sessionWait != 1} {
html "</body></html>\n"
+ z39 disconnect
return 0
}
set status [z39.$setNo responseStatus]
if {$got < $toGet} {
set sessionWait 0
z39.$setNo present $setOffset $toGet
- zwait sessionWait
+ if {[catch {zwait sessionWait 300}]} {
+ z39 disconnect
+ break
+ }
if {$sessionWait != "1"} {
break
}
set got [z39.$setNo numberOfRecordsReturned]
+ if {$got <= 0} {
+ break
+ }
}
- display-rec $setOffset [expr $got + $setOffset - 1] $dfunc
+ display-rec $setOffset [expr $got + $setOffset - 1] $dfunc z39
set setOffset [expr $got + $setOffset]
set toGet [expr 1 + $setMax - $setOffset]
wflush
global hist
global env
global sessionId
+ global targets
if {![info exists nextSetNo]} {
return
}
html "<hr><h3>History</h3><dl>\n"
for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
- html {<dt> <a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html {<dt> <a href="http:} $env(SCRIPT_NAME)
html / $sessionId {/search.egw/} $setNo + 1
html + [expr $hist($setNo,maxPresent) - 1]
- html {"> } $hist($setNo,host)
+ html {"> } [lindex $targets($hist($setNo,host)) 0]
if {[llength $hist($setNo,database)] > 1} {
html ": "
foreach b $hist($setNo,database) {
html "\n"
}
html "</dl>\n"
-}
\ No newline at end of file
+}