2 # $Id: z39util.tcl,v 1.39 1996/03/12 16:30:30 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]
124 html { <a href="http:} $env(SCRIPT_NAME) /
125 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
156 set v [join $cover ""]
157 if {[string length $v] > 0} {
165 html { <a href="http:} $env(SCRIPT_NAME) /
166 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
169 html "Error: " $dispError "\n"
174 proc display-brief {zset no setNo targetNo} {
179 set type [$zset type $no]
181 set err [lindex [$zset diag $no] 1]
182 set add [lindex [$zset diag $no] 2]
186 html "${no} Error ${err}${add} <br>\n"
192 set rtype [$zset recordType $no]
195 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
196 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
197 html [string range [join [$zset getSutrs $no]] 0 70]
202 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
203 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
204 html [string range [join [$zset getWAIS $no headline]] 0 70]
207 set score [$zset getWAIS $no score]
208 html { Score } $score
214 set author [$zset getMarc $no field 100 * a]
215 set corp [$zset getMarc $no field 110 * a]
216 set meet [$zset getMarc $no field 111 * a]
217 set title [$zset getMarc $no field 245 * a]
218 if {[llength $author] == 0} {
219 set cover [$zset getMarc $no field 245 * {[bc]}]
221 set cover [$zset getMarc $no field 245 * b]
223 set location [$zset getMarc $no field 260 * a]
224 set publisher [$zset getMarc $no field 260 * b]
225 set year [$zset getMarc $no field 260 * c]
227 html { <a href="http:} $env(SCRIPT_NAME) /
228 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
262 set v [join $cover ""]
263 if {[string length $v] > 40} {
265 html [string range $v 0 38] "..."
266 } elseif {[string length $v] > 0} {
275 html { <a href="http:} $env(SCRIPT_NAME) /
276 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
279 html "Error: " $dispError "\n"
284 proc display-raw {zset no setNo targetNo} {
285 set type [$zset type $no]
288 set err [lindex [$zset diag $no] 1]
289 set add [lindex [$zset diag $no] 2]
293 html "<h3>${no}</h3>\n"
294 html "Error ${err}${add} <br>\n"
303 set rtype [$zset recordType $no]
306 html "<xmp>\n" [join [$zset getSutrs $no]] "\n</xmp>\n"
310 html "<xmp>\n" [join [$zset getWAIS $no text]] "\n</xmp>\n"
314 if {[catch {set r [$zset getMarc $no line * * *]}]} {
315 html "Unknown record type: $rtype <br>\n"
319 set tag [lindex $line 0]
320 set indicator [lindex $line 1]
321 set fields [lindex $line 2]
322 set l [string length $indicator]
325 for {set i 0} {$i < $l} {incr i} {
326 if {[string index $indicator $i] == " "} {
329 html [string index $tag $i]
334 foreach field $fields {
335 set id [lindex $field 0]
336 set data [lindex $field 1]
338 html " <b>\$$id</b> "
346 proc put-marc-contents {cc} {
348 if {[string first :// $cc] > 0} {
349 foreach urltype {gopher http ftp mailto} {
350 if {[string first ${urltype}:// $cc] == 0} {
365 proc dl-marc-field {zset no tag id la lb sep} {
367 set c [$zset getMarc $no field $tag * $id]
372 if {$len > 1 && "x$lb" != "x"} {
373 html "<dt><b>$lb</b>\n<dd>"
375 html "<dt><b>$la</b>\n<dd>"
381 put-marc-contents $cc
387 proc dd-marc-field {zset no tag id start stop} {
389 set c [$zset getMarc $no field $tag * $id]
396 put-marc-contents $cc
403 proc dl-marc-field-rec {zset no tag lead start stop startid sep} {
405 set lines [$zset getMarc $no line $tag * *]
406 foreach line $lines {
407 foreach field [lindex $line 2] {
409 html "<dt><b>$lead</b>"
412 set id [lindex $field 0]
413 if {$id == $startid} {
419 html [lindex $field 1]
422 html [lindex $field 1]
431 proc display-full-marc {zset no setNo targetNo} {
437 set n [dl-marc-field $zset $no 700 a "Author" "Authors" "<br>\n"]
439 set n [dl-marc-field $zset $no 100 a "Author" "Authors" "<br>\n"]
441 set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
443 set n [dl-marc-field $zset $no 110 a "Corporate Name" {} ", "]
445 set n [dl-marc-field $zset $no 711 a "Meeting Name" {} ", "]
447 dd-marc-field $zset $no 711 {[bndc]} " " ""
449 set n [dl-marc-field $zset $no 111 a "Meeting Name" {} ", "]
451 dd-marc-field $zset $no 111 {[bndc]} " " " "
454 set n [dl-marc-field $zset $no 245 {a} "Title" {} " "]
456 dd-marc-field $zset $no 245 b "<em>" "</em>"
457 dd-marc-field $zset $no 245 c " " ""
459 dl-marc-field $zset $no 245 {[ab]} "Title" {} " "
461 dl-marc-field $zset $no 520 a "Abstract" {} ", "
462 dl-marc-field $zset $no 072 * "Subject code" "Subject codes" ", "
463 dl-marc-field $zset $no 650 * "Subject" {} ", "
464 dl-marc-field $zset $no 260 * "Publisher" {} " "
465 dl-marc-field $zset $no 300 * "Physical Description" {} " "
467 dl-marc-field-rec $zset $no 500 "Notes" "" "<br>\n" "a" ", "
469 dl-marc-field-rec $zset $no 510 "References" "" "<br>\n" "a" ", "
471 dl-marc-field-rec $zset $no 511 "Participant note" "" "<br>\n" "a" ", "
473 dl-marc-field $zset $no 513 a "Report type" {} ", "
474 dl-marc-field $zset $no 513 b "Period covered" {} ", "
475 dl-marc-field-rec $zset $no 515 "Numbering notes" "" "<br>\n" "a" ", "
476 dl-marc-field-rec $zset $no 516 "Data notes" "" "<br>\n" "a" ", "
477 dl-marc-field-rec $zset $no 518 "Date/time notes" "" "<br>\n" "a" ", "
479 dl-marc-field $zset $no 350 a "Price" {} ", "
480 dl-marc-field $zset $no 362 a "Dates of publication" {} ", "
481 dl-marc-field $zset $no 850 a "Holdings" {} ", "
483 dl-marc-field-rec $zset $no 270 "Contact name" "" "<br>\n" p ", "
485 set n [dl-marc-field $zset $no 270 p "Contact name" {} ", "]
490 dl-marc-field $zset $no 270 a "Street" {} ", "
491 dl-marc-field $zset $no 270 b "City" {} ", "
492 dl-marc-field $zset $no 270 c "State" {} ", "
493 dl-marc-field $zset $no 270 e "Zip code" {} ", "
494 dl-marc-field $zset $no 270 d "Country" {} ", "
495 dl-marc-field $zset $no 270 m "Network address" {} ", "
496 dl-marc-field $zset $no 301 a "Service hours" {} ", "
497 dl-marc-field $zset $no 270 k "Phone" {} ", "
498 dl-marc-field $zset $no 270 l "Fax" {} ", "
500 dl-marc-field $zset $no 270 {[abcedmakl]} "Address" {} "<br>\n"
506 dl-marc-field $zset $no 010 a "LC control number" {} ", "
507 dl-marc-field $zset $no 010 b "NUCMC control number" {} ", "
508 dl-marc-field $zset $no 020 a "ISBN" {} ", "
509 dl-marc-field $zset $no 022 a "ISSN" {} ", "
510 set url [$zset getMarc $no field 856 * u]
511 set sp [$zset getMarc $no field 856 * 3]
512 if {"x$url" != "x"} {
513 html "<dt><b>URL</b>\n"
517 html {<dd><a href="} [join $url] {">} [join $sp] "</a>\n"
519 dl-marc-field $zset $no 037 {[abc]} "Acquisition" {} "<br>\n"
520 dl-marc-field $zset $no 037 {[f6]} "Form of issue" {} "<br>\n"
521 dl-marc-field $zset $no 537 * "Source of data" {} "<br>\n"
522 dl-marc-field $zset $no 538 * "System details" {} "<br>\n"
523 dl-marc-field $zset $no 787 {[rstw6]} "Related information" {} "<br>\n"
524 dl-marc-field $zset $no 001 * "Local control number" {} ", "
528 proc display-full-wais {zset no setNo targetNo} {
535 htmlToken l [join [$zset getWAIS $no text]] {
536 if {[string compare [string index $l 0] {<}]} {
537 if {[info exist data($element)]} {
538 set data($element) $data($element)$l
540 set data($element) $l
549 set element dateOfLastModification
552 set element controlIdentifier
555 set element lastChecked
567 set element "$i,linkage"
570 set element "$i,title"
580 if {![info exists data(title)] || ![info exists data(linkage)]} {
586 html {<dt><b>Title</b>}
588 html {<dd><a href="} $data(linkage) {">} $data(title) "</a>"
589 html {<dt><b>URL</b>}
590 html {<dd>} $data(linkage) "<br>\n"
592 html {<dd>} [join [$zset getWAIS $no headline]]
594 html {<dt><b>Score</b><dd>} [$zset getWAIS $no score]
595 set lines [$zset getWAIS $no lines]
597 html {<dt><b>Lines</b><dd>} $lines "<br>\n"
600 html "</dl><pre>\n" [join [$zset getWAIS $no text]] "\n</pre>\n"
603 if {[info exists data(bytes)]} {
604 html {<dt><b>Bytes</b><dd>} $data(bytes)
606 if {[info exists data(dateOfLastModification)]} {
607 html {<dt><b>Last modified</b><dd>} $data(dateOfLastModification)
609 if {[info exists data(lastChecked)]} {
610 html {<dt><b>Last checked</b><dd>} $data(lastChecked) "<br>\n"
612 if {[info exists data(ip)]} {
613 html {<dt><b>Initial text</b><dd>} $data(ip) "</dl><br>\n"
616 html {<a href="} $env(SCRIPT_NAME) / $sessionId {/sameas.egw/}
617 html $setNo + $targetNo + 1 + $hist($setNo,maxPresent) +
618 html [egw_enc [$zset getWAIS $no documentID]] {">}
619 html {Similar WAIS record</a><br>}
621 html "<dt><b>References</b>\n"
622 for {set i 1} {[info exists data($i,linkage)]} {incr i} {
623 html {<dd><a href="} $data($i,linkage) {">}
624 if {[info exists data($i,title)]} {
634 proc display-full {zset no setNo targetNo} {
635 set type [$zset type $no]
638 set err [lindex [$zset diag $no] 1]
639 set add [lindex [$zset diag $no] 2]
643 html "Error ${err}${add} <br>\n"
652 set rtype [$zset recordType $no]
655 html "<pre>" [join [$zset getSutrs $no]] "</pre><br>\n"
659 display-full-wais $zset $no $setNo $targetNo
663 if {[catch {set r [$zset getMarc $no line * * *]}]} {
664 html "Unknown record type: $rtype <br>\n"
667 display-full-marc $zset $no $setNo $targetNo
671 proc display-rec {from to dfunc setNo targetNo} {
672 while {$from <= $to} {
673 eval "$dfunc z39${targetNo}.${setNo} $from $setNo $targetNo"
678 proc build-scan {t i} {
681 set term [egw_form entry$i]
683 set field [join [egw_form menu$i]]
685 foreach x [lindex $targets($t) 2] {
686 if {[lindex $x 0] == $field} {
687 set attr [lindex $x 1]
690 return [list $term $attr]
695 proc build-query {t ilines} {
700 for {set i 1} {$i <= $ilines} {incr i} {
701 set term [join [egw_form entry$i]]
702 if {[string length $term] == 0} continue
703 if {![string compare [lindex $targets($t) 1] WAIS]} {
704 if {[string length $q] == 0} {
709 set op [egw_form logic$i]
712 set field [join [egw_form menu$i]]
714 foreach x [lindex $targets($t) 2] {
715 if {![string compare [lindex $x 0] $field]} {
716 set attr [lindex $x 1]
719 if {![info exists attr]} {
720 egw_log debug "attr failed for $t"
721 set attr [lindex [lindex [lindex $targets($t) 2] 0] 1]
725 { set q "@and $q ${attr} \"${term}\"" }
727 { set q "@or $q ${attr} \"${term}\"" }
729 { set q "@not $q ${attr} \"${term}\"" }
731 { set q "${attr} \"${term}\"" }
733 set op [egw_form logic$i]
739 proc z39scan {setNo scanNo tno scanLines scanPos cache} {
745 set host $hist($setNo,$tno,host)
746 set idAuth $hist($setNo,$tno,idAuthentication)
747 set database $hist($setNo,$tno,database)
748 set scanAttr $hist($setNo,scanAttr)
749 set scanTerm $hist($setNo,$scanNo,scanTerm)
752 if {[catch [list set oldHost [$zz connect]]]} {
755 set zs $zz.s$scanNo.$setNo
756 $zz callback ok-response
757 $zz failback fail-response
758 set thisHost [splitHostSpec $host]
759 if {[string compare $oldHost $thisHost]} {
760 catch [list $zz disconnect]
763 if {[catch [list $zz connect $thisHost]]} {
764 displayError "Cannot connect to target" $thisHost
766 } elseif {$sessionWait == 0} {
767 if {[catch {egw_wait sessionWait 300}]} {
769 displayError "Cannot connect to target" $thisHost
772 if {$sessionWait != 1} {
773 displayError "Cannot connect to target" $thisHost
777 $zz idAuthentication $idAuth
779 if {[catch {$zz init}]} {
780 displayError "Cannot initialize target" $thisHost
784 if {[catch {egw_wait sessionWait 60}]} {
785 displayError "Cannot initialize target" $thisHost
789 if {$sessionWait != "1"} {
790 displayError "Cannot initialize target" $thisHost
794 if {![$zz initResult]} {
795 set u [$zz userInformationField]
797 displayError "Cannot initialize target $thisHost" $u
801 if {$cache && ![catch [list $zs numberOfTermsRequested 5]]} {
805 eval $zz databaseNames $database
809 $zs numberOfTermsRequested $scanLines
810 $zs preferredPositionInResponse $scanPos
812 $zz callback [list scan-response $zs]
814 egw_log debug "scan: ${scanAttr} ${scanTerm}"
816 $zs scan "${scanAttr} ${scanTerm}"
818 if {[catch {egw_wait sessionWait 60}]} {
819 egw_log debug "timeout/cancel in scan"
820 displayError "Timeout in scan" {}
821 html "</body></html>\n"
825 if {$sessionWait == -1} {
826 displayError "Scan fail" "Connection closed"
827 html "</body></html>\n"
830 if {$sessionWait != 1} {
836 proc display-scan {setNo scanNo tno} {
844 set zs $zz.s$scanNo.$setNo
845 set m [$zs numberOfEntriesReturned]
848 set t [lindex [$zs scanLine 0] 1]
850 set hist($setNo,$tno,[expr $scanNo - 1],scanTerm) $t
852 set hist($setNo,[expr $scanNo - 1],scanTerm) $t
854 set t [lindex [$zs scanLine [expr $m - 1]] 1]
856 set hist($setNo,$tno,[expr $scanNo + 1],scanTerm) $t
858 set hist($setNo,[expr $scanNo + 1],scanTerm) $t
861 html {<table width=500 border=0><tr>}
862 html {<td align=left><b>Scan term</b>}
863 html {<td align=right><b>Hits</b>}
866 for {set i 0} {$i < $m} {incr i} {
867 html {<td align=left>}
869 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
870 html {<a href="http:} $env(SCRIPT_NAME)
871 html / $sessionId / $scriptQuery / $setNo + $hist($setNo,host) +
872 html $hist($setNo,scan) + $tterm {">}
874 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
875 html {<a href="http:} $env(SCRIPT_NAME)
876 html / $sessionId {/search.egw/} $setNo + $tno +
877 html hyper + $tterm {">}
879 html [lindex [$zs scanLine $i] 1]
881 html {<td align=right>}
882 html [lindex [$zs scanLine $i] 2]
888 proc z39search {setNo piggy tno elements} {
894 set host $hist($setNo,$tno,host)
895 set idAuth $hist($setNo,$tno,idAuthentication)
896 set database $hist($setNo,$tno,database)
897 set query $hist($setNo,$tno,query)
898 catch {set docId $hist($setNo,$tno,queryId)}
901 if {[catch [list set oldHost [$zz connect]]]} {
904 $zz callback ok-response
905 $zz failback fail-response
906 set thisHost [splitHostSpec $host]
907 if {[string compare $oldHost $thisHost]} {
908 catch [list $zz disconnect]
911 if {[catch [list $zz connect $thisHost]]} {
912 displayError "Cannot connect to target" $thisHost
914 } elseif {$sessionWait == 0} {
915 if {[catch {egw_wait sessionWait 300}]} {
917 displayError "Cannot connect to target" $thisHost
920 if {$sessionWait != 1} {
921 displayError "Cannot connect to target" $thisHost
925 $zz idAuthentication $idAuth
927 if {[catch {$zz init}]} {
928 displayError "Cannot initialize target" $thisHost
932 if {$sessionWait == 0 && [catch {egw_wait sessionWait 60}]} {
933 displayError "Cannot initialize target" $thisHost
937 if {$sessionWait != "1"} {
938 displayError "Cannot initialize target" $thisHost
942 if {![$zz initResult]} {
943 set u [$zz userInformationField]
945 displayError "Cannot initialize target $thisHost" $u
948 } elseif {![catch [list $zz.$setNo smallSetUpperBound 0]]} {
950 if {[info exists hist($setNo,$tno,hits)]} {
954 if {[info exists hist($setNo,hits)]} {
960 if {![string compare [lindex $targets($host) 1] WAIS]} {
961 wais-set $zz.$setNo $zz
963 ir-set $zz.$setNo $zz
964 $zz.$setNo preferredRecordSyntax [lindex $targets($host) 1]
965 egw_log debug "set syntax to [lindex $targets($host) 1]"
967 if {![lindex $targets($host) 5]} {
970 $zz.$setNo smallSetElementSetNames $elements
971 $zz.$setNo mediumSetElementSetNames $elements
972 $zz.$setNo recordElements $elements
974 egw_log debug "database=$database"
975 eval $zz.$setNo databaseNames $database
977 $zz callback [list search-response $zz.$setNo]
979 $zz.$setNo largeSetLowerBound 999999
980 $zz.$setNo smallSetUpperBound 0
981 $zz.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
983 $zz.$setNo largeSetLowerBound 2
984 $zz.$setNo smallSetUpperBound 0
985 $zz.$setNo mediumSetPresentNumber 0
988 egw_log debug "search: $query"
990 if {[info exists docId]} {
991 $zz.$setNo search $query $docId
993 $zz.$setNo search $query
996 if {!$sessionWait && [catch {egw_wait sessionWait 60}]} {
997 egw_log debug "timeout/cancel in search"
998 displayError "Timeout in search" {}
999 html "</body></html>\n"
1004 if {$sessionWait == -1} {
1005 displayError "Search fail" "Connection closed"
1006 html "</body></html>\n"
1009 if {$sessionWait != 1} {
1012 set hist($setNo,hits) [$zz.$setNo resultCount]
1016 proc init-m-response {i} {
1020 egw_log debug "init-m-response"
1023 if {![z39$i initResult]} {
1031 proc connect-m-response {i} {
1035 egw_log debug "connect-m-response"
1036 z39$i callback [list init-m-response $i]
1037 if {[catch {z39$i init}]} {
1043 proc fail-m-response {i} {
1047 egw_log debug "fail-m-response"
1052 proc search-m-response {setNo i start number} {
1057 egw_log debug "search-m-response"
1058 set status [z39$i.$setNo responseStatus]
1059 egw_log debug "search-m-response1"
1060 if {[lindex $status 0] == "OK"} {
1062 } elseif {[lindex $status 0] == "DBOSD"} {
1063 set nor [z39$i.$setNo numberOfRecordsReturned]
1065 egw_log debug "search-m-response2"
1070 set hist($setNo,$i,hits) [z39$i.$setNo resultCount]
1071 egw_log debug "search-m-response3"
1072 set hist($setNo,$i,offset) [expr $start + $nor -1]
1073 if {[expr $nor + $start] > [z39$i.$setNo resultCount]} {
1074 egw_log debug "search-m-response4"
1079 egw_log debug "search-m-response5"
1080 if {$nor >= $number} {
1081 egw_log debug "search-m-response6 nor=$nor number=$number"
1086 egw_log debug "search-m-response7"
1087 set start [expr $start + $nor]
1088 set number [expr $number - $nor]
1089 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1090 set number [expr [z39$i.$setNo resultCount] - $start + 1]
1092 z39$i callback [list search-m-response $setNo $i $start $number]
1093 egw_log debug "mpresent start=$number number=$number"
1094 z39$i.$setNo present $start $number
1097 proc z39msearch {setNo elements start number cache} {
1104 set not $hist($setNo,0,host)
1106 egw_log debug "z39msearch start=$start number=$number elements=$elements"
1107 for {set i 1} {$i <= $not} {incr i} {
1108 set host $hist($setNo,$i,host)
1110 set oldHost [z39$i connect]
1111 set thisHost [splitHostSpec $host]
1112 if {[string compare $oldHost $thisHost]} {
1113 catch {z39$i disconnect}
1115 z39$i callback [list connect-m-response $i]
1116 z39$i failback [list fail-m-response $i]
1119 for {set i 1} {$i <= $not} {incr i} {
1120 set oldHost [z39$i connect]
1121 set host $hist($setNo,$i,host)
1122 set thisHost [splitHostSpec $host]
1123 if {![string compare $oldHost $thisHost]} {
1126 egw_log debug "old=$oldHost this=$thisHost"
1127 z39$i idAuthentication $hist($setNo,$i,idAuthentication)
1128 html "Connecting to target " $thisHost " <br>\n"
1130 if {![catch {z39$i connect $thisHost}]} {
1134 while {$zleft > 0} {
1135 egw_log debug "Waiting for init response"
1136 if {[catch {egw_wait zleft 20}]} {
1141 for {set i 1} {$i <= $not} {incr i} {
1142 set host $hist($setNo,$i,host)
1144 html "host " [splitHostSpec $host] ": "
1146 egw_log debug "i=$i zstatus=$zstatus($i)"
1147 if {$zstatus($i) < 1} {
1153 if {[catch [list z39$i.$setNo preferredRecordSyntax]]} {
1158 if {![string compare [lindex $targets($host) 1] WAIS]} {
1159 wais-set z39$i.$setNo z39$i
1161 ir-set z39$i.$setNo z39$i
1162 z39$i.$setNo preferredRecordSyntax [lindex $targets($host) 1]
1163 egw_log debug "set syntax to [lindex $targets($host) 1]"
1165 set hist($setNo,$i,offset) 0
1166 eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
1168 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1171 set thisElements $elements
1173 z39$i.$setNo smallSetElementSetNames $thisElements
1174 z39$i.$setNo mediumSetElementSetNames $thisElements
1175 z39$i.$setNo elementSetNames $thisElements
1176 z39$i.$setNo recordElements $thisElements
1178 z39$i callback [list search-m-response $setNo $i $start $number]
1181 z39$i.$setNo largeSetLowerBound 999999
1182 z39$i.$setNo smallSetUpperBound 0
1183 z39$i.$setNo mediumSetPresentNumber $number
1185 z39$i.$setNo largeSetLowerBound 2
1186 z39$i.$setNo smallSetUpperBound 0
1187 z39$i.$setNo mediumSetPresentNumber 0
1191 egw_log debug "msearch host=" $hist($setNo,$i,host)
1192 egw_log debug "setNo=$setNo query=" $hist($setNo,$i,query) "="
1193 if {[catch {z39$i.$setNo search $hist($setNo,$i,query)}]} {
1197 } elseif {[z39$i.$setNo resultCount] >= $start} {
1198 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1199 set tnumber [expr [z39$i.$setNo resultCount] - $start + 1]
1203 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1206 set thisElements $elements
1208 z39$i.$setNo smallSetElementSetNames $thisElements
1209 z39$i.$setNo mediumSetElementSetNames $thisElements
1210 z39$i.$setNo elementSetNames $thisElements
1211 z39$i.$setNo recordElements $thisElements
1213 for {set n 0} {$n < $tnumber} {incr n} {
1214 if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
1216 egw_log debug "failed on $n"
1219 html "no record at #" [expr $start + $n]
1220 html " el=-" $thisElements "-"
1225 if {$n == $tnumber} {
1232 html "present<br>\n"
1233 z39$i callback [list search-m-response $setNo $i $start $tnumber]
1235 egw_log debug "mpresent start=$start number=$tnumber"
1236 z39$i.$setNo present $start $tnumber
1243 while {$zleft > 0} {
1244 egw_log debug "Waiting for search/present response"
1245 if {[catch {egw_wait zleft 60}]} {
1249 for {set i 1} {$i <= $not} {incr i} {
1250 if {$zstatus($i) != 2} continue
1251 set status [z39$i.$setNo responseStatus]
1252 if {0 && [lindex $status 0] != "NSD"} {
1253 set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned]
1258 proc z39present {setNo tno setOffset setMax dfunc elements} {
1264 set host $hist($setNo,$tno,host)
1266 if {![lindex $targets($host) 5]} {
1270 $zz.$setNo elementSetNames $elements
1271 $zz.$setNo recordElements $elements
1272 set toGet [expr 1 + $setMax - $setOffset]
1274 $zz callback [list search-response $zz.$setNo]
1276 while {$setMax > 0 && $toGet > 0} {
1277 for {set got 0} {$got < $toGet} {incr got} {
1278 if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
1282 if {$got < $toGet} {
1284 $zz.$setNo present $setOffset $toGet
1285 if {[catch {egw_wait sessionWait 300}]} {
1286 egw_log debug "timeout/cancel in present"
1290 if {$sessionWait == "0"} {
1293 if {$sessionWait != "1"} {
1296 set got [$zz.$setNo numberOfRecordsReturned]
1301 display-rec $setOffset [expr $got + $setOffset - 1] $dfunc $setNo $tno
1302 set setOffset [expr $got + $setOffset]
1303 set toGet [expr 1 + $setMax - $setOffset]
1308 proc buttons-result-set-s {setNo targetNo setMax startPos after} {
1317 if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
1321 html {<a href="http:} $env(SCRIPT_NAME)
1322 html / $sessionId {/search.egw/} $setNo + $targetNo +
1323 html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
1325 html {"><img src="/egwgif/button-next-records.gif" }
1326 html {alt="Next Records" border=0></a>}
1328 html {">Next Records</a>}
1331 if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
1335 html {<a href="http:} $env(SCRIPT_NAME)
1336 html / $sessionId {/search.egw/} $setNo + $targetNo
1337 html + [expr $startPos - $hist($setNo,maxPresent)]
1338 html + [expr $startPos - 1]
1340 html {"><img src="/egwgif/button-previous-records.gif" }
1341 html {alt="Previous Records" border=0></a>}
1343 html {">Previous Records</a>}
1346 button-new-query 1 $setNo
1348 button-view-history 0
1353 proc score-sort {l r} {
1354 return [expr [lindex $r 0] - [lindex $l 0]]
1357 proc display-result-set-m-score {setNo} {
1363 set not $hist($setNo,0,host)
1364 for {set i 1} {$i <= $not} {incr i} {
1365 if {$zstatus($i) != 2} continue
1366 set status [z39$i.$setNo responseStatus]
1367 if {[lindex $status 0] != "DBOSD"} continue
1368 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1369 set nor $hist($setNo,maxPresent)
1371 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]
1377 lappend scoreArray [list $score $i $j]
1380 lappend scoreArray [list 10 $i $j]
1384 if {![info exists scoreArray]} {
1385 html "<br><h3>Search produced no result</h3><br>\n"
1388 set scoreSorted [lsort -command score-sort $scoreArray]
1391 foreach r $scoreSorted {
1394 display-$hist($setNo,format) z39$i.$setNo $j $setNo $i
1399 proc display-result-set-m-server {setNo} {
1405 set not $hist($setNo,0,host)
1407 for {set i 1} {$i <= $not} {incr i} {
1408 if {$zstatus($i) != 2} continue
1409 html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
1410 set status [z39$i.$setNo responseStatus]
1411 if {[lindex $status 0] == "NSD"} {
1412 z39$i.$setNo nextResultSetPosition 0
1413 set code [lindex $status 1]
1414 set msg [lindex $status 2]
1415 set addinfo [lindex $status 3]
1416 html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
1418 set r [z39$i.$setNo resultCount]
1419 html "$r hits</h3>\n<dd>\n"
1421 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1422 set nor $hist($setNo,maxPresent)
1424 set nor $hist($setNo,$i,offset)
1426 display-rec 1 $nor display-$hist($setNo,format) $setNo $i
1433 proc display-result-set-m {setNo} {
1439 egw_log debug "sort=$hist($setNo,sort)"
1440 switch $hist($setNo,sort) {
1442 display-result-set-m-score $setNo
1445 display-result-set-m-server $setNo
1450 proc display-result-set-s {setNo targetNo startPos endPos} {
1455 set host $hist($setNo,$targetNo,host)
1456 set idAuth $hist($setNo,$targetNo,idAuthentication)
1457 set database $hist($setNo,$targetNo,database)
1458 set query $hist($setNo,$targetNo,query)
1462 if {$startPos == ""} {
1463 if {[z39search $setNo 1 $targetNo B] != "1"} {
1466 set r [$zz.$setNo resultCount]
1468 set setMax [$zz.$setNo resultCount]
1469 if {$setMax > $hist($setNo,maxPresent)} {
1470 set setMax $hist($setNo,maxPresent)
1472 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1474 set setOffset [$zz.$setNo numberOfRecordsReturned]
1476 html {<h3> Records 1-} $setMax " out of $r</h3>\n"
1478 html "<h3> No hits</h3>\n"
1482 display-rec 1 $setMax display-brief $setNo $targetNo
1486 if {[z39search $setNo 0 $targetNo B] != "1"} {
1489 set r [$zz.$setNo resultCount]
1490 set setOffset $startPos
1491 set setMax [$zz.$setNo resultCount]
1492 if {$setMax > $endPos} {
1495 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1497 html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
1499 html "<h3> No hits</h3>\n"
1505 z39present $setNo $targetNo $setOffset $setMax display-brief B
1509 buttons-result-set-s $setNo $targetNo $setMax $startPos 1
1512 proc z39history {} {
1522 if {![info exists nextSetNo]} {
1525 html "<h2>History</h2><br>\n"
1527 html {<table width=500 border=1><tr>}
1528 html {<td align=center><b>Target</b>}
1529 html {<td align=center><b>Database</b>}
1530 html {<td align=center><b>Hits</b>}
1531 html {<td align=center><b>Query</b>}
1536 for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
1537 if {$hist($setNo,scan) > 0} continue
1538 set host $hist($setNo,0,host)
1540 html {<td align=left>}
1544 html [lindex $targets($host) 0]
1546 html {<td align=left>} [join $hist($setNo,0,database)]
1548 if {[llength [lindex $targets($host) 1]] > 1} {
1550 foreach b $hist($setNo,0,database) {
1557 html {<td align=right>}
1559 if {[info exists hist($setNo,hits)]} {
1560 html { <a href="http:} $env(SCRIPT_NAME)
1561 html / $sessionId {/search.egw/} $setNo + $targetNo + 1
1562 html + $hist($setNo,maxPresent)
1564 html {">} $hist($setNo,hits) {</a>}
1566 html {">Result</a>: } $hist($setNo,hits) { hits.}
1572 html {Search failed.}
1576 html {<td align=left>}
1580 html { <a href="http:} $env(SCRIPT_NAME)
1581 html / $sessionId / $scriptQuery / $setNo + $host
1585 html {">Query</a>: }
1588 for {set i 1} {$i <= 3} {incr i} {
1589 if {[string length $hist($setNo,form,entry$i)] > 0} {
1590 html " <b>" [join $op " "] "</b> "
1591 html [join $hist($setNo,form,menu$i)] "="
1592 html $hist($setNo,form,entry$i)
1593 set op $hist($setNo,form,logic$i)
1597 html {</a><tr>} "\n"
1608 proc displayError {msga msgb} {
1609 html "<p><center>\n"
1610 html {<img src="/egwgif/noway.gif" alt="Error">}
1611 html "<h2>" $msga "</h2>\n"
1612 if {[string length $msgb] > 0} {
1613 html "<h3>" $msgb "</h3>\n"
1615 html "</center><p>\n"
1618 proc button-main {} {
1620 html {<a href="http://europagate.dtv.dk/">}
1622 html {<img src="/egwgif/button-egw.gif" alt="Europagate" border=0></a>}
1624 html {Europagate</a>}
1628 proc button-define-target {more} {
1636 html {<a href="http:} $env(SCRIPT_NAME)
1637 html / $sessionId {/tform.egw}
1639 html {"><img src="/egwgif/button-define-target.gif" }
1640 html {alt="Define Target" border=0></a>}
1642 html {">Define Target</a>}
1646 proc button-new-target {more} {
1653 if {[string length $scriptTarget] == 0} return
1658 html {<a href="http:} $env(SCRIPT_NAME)
1659 html / $sessionId / $scriptTarget
1661 html {"><img src="/egwgif/button-new-target.gif" }
1662 html {alt="New Target" border=0></a>}
1664 html {">New Target</a>}
1668 proc button-view-history {more} {
1677 html {<a href="http:} $env(SCRIPT_NAME)
1678 html / $sessionId {/history.egw;}
1679 catch { html "/" $nextSetNo}
1681 html {"><img src="/egwgif/button-view-history.gif" alt="View History" }
1682 html {border=0></a>}
1684 html {">View History</a>}
1688 proc button-new-query {more setNo} {
1699 html {<a href="http:} $env(SCRIPT_NAME)
1700 html / $sessionId / $scriptQuery / $setNo + $hist($setNo,0,host) {">}
1703 html {<img src="/egwgif/button-new-query.gif" }
1704 html {alt="New Query" border=0></a>}
1706 html {New Query</a>}
1710 proc button-scan-window {more setNo} {
1720 html {<a href="http:} $env(SCRIPT_NAME)
1721 html / $sessionId {/search.egw/} $setNo + $targetNo + {scan} {">}
1723 html {<img src="/egwgif/button-scan-window.gif" }
1724 html {alt="Scan" border=0></a>}
1730 proc maintenance {} {
1731 html {<hr>This page is maintained by }
1732 html {<a href="mailto:pwh@dtv.dk"> Peter Wad Hansen </a>.}
1733 html {Last modified 29. january 1996. <br>}
1734 html {<em> This and the following pages are under construction and }
1735 html {will continue to be so until the end of January 1996.</em>}
1738 proc splitHostSpec {host} {
1739 set i [string first / $host]
1742 return [string range $host 0 $i]
1747 proc splitDatabaseSpec {host} {
1748 set i [string first / $host]
1751 regsub -all -- - [string range $host $i end] { } res
1754 regsub -all -- - $host {} res
1758 proc mergeHostSpec {host databases} {
1759 return ${host}/[join $databases -]
1762 proc mkAssoc {assoc host} {
1765 if {[catch {$assoc failback fail-response}]} {
1766 if {![string compare [lindex $targets($host) 1] WAIS]} {
1772 if {![string compare [lindex $targets($host) 1] WAIS]} {
1773 if {[$assoc comstack] == "wais"} return
1776 if {[$assoc comstack] == "tcpip"} return
1782 if {[info exists utilExtension]} {
1783 source $utilExtension