2 # $Id: z39util.tcl,v 1.40 1996/03/13 14:07:32 adam Exp $
6 set f [open "tcl.state.${sessionId}" w]
7 foreach var [info globals] {
8 if {$var == "f"} continue
9 if {$var == "sessionId"} continue
10 if {$var == "errorInfo"} continue
11 if {[catch {set names [array names $var]}]} {
13 puts $f "set ${var} \{$v\}"
16 eval "set v \$${var}(\$n)"
17 puts $f "set ${var}($n) \{$v\}"
21 puts $f "set ${var} \{$v\}"
29 proc search-response {zz} {
32 set status [$zz responseStatus]
33 if {[lindex $status 0] == "NSD"} {
34 $zz nextResultSetPosition 0
35 set code [lindex $status 1]
36 set msg [lindex $status 2]
37 set addinfo [lindex $status 3]
38 displayError "Diagnostic message" \
39 "$msg: $addinfo<br>\n(error code $code)"
46 proc scan-response {zz} {
49 set status [$zz scanStatus]
51 displayError "Scan fail" ""
63 proc fail-response {} {
68 proc display-medium {zset no setNo targetNo} {
73 set type [$zset type $no]
75 set err [lindex [$zset diag $no] 1]
76 set add [lindex [$zset diag $no] 2]
80 html "${no} Error ${err}${add} <br>\n"
86 set rtype [$zset recordType $no]
89 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
90 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
91 html [join [$zset getSutrs $no]]
96 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
97 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
98 html [join [$zset getWAIS $no headline]]
101 html {Score: } [$zset getWAIS $no score]
102 set lines [$zset getWAIS $no lines]
104 html {, } $lines { lines}
111 set author [$zset getMarc $no field 100 * a]
112 set corp [$zset getMarc $no field 110 * a]
113 set meet [$zset getMarc $no field 111 * a]
114 set title [$zset getMarc $no field 245 * a]
115 if {[llength $author] == 0} {
116 set cover [$zset getMarc $no field 245 * {[bc]}]
118 set cover [$zset getMarc $no field 245 * b]
120 set location [$zset getMarc $no field 260 * a]
121 set publisher [$zset getMarc $no field 260 * b]
122 set year [$zset getMarc $no field 260 * c]
123 set score [$zset getMarc $no field 999 * r]
125 html { <a href="http:} $env(SCRIPT_NAME) /
126 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
157 set v [join $cover ""]
158 if {[string length $v] > 0} {
165 if {[scan $score %d nscore]} {
166 html "; Score " $nscore
169 html { <a href="http:} $env(SCRIPT_NAME) /
170 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
173 html "Error: " $dispError "\n"
178 proc display-brief {zset no setNo targetNo} {
183 set type [$zset type $no]
185 set err [lindex [$zset diag $no] 1]
186 set add [lindex [$zset diag $no] 2]
190 html "${no} Error ${err}${add} <br>\n"
196 set rtype [$zset recordType $no]
199 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
200 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
201 html [string range [join [$zset getSutrs $no]] 0 70]
206 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
207 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
208 html [string range [join [$zset getWAIS $no headline]] 0 70]
211 set score [$zset getWAIS $no score]
212 html { Score } $score
218 set author [$zset getMarc $no field 100 * a]
219 set corp [$zset getMarc $no field 110 * a]
220 set meet [$zset getMarc $no field 111 * a]
221 set title [$zset getMarc $no field 245 * a]
222 if {[llength $author] == 0} {
223 set cover [$zset getMarc $no field 245 * {[bc]}]
225 set cover [$zset getMarc $no field 245 * b]
227 set location [$zset getMarc $no field 260 * a]
228 set publisher [$zset getMarc $no field 260 * b]
229 set year [$zset getMarc $no field 260 * c]
231 html { <a href="http:} $env(SCRIPT_NAME) /
232 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
266 set v [join $cover ""]
267 if {[string length $v] > 40} {
269 html [string range $v 0 38] "..."
270 } elseif {[string length $v] > 0} {
279 html { <a href="http:} $env(SCRIPT_NAME) /
280 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
283 html "Error: " $dispError "\n"
288 proc display-raw {zset no setNo targetNo} {
289 set type [$zset type $no]
292 set err [lindex [$zset diag $no] 1]
293 set add [lindex [$zset diag $no] 2]
297 html "<h3>${no}</h3>\n"
298 html "Error ${err}${add} <br>\n"
307 set rtype [$zset recordType $no]
310 html "<xmp>\n" [join [$zset getSutrs $no]] "\n</xmp>\n"
314 html "<xmp>\n" [join [$zset getWAIS $no text]] "\n</xmp>\n"
318 if {[catch {set r [$zset getMarc $no line * * *]}]} {
319 html "Unknown record type: $rtype <br>\n"
323 set tag [lindex $line 0]
324 set indicator [lindex $line 1]
325 set fields [lindex $line 2]
326 set l [string length $indicator]
329 for {set i 0} {$i < $l} {incr i} {
330 if {[string index $indicator $i] == " "} {
333 html [string index $tag $i]
338 foreach field $fields {
339 set id [lindex $field 0]
340 set data [lindex $field 1]
342 html " <b>\$$id</b> "
350 proc put-marc-contents {cc} {
352 if {[string first :// $cc] > 0} {
353 foreach urltype {gopher http ftp mailto} {
354 if {[string first ${urltype}:// $cc] == 0} {
369 proc dl-marc-field {zset no tag id la lb sep} {
371 set c [$zset getMarc $no field $tag * $id]
376 if {$len > 1 && "x$lb" != "x"} {
377 html "<dt><b>$lb</b>\n<dd>"
379 html "<dt><b>$la</b>\n<dd>"
385 put-marc-contents $cc
391 proc dd-marc-field {zset no tag id start stop} {
393 set c [$zset getMarc $no field $tag * $id]
400 put-marc-contents $cc
407 proc dl-marc-field-rec {zset no tag lead start stop startid sep} {
409 set lines [$zset getMarc $no line $tag * *]
410 foreach line $lines {
411 foreach field [lindex $line 2] {
413 html "<dt><b>$lead</b>"
416 set id [lindex $field 0]
417 if {$id == $startid} {
423 html [lindex $field 1]
426 html [lindex $field 1]
435 proc display-full-marc {zset no setNo targetNo} {
441 set n [dl-marc-field $zset $no 700 a "Author" "Authors" "<br>\n"]
443 set n [dl-marc-field $zset $no 100 a "Author" "Authors" "<br>\n"]
445 set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
447 set n [dl-marc-field $zset $no 110 a "Corporate Name" {} ", "]
449 set n [dl-marc-field $zset $no 711 a "Meeting Name" {} ", "]
451 dd-marc-field $zset $no 711 {[bndc]} " " ""
453 set n [dl-marc-field $zset $no 111 a "Meeting Name" {} ", "]
455 dd-marc-field $zset $no 111 {[bndc]} " " " "
458 set n [dl-marc-field $zset $no 245 {a} "Title" {} " "]
460 dd-marc-field $zset $no 245 b "<em>" "</em>"
461 dd-marc-field $zset $no 245 c " " ""
463 dl-marc-field $zset $no 245 {[ab]} "Title" {} " "
465 dl-marc-field $zset $no 520 a "Abstract" {} ", "
466 dl-marc-field $zset $no 072 * "Subject code" "Subject codes" ", "
467 dl-marc-field $zset $no 650 * "Subject" {} ", "
468 dl-marc-field $zset $no 260 * "Publisher" {} " "
469 dl-marc-field $zset $no 300 * "Physical Description" {} " "
471 dl-marc-field-rec $zset $no 500 "Notes" "" "<br>\n" "a" ", "
473 dl-marc-field-rec $zset $no 510 "References" "" "<br>\n" "a" ", "
475 dl-marc-field-rec $zset $no 511 "Participant note" "" "<br>\n" "a" ", "
477 dl-marc-field $zset $no 513 a "Report type" {} ", "
478 dl-marc-field $zset $no 513 b "Period covered" {} ", "
479 dl-marc-field-rec $zset $no 515 "Numbering notes" "" "<br>\n" "a" ", "
480 dl-marc-field-rec $zset $no 516 "Data notes" "" "<br>\n" "a" ", "
481 dl-marc-field-rec $zset $no 518 "Date/time notes" "" "<br>\n" "a" ", "
483 dl-marc-field $zset $no 350 a "Price" {} ", "
484 dl-marc-field $zset $no 362 a "Dates of publication" {} ", "
485 dl-marc-field $zset $no 850 a "Holdings" {} ", "
487 dl-marc-field-rec $zset $no 270 "Contact name" "" "<br>\n" p ", "
489 set n [dl-marc-field $zset $no 270 p "Contact name" {} ", "]
494 dl-marc-field $zset $no 270 a "Street" {} ", "
495 dl-marc-field $zset $no 270 b "City" {} ", "
496 dl-marc-field $zset $no 270 c "State" {} ", "
497 dl-marc-field $zset $no 270 e "Zip code" {} ", "
498 dl-marc-field $zset $no 270 d "Country" {} ", "
499 dl-marc-field $zset $no 270 m "Network address" {} ", "
500 dl-marc-field $zset $no 301 a "Service hours" {} ", "
501 dl-marc-field $zset $no 270 k "Phone" {} ", "
502 dl-marc-field $zset $no 270 l "Fax" {} ", "
504 dl-marc-field $zset $no 270 {[abcedmakl]} "Address" {} "<br>\n"
510 dl-marc-field $zset $no 010 a "LC control number" {} ", "
511 dl-marc-field $zset $no 010 b "NUCMC control number" {} ", "
512 dl-marc-field $zset $no 020 a "ISBN" {} ", "
513 dl-marc-field $zset $no 022 a "ISSN" {} ", "
514 set url [$zset getMarc $no field 856 * u]
515 set sp [$zset getMarc $no field 856 * 3]
516 if {"x$url" != "x"} {
517 html "<dt><b>URL</b>\n"
521 html {<dd><a href="} [join $url] {">} [join $sp] "</a>\n"
523 dl-marc-field $zset $no 037 {[abc]} "Acquisition" {} "<br>\n"
524 dl-marc-field $zset $no 037 {[f6]} "Form of issue" {} "<br>\n"
525 dl-marc-field $zset $no 537 * "Source of data" {} "<br>\n"
526 dl-marc-field $zset $no 538 * "System details" {} "<br>\n"
527 dl-marc-field $zset $no 787 {[rstw6]} "Related information" {} "<br>\n"
528 dl-marc-field $zset $no 999 r "Score" {} ", "
529 dl-marc-field $zset $no 001 * "Local control number" {} ", "
533 proc display-full-wais {zset no setNo targetNo} {
540 htmlToken l [join [$zset getWAIS $no text]] {
541 if {[string compare [string index $l 0] {<}]} {
542 if {[info exist data($element)]} {
543 set data($element) $data($element)$l
545 set data($element) $l
554 set element dateOfLastModification
557 set element controlIdentifier
560 set element lastChecked
572 set element "$i,linkage"
575 set element "$i,title"
585 if {![info exists data(title)] || ![info exists data(linkage)]} {
591 html {<dt><b>Title</b>}
593 html {<dd><a href="} $data(linkage) {">} $data(title) "</a>"
594 html {<dt><b>URL</b>}
595 html {<dd>} $data(linkage) "<br>\n"
597 html {<dd>} [join [$zset getWAIS $no headline]]
599 html {<dt><b>Score</b><dd>} [$zset getWAIS $no score]
600 set lines [$zset getWAIS $no lines]
602 html {<dt><b>Lines</b><dd>} $lines "<br>\n"
605 html "</dl><pre>\n" [join [$zset getWAIS $no text]] "\n</pre>\n"
608 if {[info exists data(bytes)]} {
609 html {<dt><b>Bytes</b><dd>} $data(bytes)
611 if {[info exists data(dateOfLastModification)]} {
612 html {<dt><b>Last modified</b><dd>} $data(dateOfLastModification)
614 if {[info exists data(lastChecked)]} {
615 html {<dt><b>Last checked</b><dd>} $data(lastChecked) "<br>\n"
617 if {[info exists data(ip)]} {
618 html {<dt><b>Initial text</b><dd>} $data(ip) "<br>\n"
621 html {<a href="} $env(SCRIPT_NAME) / $sessionId {/sameas.egw/}
622 html $setNo + $targetNo + 1 + $hist($setNo,maxPresent) +
623 html [egw_enc [$zset getWAIS $no documentID]] {">}
624 html {Similar WAIS record</a><br>}
626 if {[info exists data($i,linkage)]} {
627 html "<dt><b>References</b>\n"
629 for {set i 1} {[info exists data($i,linkage)]} {incr i} {
630 html {<dd><a href="} $data($i,linkage) {">}
631 if {[info exists data($i,title)]} {
641 proc display-full {zset no setNo targetNo} {
642 set type [$zset type $no]
645 set err [lindex [$zset diag $no] 1]
646 set add [lindex [$zset diag $no] 2]
650 html "Error ${err}${add} <br>\n"
659 set rtype [$zset recordType $no]
662 html "<pre>" [join [$zset getSutrs $no]] "</pre><br>\n"
666 display-full-wais $zset $no $setNo $targetNo
670 if {[catch {set r [$zset getMarc $no line * * *]}]} {
671 html "Unknown record type: $rtype <br>\n"
674 display-full-marc $zset $no $setNo $targetNo
678 proc display-rec {from to dfunc setNo targetNo} {
679 while {$from <= $to} {
680 eval "$dfunc z39${targetNo}.${setNo} $from $setNo $targetNo"
685 proc build-scan {t i} {
688 set term [egw_form entry$i]
690 set field [join [egw_form menu$i]]
692 foreach x [lindex $targets($t) 2] {
693 if {[lindex $x 0] == $field} {
694 set attr [lindex $x 1]
697 return [list $term $attr]
702 proc build-query {t ilines} {
707 for {set i 1} {$i <= $ilines} {incr i} {
708 set term [join [egw_form entry$i]]
709 if {[string length $term] == 0} continue
710 if {![string compare [lindex $targets($t) 1] WAIS]} {
711 if {[string length $q] == 0} {
716 set op [egw_form logic$i]
719 set field [join [egw_form menu$i]]
721 foreach x [lindex $targets($t) 2] {
722 if {![string compare [lindex $x 0] $field]} {
723 set attr [lindex $x 1]
726 if {![info exists attr]} {
727 egw_log debug "attr failed for $t"
728 set attr [lindex [lindex [lindex $targets($t) 2] 0] 1]
732 { set q "@and $q ${attr} \"${term}\"" }
734 { set q "@or $q ${attr} \"${term}\"" }
736 { set q "@not $q ${attr} \"${term}\"" }
738 { set q "${attr} \"${term}\"" }
740 set op [egw_form logic$i]
746 proc z39scan {setNo scanNo tno scanLines scanPos cache} {
752 set host $hist($setNo,$tno,host)
753 set idAuth $hist($setNo,$tno,idAuthentication)
754 set database $hist($setNo,$tno,database)
755 set scanAttr $hist($setNo,scanAttr)
756 set scanTerm $hist($setNo,$scanNo,scanTerm)
759 if {[catch [list set oldHost [$zz connect]]]} {
762 set zs $zz.s$scanNo.$setNo
763 $zz callback ok-response
764 $zz failback fail-response
765 set thisHost [splitHostSpec $host]
766 if {[string compare $oldHost $thisHost]} {
767 catch [list $zz disconnect]
770 if {[catch [list $zz connect $thisHost]]} {
771 displayError "Cannot connect to target" $thisHost
773 } elseif {$sessionWait == 0} {
774 if {[catch {egw_wait sessionWait 300}]} {
776 displayError "Cannot connect to target" $thisHost
779 if {$sessionWait != 1} {
780 displayError "Cannot connect to target" $thisHost
784 $zz idAuthentication $idAuth
786 if {[catch {$zz init}]} {
787 displayError "Cannot initialize target" $thisHost
791 if {[catch {egw_wait sessionWait 60}]} {
792 displayError "Cannot initialize target" $thisHost
796 if {$sessionWait != "1"} {
797 displayError "Cannot initialize target" $thisHost
801 if {![$zz initResult]} {
802 set u [$zz userInformationField]
804 displayError "Cannot initialize target $thisHost" $u
808 if {$cache && ![catch [list $zs numberOfTermsRequested 5]]} {
812 eval $zz databaseNames $database
816 $zs numberOfTermsRequested $scanLines
817 $zs preferredPositionInResponse $scanPos
819 $zz callback [list scan-response $zs]
821 egw_log debug "scan: ${scanAttr} ${scanTerm}"
823 $zs scan "${scanAttr} ${scanTerm}"
825 if {[catch {egw_wait sessionWait 60}]} {
826 egw_log debug "timeout/cancel in scan"
827 displayError "Timeout in scan" {}
828 html "</body></html>\n"
832 if {$sessionWait == -1} {
833 displayError "Scan fail" "Connection closed"
834 html "</body></html>\n"
837 if {$sessionWait != 1} {
843 proc display-scan {setNo scanNo tno} {
851 set zs $zz.s$scanNo.$setNo
852 set m [$zs numberOfEntriesReturned]
855 set t [lindex [$zs scanLine 0] 1]
857 set hist($setNo,$tno,[expr $scanNo - 1],scanTerm) $t
859 set hist($setNo,[expr $scanNo - 1],scanTerm) $t
861 set t [lindex [$zs scanLine [expr $m - 1]] 1]
863 set hist($setNo,$tno,[expr $scanNo + 1],scanTerm) $t
865 set hist($setNo,[expr $scanNo + 1],scanTerm) $t
868 html {<table width=500 border=0><tr>}
869 html {<td align=left><b>Scan term</b>}
870 html {<td align=right><b>Hits</b>}
873 for {set i 0} {$i < $m} {incr i} {
874 html {<td align=left>}
876 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
877 html {<a href="http:} $env(SCRIPT_NAME)
878 html / $sessionId / $scriptQuery {;/} $setNo + $hist($setNo,host) +
879 html $hist($setNo,scan) + $tterm {">}
881 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
882 html {<a href="http:} $env(SCRIPT_NAME)
883 html / $sessionId {/search.egw/} $setNo + $tno +
884 html hyper + $tterm {">}
886 html [lindex [$zs scanLine $i] 1]
888 html {<td align=right>}
889 html [lindex [$zs scanLine $i] 2]
895 proc z39search {setNo piggy tno elements} {
901 set host $hist($setNo,$tno,host)
902 set idAuth $hist($setNo,$tno,idAuthentication)
903 set database $hist($setNo,$tno,database)
904 set query $hist($setNo,$tno,query)
905 catch {set docId $hist($setNo,$tno,queryId)}
908 if {[catch [list set oldHost [$zz connect]]]} {
911 $zz callback ok-response
912 $zz failback fail-response
913 set thisHost [splitHostSpec $host]
914 if {[string compare $oldHost $thisHost]} {
915 catch [list $zz disconnect]
918 if {[catch [list $zz connect $thisHost]]} {
919 displayError "Cannot connect to target" $thisHost
921 } elseif {$sessionWait == 0} {
922 if {[catch {egw_wait sessionWait 300}]} {
924 displayError "Cannot connect to target" $thisHost
927 if {$sessionWait != 1} {
928 displayError "Cannot connect to target" $thisHost
932 $zz idAuthentication $idAuth
934 if {[catch {$zz init}]} {
935 displayError "Cannot initialize target" $thisHost
939 if {$sessionWait == 0 && [catch {egw_wait sessionWait 60}]} {
940 displayError "Cannot initialize target" $thisHost
944 if {$sessionWait != "1"} {
945 displayError "Cannot initialize target" $thisHost
949 if {![$zz initResult]} {
950 set u [$zz userInformationField]
952 displayError "Cannot initialize target $thisHost" $u
955 } elseif {![catch [list $zz.$setNo smallSetUpperBound 0]]} {
956 if {[info exists hist($setNo,$tno,hits)]} {
961 if {![string compare [lindex $targets($host) 1] WAIS]} {
962 wais-set $zz.$setNo $zz
964 ir-set $zz.$setNo $zz
965 $zz.$setNo preferredRecordSyntax [lindex $targets($host) 1]
966 egw_log debug "set syntax to [lindex $targets($host) 1]"
968 if {![lindex $targets($host) 5]} {
971 $zz.$setNo smallSetElementSetNames $elements
972 $zz.$setNo mediumSetElementSetNames $elements
973 $zz.$setNo recordElements $elements
975 egw_log debug "database=$database"
976 eval $zz.$setNo databaseNames $database
978 $zz callback [list search-response $zz.$setNo]
980 $zz.$setNo largeSetLowerBound 999999
981 $zz.$setNo smallSetUpperBound 0
982 $zz.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
984 $zz.$setNo largeSetLowerBound 2
985 $zz.$setNo smallSetUpperBound 0
986 $zz.$setNo mediumSetPresentNumber 0
989 egw_log debug "search: $query"
991 if {[info exists docId]} {
992 $zz.$setNo search $query $docId
994 $zz.$setNo search $query
997 if {!$sessionWait && [catch {egw_wait sessionWait 60}]} {
998 egw_log debug "timeout/cancel in search"
999 displayError "Timeout in search" {}
1000 html "</body></html>\n"
1005 if {$sessionWait == -1} {
1006 displayError "Search fail" "Connection closed"
1007 html "</body></html>\n"
1010 if {$sessionWait != 1} {
1013 set hist($setNo,$tno,hits) [$zz.$setNo resultCount]
1017 proc init-m-response {i} {
1021 egw_log debug "init-m-response"
1024 if {![z39$i initResult]} {
1032 proc connect-m-response {i} {
1036 egw_log debug "connect-m-response"
1037 z39$i callback [list init-m-response $i]
1038 if {[catch {z39$i init}]} {
1044 proc fail-m-response {i} {
1048 egw_log debug "fail-m-response"
1053 proc search-m-response {setNo i start number} {
1058 egw_log debug "search-m-response"
1059 set status [z39$i.$setNo responseStatus]
1060 egw_log debug "search-m-response1"
1061 if {[lindex $status 0] == "OK"} {
1063 } elseif {[lindex $status 0] == "DBOSD"} {
1064 set nor [z39$i.$setNo numberOfRecordsReturned]
1066 egw_log debug "search-m-response2"
1071 set hist($setNo,$i,hits) [z39$i.$setNo resultCount]
1072 egw_log debug "search-m-response3"
1073 set hist($setNo,$i,offset) [expr $start + $nor -1]
1074 if {[expr $nor + $start] > [z39$i.$setNo resultCount]} {
1075 egw_log debug "search-m-response4"
1080 egw_log debug "search-m-response5"
1081 if {$nor >= $number} {
1082 egw_log debug "search-m-response6 nor=$nor number=$number"
1087 egw_log debug "search-m-response7"
1088 set start [expr $start + $nor]
1089 set number [expr $number - $nor]
1090 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1091 set number [expr [z39$i.$setNo resultCount] - $start + 1]
1093 z39$i callback [list search-m-response $setNo $i $start $number]
1094 egw_log debug "mpresent start=$number number=$number"
1095 z39$i.$setNo present $start $number
1098 proc z39msearch {setNo elements start number cache} {
1105 set not $hist($setNo,0,host)
1107 egw_log debug "z39msearch start=$start number=$number elements=$elements"
1108 for {set i 1} {$i <= $not} {incr i} {
1109 set host $hist($setNo,$i,host)
1111 set oldHost [z39$i connect]
1112 set thisHost [splitHostSpec $host]
1113 if {[string compare $oldHost $thisHost]} {
1114 catch {z39$i disconnect}
1116 z39$i callback [list connect-m-response $i]
1117 z39$i failback [list fail-m-response $i]
1120 for {set i 1} {$i <= $not} {incr i} {
1121 set oldHost [z39$i connect]
1122 set host $hist($setNo,$i,host)
1123 set thisHost [splitHostSpec $host]
1124 if {![string compare $oldHost $thisHost]} {
1127 egw_log debug "old=$oldHost this=$thisHost"
1128 z39$i idAuthentication $hist($setNo,$i,idAuthentication)
1129 html "Connecting to target " $thisHost " <br>\n"
1131 if {![catch {z39$i connect $thisHost}]} {
1135 while {$zleft > 0} {
1136 egw_log debug "Waiting for init response"
1137 if {[catch {egw_wait zleft 20}]} {
1142 for {set i 1} {$i <= $not} {incr i} {
1143 set host $hist($setNo,$i,host)
1145 html "host " [splitHostSpec $host] ": "
1147 egw_log debug "i=$i zstatus=$zstatus($i)"
1148 if {$zstatus($i) < 1} {
1154 if {[catch [list z39$i.$setNo preferredRecordSyntax]]} {
1159 if {![string compare [lindex $targets($host) 1] WAIS]} {
1160 wais-set z39$i.$setNo z39$i
1162 ir-set z39$i.$setNo z39$i
1163 z39$i.$setNo preferredRecordSyntax [lindex $targets($host) 1]
1164 egw_log debug "set syntax to [lindex $targets($host) 1]"
1166 set hist($setNo,$i,offset) 0
1167 eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
1169 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1172 set thisElements $elements
1174 z39$i.$setNo smallSetElementSetNames $thisElements
1175 z39$i.$setNo mediumSetElementSetNames $thisElements
1176 z39$i.$setNo elementSetNames $thisElements
1177 z39$i.$setNo recordElements $thisElements
1179 z39$i callback [list search-m-response $setNo $i $start $number]
1182 z39$i.$setNo largeSetLowerBound 999999
1183 z39$i.$setNo smallSetUpperBound 0
1184 z39$i.$setNo mediumSetPresentNumber $number
1186 z39$i.$setNo largeSetLowerBound 2
1187 z39$i.$setNo smallSetUpperBound 0
1188 z39$i.$setNo mediumSetPresentNumber 0
1192 egw_log debug "msearch host=" $hist($setNo,$i,host)
1193 egw_log debug "setNo=$setNo query=" $hist($setNo,$i,query) "="
1194 if {[catch {z39$i.$setNo search $hist($setNo,$i,query)}]} {
1198 } elseif {[z39$i.$setNo resultCount] >= $start} {
1199 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1200 set tnumber [expr [z39$i.$setNo resultCount] - $start + 1]
1204 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1207 set thisElements $elements
1209 z39$i.$setNo smallSetElementSetNames $thisElements
1210 z39$i.$setNo mediumSetElementSetNames $thisElements
1211 z39$i.$setNo elementSetNames $thisElements
1212 z39$i.$setNo recordElements $thisElements
1214 for {set n 0} {$n < $tnumber} {incr n} {
1215 if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
1217 egw_log debug "failed on $n"
1220 html "no record at #" [expr $start + $n]
1221 html " el=-" $thisElements "-"
1226 if {$n == $tnumber} {
1233 html "present<br>\n"
1234 z39$i callback [list search-m-response $setNo $i $start $tnumber]
1236 egw_log debug "mpresent start=$start number=$tnumber"
1237 z39$i.$setNo present $start $tnumber
1244 while {$zleft > 0} {
1245 egw_log debug "Waiting for search/present response"
1246 if {[catch {egw_wait zleft 60}]} {
1250 for {set i 1} {$i <= $not} {incr i} {
1251 if {$zstatus($i) != 2} continue
1252 set status [z39$i.$setNo responseStatus]
1253 if {0 && [lindex $status 0] != "NSD"} {
1254 set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned]
1259 proc z39present {setNo tno setOffset setMax dfunc elements} {
1265 set host $hist($setNo,$tno,host)
1267 if {![lindex $targets($host) 5]} {
1271 $zz.$setNo elementSetNames $elements
1272 $zz.$setNo recordElements $elements
1273 set toGet [expr 1 + $setMax - $setOffset]
1275 $zz callback [list search-response $zz.$setNo]
1277 while {$setMax > 0 && $toGet > 0} {
1278 for {set got 0} {$got < $toGet} {incr got} {
1279 if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
1283 if {$got < $toGet} {
1285 $zz.$setNo present $setOffset $toGet
1286 if {[catch {egw_wait sessionWait 300}]} {
1287 egw_log debug "timeout/cancel in present"
1291 if {$sessionWait == "0"} {
1294 if {$sessionWait != "1"} {
1297 set got [$zz.$setNo numberOfRecordsReturned]
1302 display-rec $setOffset [expr $got + $setOffset - 1] $dfunc $setNo $tno
1303 set setOffset [expr $got + $setOffset]
1304 set toGet [expr 1 + $setMax - $setOffset]
1309 proc buttons-result-set-s {setNo targetNo setMax startPos after} {
1318 if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
1322 html {<a href="http:} $env(SCRIPT_NAME)
1323 html / $sessionId {/search.egw/} $setNo + $targetNo +
1324 html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
1326 html {"><img src="/egwgif/button-next-records.gif" }
1327 html {alt="Next Records" border=0></a>}
1329 html {">Next Records</a>}
1332 if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
1336 html {<a href="http:} $env(SCRIPT_NAME)
1337 html / $sessionId {/search.egw/} $setNo + $targetNo
1338 html + [expr $startPos - $hist($setNo,maxPresent)]
1339 html + [expr $startPos - 1]
1341 html {"><img src="/egwgif/button-previous-records.gif" }
1342 html {alt="Previous Records" border=0></a>}
1344 html {">Previous Records</a>}
1347 if {$targetNo > 0} {
1348 button-result-set $setNo $targetNo
1350 button-new-query $setNo
1357 proc score-sort {l r} {
1358 return [expr [lindex $r 0] - [lindex $l 0]]
1361 proc display-result-set-m-score {setNo} {
1367 set not $hist($setNo,0,host)
1368 for {set i 1} {$i <= $not} {incr i} {
1369 if {$zstatus($i) != 2} continue
1370 set status [z39$i.$setNo responseStatus]
1371 if {[lindex $status 0] != "DBOSD"} continue
1372 set nor $hist($setNo,$i,offset)
1373 for {set j 1} {$j <= $nor} {incr j} {
1374 if {![string compare [z39$i.$setNo recordType $j] WAIS]} {
1375 set score [z39$i.$setNo getWAIS $j score]
1376 } elseif {![string compare [z39$i.$setNo recordType $j] USmarc]} {
1377 set score [z39$i.$setNo getMarc $j field 999 * r]
1378 if {[scan $score %d score] != 1} {
1385 lappend scoreArray [list $score $i $j]
1389 if {![info exists scoreArray]} {
1390 html "<br><h3>Search produced no result</h3><br>\n"
1393 set scoreSorted [lsort -command score-sort $scoreArray]
1394 foreach r $scoreSorted {
1397 display-$hist($setNo,format) z39$i.$setNo $j $setNo $i
1401 for {set i 1} {$i <= $not} {incr i} {
1402 if {$zstatus($i) != 2} continue
1403 set status [z39$i.$setNo responseStatus]
1404 if {[lindex $status 0] == "NSD"} {
1405 z39$i.$setNo nextResultSetPosition 0
1406 set code [lindex $status 1]
1407 set msg [lindex $status 2]
1408 set addinfo [lindex $status 3]
1409 html {<dt>} [lindex $targets($hist($setNo,$i,host)) 0]
1410 html "<dd>Error: $msg: $addinfo (code $code)<br>\n"
1416 proc display-result-set-m-server {setNo} {
1424 set not $hist($setNo,0,host)
1426 for {set i 1} {$i <= $not} {incr i} {
1427 if {$zstatus($i) != 2} continue
1428 set status [z39$i.$setNo responseStatus]
1429 if {[lindex $status 0] == "NSD"} {
1430 html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
1431 z39$i.$setNo nextResultSetPosition 0
1432 set code [lindex $status 1]
1433 set msg [lindex $status 2]
1434 set addinfo [lindex $status 3]
1435 html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
1437 html {<dt><a href="http:} $env(SCRIPT_NAME)
1438 html / $sessionId {/search.egw/} $setNo + $i + 1
1439 html + $hist($setNo,maxPresent) {">}
1440 html "<h3>" [lindex $targets($hist($setNo,$i,host)) 0] "</a>: "
1441 set r [z39$i.$setNo resultCount]
1442 html "$r hits</h3>\n<dd>\n"
1444 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1445 set nor $hist($setNo,maxPresent)
1447 set nor $hist($setNo,$i,offset)
1449 display-rec 1 $nor display-$hist($setNo,format) $setNo $i
1456 proc display-result-set-m {setNo} {
1462 egw_log debug "sort=$hist($setNo,sort)"
1463 switch $hist($setNo,sort) {
1465 display-result-set-m-score $setNo
1468 display-result-set-m-server $setNo
1473 proc display-result-set-s {setNo targetNo startPos endPos} {
1478 set host $hist($setNo,$targetNo,host)
1479 set idAuth $hist($setNo,$targetNo,idAuthentication)
1480 set database $hist($setNo,$targetNo,database)
1481 set query $hist($setNo,$targetNo,query)
1485 if {$startPos == ""} {
1486 if {[z39search $setNo 1 $targetNo B] != "1"} {
1489 set r [$zz.$setNo resultCount]
1491 set setMax [$zz.$setNo resultCount]
1492 if {$setMax > $hist($setNo,maxPresent)} {
1493 set setMax $hist($setNo,maxPresent)
1495 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1497 set setOffset [$zz.$setNo numberOfRecordsReturned]
1499 html {<h3> Records 1-} $setMax " out of $r</h3>\n"
1501 html "<h3> No hits</h3>\n"
1505 display-rec 1 $setMax display-brief $setNo $targetNo
1509 if {[z39search $setNo 0 $targetNo B] != "1"} {
1512 set r [$zz.$setNo resultCount]
1513 set setOffset $startPos
1514 set setMax [$zz.$setNo resultCount]
1515 if {$setMax > $endPos} {
1518 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1520 html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
1522 html "<h3> No hits</h3>\n"
1528 z39present $setNo $targetNo $setOffset $setMax display-brief B
1532 buttons-result-set-s $setNo $targetNo $setMax $startPos 1
1535 proc z39history {} {
1544 if {![info exists nextSetNo]} {
1547 html "<h2>History</h2><br>\n"
1549 html {<table width=500 border=1><tr>}
1550 html {<td align=center><b>Target</b>}
1551 html {<td align=center><b>Database</b>}
1552 html {<td align=center><b>Hits</b>}
1553 html {<td align=center><b>Query</b>}
1558 for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
1559 if {[info exists hist($setNo,scan)]} {
1560 if {$hist($setNo,scan) > 0} continue
1562 if {[info exists hist($setNo,1,host)]} {
1564 set end $hist($setNo,0,host)
1569 for {set i $start} {$i <= $end} {incr i} {
1571 html {<td align=left>}
1575 set host $hist($setNo,$i,host)
1576 html [lindex $targets($host) 0]
1578 html {<td align=left>} [join $hist($setNo,$i,database)]
1580 if {[llength [lindex $targets($host) 1]] > 1} {
1582 foreach b $hist($setNo,$i,database) {
1589 html {<td align=right>}
1591 if {[info exists hist($setNo,$i,hits)]} {
1592 html { <a href="http:} $env(SCRIPT_NAME)
1593 html / $sessionId {/search.egw/} $setNo + $i + 1
1594 html + $hist($setNo,maxPresent)
1595 html {">} $hist($setNo,$i,hits) {</a>}
1600 html {Search failed.}
1604 html {<td align=left>}
1608 html { <a href="http:} $env(SCRIPT_NAME)
1609 html / $sessionId / $scriptQuery {;/} $setNo + $host
1613 html {">Query</a>: }
1616 for {set j 1} {$j <= 3} {incr j} {
1617 if {[string length $hist($setNo,form,entry$j)] > 0} {
1618 html " <b>" [join $op " "] "</b> "
1619 set pre [join $hist($setNo,form,menu$j)]
1620 if {[string length $pre] > 0} {
1623 html $hist($setNo,form,entry$j)
1624 set op $hist($setNo,form,logic$j)
1628 html {</a><tr>} "\n"
1640 proc displayError {msga msgb} {
1641 html "<p><center>\n"
1642 html {<img src="/egwgif/noway.gif" alt="Error">}
1643 html "<h2>" $msga "</h2>\n"
1644 if {[string length $msgb] > 0} {
1645 html "<h3>" $msgb "</h3>\n"
1647 html "</center><p>\n"
1650 proc button-main {} {
1652 html {<a href="http://europagate.dtv.dk/">}
1654 html {<img src="/egwgif/button-egw.gif" alt="Europagate" border=0></a>}
1656 html {Europagate</a>}
1660 proc button-define-target {} {
1668 html {<a href="http:} $env(SCRIPT_NAME)
1669 html / $sessionId {/tform.egw}
1671 html {"><img src="/egwgif/button-define-target.gif" }
1672 html {alt="Define Target" border=0></a>}
1674 html {">Define Target</a>}
1678 proc button-new-target {} {
1684 if {[string length $scriptTarget] == 0} return
1689 html {<a href="http:} $env(SCRIPT_NAME)
1690 html / $sessionId / $scriptTarget
1692 html {"><img src="/egwgif/button-new-target.gif" }
1693 html {alt="New Target" border=0></a>}
1695 html {">New Target</a>}
1699 proc button-view-history {} {
1708 html {<a href="http:} $env(SCRIPT_NAME)
1709 html / $sessionId {/history.egw;}
1710 catch { html "/" $nextSetNo}
1712 html {"><img src="/egwgif/button-view-history.gif" alt="View History" }
1713 html {border=0></a>}
1715 html {">View History</a>}
1719 proc button-new-query {setNo} {
1729 html {<a href="http:} $env(SCRIPT_NAME)
1730 html / $sessionId / $scriptQuery {;/} $setNo + $hist($setNo,0,host) {">}
1733 html {<img src="/egwgif/button-new-query.gif" }
1734 html {alt="New Query" border=0></a>}
1736 html {New Query</a>}
1740 proc button-result-set {setNo tno} {
1749 html {<a href="http:} $env(SCRIPT_NAME) / $sessionId
1751 html {/msearch.egw/} $setNo
1753 html {/search.egw/} $setNo + $tno
1755 html + 1 + $hist($setNo,maxPresent)
1757 html {"><img src="/egwgif/button-result-set.gif" }
1758 html {alt="Result Set" border=0></a>}
1760 html {">Result Set</a>}
1764 proc button-scan-window {setNo} {
1774 html {<a href="http:} $env(SCRIPT_NAME)
1775 html / $sessionId {/search.egw/} $setNo + $targetNo + {scan} {">}
1777 html {<img src="/egwgif/button-scan-window.gif" }
1778 html {alt="Scan" border=0></a>}
1784 proc maintenance {} {
1785 html {<hr>This page is maintained by }
1786 html {<a href="mailto:pwh@dtv.dk"> Peter Wad Hansen </a>.}
1787 html {Last modified 29. january 1996. <br>}
1788 html {<em> This and the following pages are under construction and }
1789 html {will continue to be so until the end of January 1996.</em>}
1792 proc splitHostSpec {host} {
1793 set i [string first / $host]
1796 return [string range $host 0 $i]
1801 proc splitDatabaseSpec {host} {
1802 set i [string first / $host]
1805 regsub -all -- - [string range $host $i end] { } res
1808 regsub -all -- - $host {} res
1812 proc mergeHostSpec {host databases} {
1813 return ${host}/[join $databases -]
1816 proc mkAssoc {assoc host} {
1819 if {[catch {$assoc failback fail-response}]} {
1820 if {![string compare [lindex $targets($host) 1] WAIS]} {
1826 if {![string compare [lindex $targets($host) 1] WAIS]} {
1827 if {[$assoc comstack] == "wais"} return
1830 if {[$assoc comstack] == "tcpip"} return
1836 proc serverList {headlineProc targetProc} {
1838 global groupsDescription
1840 proc targetsCmp {l r} {
1842 return [string compare [string tolower [lindex $targets($l) 0]] \
1843 [string tolower [lindex $targets($r) 0]]]
1845 proc groupCmp {l r} {
1847 if {[catch {set lo $groupsOrder($l)}]} {
1850 if {[catch {set ro $groupsOrder($r)}]} {
1853 return [expr $lo - $ro]
1856 foreach tt [array names targets] {
1857 lappend groupsTmp([lindex $targets($tt) 6]) $tt
1859 set gts [lsort -command groupCmp [array names groupsTmp]]
1861 if {[info exists groupsDescription($gt)]} {
1862 eval $headlineProc [list $groupsDescription($gt)]
1864 eval $headlineProc $gt
1866 set tn [lsort -command targetsCmp $groupsTmp($gt)]
1872 rename targetsCmp {}
1875 if {[info exists utilExtension]} {
1876 source $utilExtension