2 # $Id: z39util.tcl,v 1.38 1996/03/11 17:40:49 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} {
178 set type [$zset type $no]
180 set err [lindex [$zset diag $no] 1]
181 set add [lindex [$zset diag $no] 2]
185 html "${no} Error ${err}${add} <br>\n"
191 set rtype [$zset recordType $no]
194 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
195 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
196 html [string range [join [$zset getSutrs $no]] 0 70]
201 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
202 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
203 html [string range [join [$zset getWAIS $no headline]] 0 70]
206 set score [$zset getWAIS $no score]
207 html { Score } $score
213 set author [$zset getMarc $no field 100 * a]
214 set corp [$zset getMarc $no field 110 * a]
215 set meet [$zset getMarc $no field 111 * a]
216 set title [$zset getMarc $no field 245 * a]
217 if {[llength $author] == 0} {
218 set cover [$zset getMarc $no field 245 * {[bc]}]
220 set cover [$zset getMarc $no field 245 * b]
222 set location [$zset getMarc $no field 260 * a]
223 set publisher [$zset getMarc $no field 260 * b]
224 set year [$zset getMarc $no field 260 * c]
226 html { <a href="http:} $env(SCRIPT_NAME) /
227 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
261 set v [join $cover ""]
262 if {[string length $v] > 40} {
264 html [string range $v 0 38] "..."
265 } elseif {[string length $v] > 0} {
274 html { <a href="http:} $env(SCRIPT_NAME) /
275 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
278 html "Error: " $dispError "\n"
283 proc display-raw {zset no setNo targetNo} {
284 set type [$zset type $no]
287 set err [lindex [$zset diag $no] 1]
288 set add [lindex [$zset diag $no] 2]
292 html "<h3>${no}</h3>\n"
293 html "Error ${err}${add} <br>\n"
302 set rtype [$zset recordType $no]
305 html "<xmp>\n" [join [$zset getSutrs $no]] "\n</xmp>\n"
309 html "<xmp>\n" [join [$zset getWAIS $no text]] "\n</xmp>\n"
313 if {[catch {set r [$zset getMarc $no line * * *]}]} {
314 html "Unknown record type: $rtype <br>\n"
318 set tag [lindex $line 0]
319 set indicator [lindex $line 1]
320 set fields [lindex $line 2]
321 set l [string length $indicator]
324 for {set i 0} {$i < $l} {incr i} {
325 if {[string index $indicator $i] == " "} {
328 html [string index $tag $i]
333 foreach field $fields {
334 set id [lindex $field 0]
335 set data [lindex $field 1]
337 html " <b>\$$id</b> "
345 proc put-marc-contents {cc} {
347 if {[string first :// $cc] > 0} {
348 foreach urltype {gopher http ftp mailto} {
349 if {[string first ${urltype}:// $cc] == 0} {
364 proc dl-marc-field {zset no tag id la lb sep} {
366 set c [$zset getMarc $no field $tag * $id]
371 if {$len > 1 && "x$lb" != "x"} {
372 html "<dt><b>$lb</b>\n<dd>"
374 html "<dt><b>$la</b>\n<dd>"
380 put-marc-contents $cc
386 proc dd-marc-field {zset no tag id start stop} {
388 set c [$zset getMarc $no field $tag * $id]
395 put-marc-contents $cc
402 proc dl-marc-field-rec {zset no tag lead start stop startid sep} {
404 set lines [$zset getMarc $no line $tag * *]
405 foreach line $lines {
406 foreach field [lindex $line 2] {
408 html "<dt><b>$lead</b>"
411 set id [lindex $field 0]
412 if {$id == $startid} {
418 html [lindex $field 1]
421 html [lindex $field 1]
430 proc display-full-marc {zset no setNo targetNo} {
436 set n [dl-marc-field $zset $no 700 a "Author" "Authors" "<br>\n"]
438 set n [dl-marc-field $zset $no 100 a "Author" "Authors" "<br>\n"]
440 set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
442 set n [dl-marc-field $zset $no 110 a "Corporate Name" {} ", "]
444 set n [dl-marc-field $zset $no 711 a "Meeting Name" {} ", "]
446 dd-marc-field $zset $no 711 {[bndc]} " " ""
448 set n [dl-marc-field $zset $no 111 a "Meeting Name" {} ", "]
450 dd-marc-field $zset $no 111 {[bndc]} " " " "
453 set n [dl-marc-field $zset $no 245 {a} "Title" {} " "]
455 dd-marc-field $zset $no 245 b "<em>" "</em>"
456 dd-marc-field $zset $no 245 c " " ""
458 dl-marc-field $zset $no 245 {[ab]} "Title" {} " "
460 dl-marc-field $zset $no 520 a "Abstract" {} ", "
461 dl-marc-field $zset $no 072 * "Subject code" "Subject codes" ", "
462 dl-marc-field $zset $no 650 * "Subject" {} ", "
463 dl-marc-field $zset $no 260 * "Publisher" {} " "
464 dl-marc-field $zset $no 300 * "Physical Description" {} " "
466 dl-marc-field-rec $zset $no 500 "Notes" "" "<br>\n" "a" ", "
468 dl-marc-field-rec $zset $no 510 "References" "" "<br>\n" "a" ", "
470 dl-marc-field-rec $zset $no 511 "Participant note" "" "<br>\n" "a" ", "
472 dl-marc-field $zset $no 513 a "Report type" {} ", "
473 dl-marc-field $zset $no 513 b "Period covered" {} ", "
474 dl-marc-field-rec $zset $no 515 "Numbering notes" "" "<br>\n" "a" ", "
475 dl-marc-field-rec $zset $no 516 "Data notes" "" "<br>\n" "a" ", "
476 dl-marc-field-rec $zset $no 518 "Date/time notes" "" "<br>\n" "a" ", "
478 dl-marc-field $zset $no 350 a "Price" {} ", "
479 dl-marc-field $zset $no 362 a "Dates of publication" {} ", "
480 dl-marc-field $zset $no 850 a "Holdings" {} ", "
482 dl-marc-field-rec $zset $no 270 "Contact name" "" "<br>\n" p ", "
484 set n [dl-marc-field $zset $no 270 p "Contact name" {} ", "]
489 dl-marc-field $zset $no 270 a "Street" {} ", "
490 dl-marc-field $zset $no 270 b "City" {} ", "
491 dl-marc-field $zset $no 270 c "State" {} ", "
492 dl-marc-field $zset $no 270 e "Zip code" {} ", "
493 dl-marc-field $zset $no 270 d "Country" {} ", "
494 dl-marc-field $zset $no 270 m "Network address" {} ", "
495 dl-marc-field $zset $no 301 a "Service hours" {} ", "
496 dl-marc-field $zset $no 270 k "Phone" {} ", "
497 dl-marc-field $zset $no 270 l "Fax" {} ", "
499 dl-marc-field $zset $no 270 {[abcedmakl]} "Address" {} "<br>\n"
505 dl-marc-field $zset $no 010 a "LC control number" {} ", "
506 dl-marc-field $zset $no 010 b "NUCMC control number" {} ", "
507 dl-marc-field $zset $no 020 a "ISBN" {} ", "
508 dl-marc-field $zset $no 022 a "ISSN" {} ", "
509 set url [$zset getMarc $no field 856 * u]
510 set sp [$zset getMarc $no field 856 * 3]
511 if {"x$url" != "x"} {
512 html "<dt><b>URL</b>\n"
516 html {<dd><a href="} [join $url] {">} [join $sp] "</a>\n"
518 dl-marc-field $zset $no 037 {[abc]} "Acquisition" {} "<br>\n"
519 dl-marc-field $zset $no 037 {[f6]} "Form of issue" {} "<br>\n"
520 dl-marc-field $zset $no 537 * "Source of data" {} "<br>\n"
521 dl-marc-field $zset $no 538 * "System details" {} "<br>\n"
522 dl-marc-field $zset $no 787 {[rstw6]} "Related information" {} "<br>\n"
523 dl-marc-field $zset $no 001 * "Local control number" {} ", "
527 proc display-full-wais {zset no setNo targetNo} {
534 htmlToken l [join [$zset getWAIS $no text]] {
535 if {[string compare [string index $l 0] {<}]} {
536 if {[info exist data($element)]} {
537 set data($element) $data($element)$l
539 set data($element) $l
548 set element dateOfLastModification
551 set element controlIdentifier
554 set element lastChecked
566 set element "$i,linkage"
569 set element "$i,title"
579 if {![info exists data(title)] || ![info exists data(linkage)]} {
585 html {Title: <a href="} $data(linkage) {">} $data(title) "</a><br>\n"
586 html {URL: } $data(linkage) "<br>\n"
588 html {Title: } [join [$zset getWAIS $no headline]] "<br>\n"
590 html {Score: } [$zset getWAIS $no score] "<br>\n"
591 set lines [$zset getWAIS $no lines]
593 html {Lines: } $lines "<br>\n"
596 html "<pre>\n" [join [$zset getWAIS $no text]] "\n</pre>\n"
599 if {[info exists data(bytes)]} {
600 html {Bytes: } $data(bytes) "<br>\n"
602 if {[info exists data(dateOfLastModification)]} {
603 html {Last modified: } $data(dateOfLastModification) "<br>\n"
605 if {[info exists data(lastChecked)]} {
606 html {Last checked: } $data(lastChecked) "<br>\n"
608 if {[info exists data(ip)]} {
609 html {<dl><dt>Initial text<dd>} $data(ip) "</dl><br>\n"
612 html {<a href="} $env(SCRIPT_NAME) / $sessionId {/sameas.egw/}
613 html $setNo + $targetNo + 1 + $hist($setNo,maxPresent) +
614 html [egw_enc [$zset getWAIS $no documentID]] {">}
615 html {Similar WAIS record</a><br>}
616 html "<dl><dt>References\n<dd>\n"
617 for {set i 1} {[info exists data($i,linkage)]} {incr i} {
618 html {<a href="} $data($i,linkage) {">}
619 if {[info exists data($i,title)]} {
629 proc display-full {zset no setNo targetNo} {
630 set type [$zset type $no]
633 set err [lindex [$zset diag $no] 1]
634 set add [lindex [$zset diag $no] 2]
638 html "Error ${err}${add} <br>\n"
647 set rtype [$zset recordType $no]
650 html "<pre>" [join [$zset getSutrs $no]] "</pre><br>\n"
654 display-full-wais $zset $no $setNo $targetNo
658 if {[catch {set r [$zset getMarc $no line * * *]}]} {
659 html "Unknown record type: $rtype <br>\n"
662 display-full-marc $zset $no $setNo $targetNo
666 proc display-rec {from to dfunc setNo targetNo} {
667 while {$from <= $to} {
668 eval "$dfunc z39${targetNo}.${setNo} $from $setNo $targetNo"
673 proc build-scan {t i} {
676 set term [egw_form entry$i]
678 set field [join [egw_form menu$i]]
680 foreach x [lindex $targets($t) 2] {
681 if {[lindex $x 0] == $field} {
682 set attr [lindex $x 1]
685 return [list $term $attr]
690 proc build-query {t ilines} {
695 for {set i 1} {$i <= $ilines} {incr i} {
696 set term [join [egw_form entry$i]]
697 if {![string compare [lindex $targets($t) 1] WAIS]} {
698 if {[string length $op] == 0} {
703 set op [egw_form logic$i]
706 if {[string length $term] > 0} {
707 set field [join [egw_form menu$i]]
709 foreach x [lindex $targets($t) 2] {
710 if {![string compare [lindex $x 0] $field]} {
711 set attr [lindex $x 1]
714 if {![info exists attr]} {
715 egw_log debug "attr failed for $t"
716 set attr [lindex [lindex [lindex $targets($t) 2] 0] 1]
720 { set q "@and $q ${attr} \"${term}\"" }
722 { set q "@or $q ${attr} \"${term}\"" }
724 { set q "@not $q ${attr} \"${term}\"" }
726 { set q "${attr} \"${term}\"" }
728 set op [egw_form logic$i]
734 proc z39scan {setNo scanNo tno scanLines scanPos cache} {
740 set host $hist($setNo,$tno,host)
741 set idAuth $hist($setNo,$tno,idAuthentication)
742 set database $hist($setNo,$tno,database)
743 set scanAttr $hist($setNo,scanAttr)
744 set scanTerm $hist($setNo,$scanNo,scanTerm)
747 if {[catch [list set oldHost [$zz connect]]]} {
750 set zs $zz.s$scanNo.$setNo
751 $zz callback ok-response
752 $zz failback fail-response
753 set thisHost [splitHostSpec $host]
754 if {[string compare $oldHost $thisHost]} {
755 catch [list $zz disconnect]
758 if {[catch [list $zz connect $thisHost]]} {
759 displayError "Cannot connect to target" $thisHost
761 } elseif {$sessionWait == 0} {
762 if {[catch {egw_wait sessionWait 300}]} {
764 displayError "Cannot connect to target" $thisHost
767 if {$sessionWait != 1} {
768 displayError "Cannot connect to target" $thisHost
772 $zz idAuthentication $idAuth
774 if {[catch {$zz init}]} {
775 displayError "Cannot initialize target" $thisHost
779 if {[catch {egw_wait sessionWait 60}]} {
780 displayError "Cannot initialize target" $thisHost
784 if {$sessionWait != "1"} {
785 displayError "Cannot initialize target" $thisHost
789 if {![$zz initResult]} {
790 set u [$zz userInformationField]
792 displayError "Cannot initialize target $thisHost" $u
796 if {$cache && ![catch [list $zs numberOfTermsRequested 5]]} {
800 eval $zz databaseNames $database
804 $zs numberOfTermsRequested $scanLines
805 $zs preferredPositionInResponse $scanPos
807 $zz callback [list scan-response $zs]
809 egw_log debug "scan: ${scanAttr} ${scanTerm}"
811 $zs scan "${scanAttr} ${scanTerm}"
813 if {[catch {egw_wait sessionWait 60}]} {
814 egw_log debug "timeout/cancel in scan"
815 displayError "Timeout in scan" {}
816 html "</body></html>\n"
820 if {$sessionWait == -1} {
821 displayError "Scan fail" "Connection closed"
822 html "</body></html>\n"
825 if {$sessionWait != 1} {
831 proc display-scan {setNo scanNo tno} {
838 set zs $zz.s$scanNo.$setNo
839 set m [$zs numberOfEntriesReturned]
842 set t [lindex [$zs scanLine 0] 1]
844 set hist($setNo,$tno,[expr $scanNo - 1],scanTerm) $t
846 set hist($setNo,[expr $scanNo - 1],scanTerm) $t
848 set t [lindex [$zs scanLine [expr $m - 1]] 1]
850 set hist($setNo,$tno,[expr $scanNo + 1],scanTerm) $t
852 set hist($setNo,[expr $scanNo + 1],scanTerm) $t
855 html {<table width=500 border=0><tr>}
856 html {<td align=left><b>Scan term</b>}
857 html {<td align=right><b>Hits</b>}
860 for {set i 0} {$i < $m} {incr i} {
861 html {<td align=left>}
863 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
864 html {<a href="http:} $env(SCRIPT_NAME)
865 html / $sessionId {/query.egw/} $hist($setNo,host) + $setNo +
866 html $hist($setNo,scan) + $tterm {">}
868 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
869 html {<a href="http:} $env(SCRIPT_NAME)
870 html / $sessionId {/search.egw/} $setNo + $tno +
871 html hyper + $tterm {">}
873 html [lindex [$zs scanLine $i] 1]
875 html {<td align=right>}
876 html [lindex [$zs scanLine $i] 2]
882 proc z39search {setNo piggy tno elements} {
888 set host $hist($setNo,$tno,host)
889 set idAuth $hist($setNo,$tno,idAuthentication)
890 set database $hist($setNo,$tno,database)
891 set query $hist($setNo,$tno,query)
892 catch {set docId $hist($setNo,$tno,queryId)}
895 if {[catch [list set oldHost [$zz connect]]]} {
898 $zz callback ok-response
899 $zz failback fail-response
900 set thisHost [splitHostSpec $host]
901 if {[string compare $oldHost $thisHost]} {
902 catch [list $zz disconnect]
905 if {[catch [list $zz connect $thisHost]]} {
906 displayError "Cannot connect to target" $thisHost
908 } elseif {$sessionWait == 0} {
909 if {[catch {egw_wait sessionWait 300}]} {
911 displayError "Cannot connect to target" $thisHost
914 if {$sessionWait != 1} {
915 displayError "Cannot connect to target" $thisHost
919 $zz idAuthentication $idAuth
921 if {[catch {$zz init}]} {
922 displayError "Cannot initialize target" $thisHost
926 if {$sessionWait == 0 && [catch {egw_wait sessionWait 60}]} {
927 displayError "Cannot initialize target" $thisHost
931 if {$sessionWait != "1"} {
932 displayError "Cannot initialize target" $thisHost
936 if {![$zz initResult]} {
937 set u [$zz userInformationField]
939 displayError "Cannot initialize target $thisHost" $u
942 } elseif {![catch [list $zz.$setNo smallSetUpperBound 0]]} {
944 if {[info exists hist($setNo,$tno,hits)]} {
948 if {[info exists hist($setNo,hits)]} {
954 if {![string compare [lindex $targets($host) 1] WAIS]} {
955 wais-set $zz.$setNo $zz
957 ir-set $zz.$setNo $zz
958 $zz.$setNo preferredRecordSyntax [lindex $targets($host) 1]
959 egw_log debug "set syntax to [lindex $targets($host) 1]"
961 if {![lindex $targets($host) 5]} {
964 $zz.$setNo smallSetElementSetNames $elements
965 $zz.$setNo mediumSetElementSetNames $elements
966 $zz.$setNo recordElements $elements
968 egw_log debug "database=$database"
969 eval $zz.$setNo databaseNames $database
971 $zz callback [list search-response $zz.$setNo]
973 $zz.$setNo largeSetLowerBound 999999
974 $zz.$setNo smallSetUpperBound 0
975 $zz.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
977 $zz.$setNo largeSetLowerBound 2
978 $zz.$setNo smallSetUpperBound 0
979 $zz.$setNo mediumSetPresentNumber 0
982 egw_log debug "search: $query"
984 if {[info exists docId]} {
985 $zz.$setNo search $query $docId
987 $zz.$setNo search $query
990 if {!$sessionWait && [catch {egw_wait sessionWait 60}]} {
991 egw_log debug "timeout/cancel in search"
992 displayError "Timeout in search" {}
993 html "</body></html>\n"
998 if {$sessionWait == -1} {
999 displayError "Search fail" "Connection closed"
1000 html "</body></html>\n"
1003 if {$sessionWait != 1} {
1006 set hist($setNo,hits) [$zz.$setNo resultCount]
1010 proc init-m-response {i} {
1014 egw_log debug "init-m-response"
1017 if {![z39$i initResult]} {
1025 proc connect-m-response {i} {
1029 egw_log debug "connect-m-response"
1030 z39$i callback [list init-m-response $i]
1031 if {[catch {z39$i init}]} {
1037 proc fail-m-response {i} {
1041 egw_log debug "fail-m-response"
1046 proc search-m-response {setNo i start number} {
1051 egw_log debug "search-m-response"
1052 set status [z39$i.$setNo responseStatus]
1053 egw_log debug "search-m-response1"
1054 if {[lindex $status 0] == "OK"} {
1056 } elseif {[lindex $status 0] == "DBOSD"} {
1057 set nor [z39$i.$setNo numberOfRecordsReturned]
1059 egw_log debug "search-m-response2"
1064 set hist($setNo,$i,hits) [z39$i.$setNo resultCount]
1065 egw_log debug "search-m-response3"
1066 set hist($setNo,$i,offset) [expr $start + $nor -1]
1067 if {[expr $nor + $start] > [z39$i.$setNo resultCount]} {
1068 egw_log debug "search-m-response4"
1073 egw_log debug "search-m-response5"
1074 if {$nor >= $number} {
1075 egw_log debug "search-m-response6 nor=$nor number=$number"
1080 egw_log debug "search-m-response7"
1081 set start [expr $start + $nor]
1082 set number [expr $number - $nor]
1083 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1084 set number [expr [z39$i.$setNo resultCount] - $start + 1]
1086 z39$i callback [list search-m-response $setNo $i $start $number]
1087 egw_log debug "mpresent start=$number number=$number"
1088 z39$i.$setNo present $start $number
1091 proc z39msearch {setNo elements start number cache} {
1098 set not $hist($setNo,0,host)
1100 egw_log debug "z39msearch start=$start number=$number elements=$elements"
1101 for {set i 1} {$i <= $not} {incr i} {
1102 set host $hist($setNo,$i,host)
1104 set oldHost [z39$i connect]
1105 set thisHost [splitHostSpec $host]
1106 if {[string compare $oldHost $thisHost]} {
1107 catch {z39$i disconnect}
1109 z39$i callback [list connect-m-response $i]
1110 z39$i failback [list fail-m-response $i]
1113 for {set i 1} {$i <= $not} {incr i} {
1114 set oldHost [z39$i connect]
1115 set host $hist($setNo,$i,host)
1116 set thisHost [splitHostSpec $host]
1117 if {![string compare $oldHost $thisHost]} {
1120 egw_log debug "old=$oldHost this=$thisHost"
1121 z39$i idAuthentication $hist($setNo,$i,idAuthentication)
1122 html "Connecting to target " $thisHost " <br>\n"
1124 if {![catch {z39$i connect $thisHost}]} {
1128 while {$zleft > 0} {
1129 egw_log debug "Waiting for init response"
1130 if {[catch {egw_wait zleft 20}]} {
1135 for {set i 1} {$i <= $not} {incr i} {
1136 set host $hist($setNo,$i,host)
1138 html "host " [splitHostSpec $host] ": "
1140 egw_log debug "i=$i zstatus=$zstatus($i)"
1141 if {$zstatus($i) < 1} {
1147 if {[catch [list z39$i.$setNo preferredRecordSyntax]]} {
1152 if {![string compare [lindex $targets($host) 1] WAIS]} {
1153 wais-set z39$i.$setNo z39$i
1155 ir-set z39$i.$setNo z39$i
1156 z39$i.$setNo preferredRecordSyntax [lindex $targets($host) 1]
1157 egw_log debug "set syntax to [lindex $targets($host) 1]"
1159 set hist($setNo,$i,offset) 0
1160 eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
1162 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1165 set thisElements $elements
1167 z39$i.$setNo smallSetElementSetNames $thisElements
1168 z39$i.$setNo mediumSetElementSetNames $thisElements
1169 z39$i.$setNo elementSetNames $thisElements
1170 z39$i.$setNo recordElements $thisElements
1172 z39$i callback [list search-m-response $setNo $i $start $number]
1175 z39$i.$setNo largeSetLowerBound 999999
1176 z39$i.$setNo smallSetUpperBound 0
1177 z39$i.$setNo mediumSetPresentNumber $number
1179 z39$i.$setNo largeSetLowerBound 2
1180 z39$i.$setNo smallSetUpperBound 0
1181 z39$i.$setNo mediumSetPresentNumber 0
1185 egw_log debug "msearch host=" $hist($setNo,$i,host)
1186 egw_log debug "setNo=$setNo query=" $hist($setNo,$i,query) "="
1187 if {[catch {z39$i.$setNo search $hist($setNo,$i,query)}]} {
1191 } elseif {[z39$i.$setNo resultCount] >= $start} {
1192 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1193 set tnumber [expr [z39$i.$setNo resultCount] - $start + 1]
1197 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1200 set thisElements $elements
1202 z39$i.$setNo smallSetElementSetNames $thisElements
1203 z39$i.$setNo mediumSetElementSetNames $thisElements
1204 z39$i.$setNo elementSetNames $thisElements
1205 z39$i.$setNo recordElements $thisElements
1207 for {set n 0} {$n < $tnumber} {incr n} {
1208 if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
1210 egw_log debug "failed on $n"
1213 html "no record at #" [expr $start + $n]
1214 html " el=-" $thisElements "-"
1219 if {$n == $tnumber} {
1226 html "present<br>\n"
1227 z39$i callback [list search-m-response $setNo $i $start $tnumber]
1229 egw_log debug "mpresent start=$start number=$tnumber"
1230 z39$i.$setNo present $start $tnumber
1237 while {$zleft > 0} {
1238 egw_log debug "Waiting for search/present response"
1239 if {[catch {egw_wait zleft 60}]} {
1243 for {set i 1} {$i <= $not} {incr i} {
1244 if {$zstatus($i) != 2} continue
1245 set status [z39$i.$setNo responseStatus]
1246 if {0 && [lindex $status 0] != "NSD"} {
1247 set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned]
1252 proc z39present {setNo tno setOffset setMax dfunc elements} {
1258 set host $hist($setNo,$tno,host)
1260 if {![lindex $targets($host) 5]} {
1264 $zz.$setNo elementSetNames $elements
1265 $zz.$setNo recordElements $elements
1266 set toGet [expr 1 + $setMax - $setOffset]
1268 $zz callback [list search-response $zz.$setNo]
1270 while {$setMax > 0 && $toGet > 0} {
1271 for {set got 0} {$got < $toGet} {incr got} {
1272 if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
1276 if {$got < $toGet} {
1278 $zz.$setNo present $setOffset $toGet
1279 if {[catch {egw_wait sessionWait 300}]} {
1280 egw_log debug "timeout/cancel in present"
1284 if {$sessionWait == "0"} {
1287 if {$sessionWait != "1"} {
1290 set got [$zz.$setNo numberOfRecordsReturned]
1295 display-rec $setOffset [expr $got + $setOffset - 1] $dfunc $setNo $tno
1296 set setOffset [expr $got + $setOffset]
1297 set toGet [expr 1 + $setMax - $setOffset]
1302 proc buttons-result-set-s {setNo targetNo setMax startPos after} {
1311 if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
1312 html {<a href="http:} $env(SCRIPT_NAME)
1313 html / $sessionId {/search.egw/} $setNo + $targetNo +
1314 html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
1316 html {"><img src="/egwgif/button-next-records.gif" alt="Next Records"}
1317 html { border=0></a>}
1319 html {">Next Records</a>} " | \n"
1322 if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
1323 html {<a href="http:} $env(SCRIPT_NAME)
1324 html / $sessionId {/search.egw/} $setNo + $targetNo
1325 html + [expr $startPos - $hist($setNo,maxPresent)]
1326 html + [expr $startPos - 1]
1328 html {"><img src="/egwgif/button-previous-records.gif" }
1329 html {alt="Previous Records" border=0></a>}
1331 html {">Previous Records</a>} " | \n"
1334 button-new-query 1 $setNo
1336 button-view-history 0
1341 proc score-sort {l r} {
1342 return [expr [lindex $r 0] - [lindex $l 0]]
1345 proc display-result-set-m-score {setNo} {
1351 set not $hist($setNo,0,host)
1352 for {set i 1} {$i <= $not} {incr i} {
1353 if {$zstatus($i) != 2} continue
1354 set status [z39$i.$setNo responseStatus]
1355 if {[lindex $status 0] != "DBOSD"} continue
1356 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1357 set nor $hist($setNo,maxPresent)
1359 set nor $hist($setNo,$i,offset)
1361 for {set j 1} {$j <= $nor} {incr j} {
1362 if {![string compare [z39$i.$setNo recordType $j] WAIS]} {
1363 set score [z39$i.$setNo getWAIS $j score]
1365 lappend scoreArray [list $score $i $j]
1368 lappend scoreArray [list 10 $i $j]
1372 if {![info exists scoreArray]} {
1373 html "<br><h3>Search produced no result</h3><br>\n"
1376 set scoreSorted [lsort -command score-sort $scoreArray]
1379 foreach r $scoreSorted {
1382 display-$hist($setNo,format) z39$i.$setNo $j $setNo $i
1387 proc display-result-set-m-server {setNo} {
1393 set not $hist($setNo,0,host)
1395 for {set i 1} {$i <= $not} {incr i} {
1396 if {$zstatus($i) != 2} continue
1397 html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
1398 set status [z39$i.$setNo responseStatus]
1399 if {[lindex $status 0] == "NSD"} {
1400 z39$i.$setNo nextResultSetPosition 0
1401 set code [lindex $status 1]
1402 set msg [lindex $status 2]
1403 set addinfo [lindex $status 3]
1404 html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
1406 set r [z39$i.$setNo resultCount]
1407 html "$r hits</h3>\n<dd>\n"
1409 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1410 set nor $hist($setNo,maxPresent)
1412 set nor $hist($setNo,$i,offset)
1414 display-rec 1 $nor display-$hist($setNo,format) $setNo $i
1421 proc display-result-set-m {setNo} {
1427 egw_log debug "sort=$hist($setNo,sort)"
1428 switch $hist($setNo,sort) {
1430 display-result-set-m-score $setNo
1433 display-result-set-m-server $setNo
1438 proc display-result-set-s {setNo targetNo startPos endPos} {
1443 set host $hist($setNo,$targetNo,host)
1444 set idAuth $hist($setNo,$targetNo,idAuthentication)
1445 set database $hist($setNo,$targetNo,database)
1446 set query $hist($setNo,$targetNo,query)
1450 if {$startPos == ""} {
1451 if {[z39search $setNo 1 $targetNo B] != "1"} {
1454 set r [$zz.$setNo resultCount]
1456 set setMax [$zz.$setNo resultCount]
1457 if {$setMax > $hist($setNo,maxPresent)} {
1458 set setMax $hist($setNo,maxPresent)
1460 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1462 set setOffset [$zz.$setNo numberOfRecordsReturned]
1464 html {<h3> Records 1-} $setMax " out of $r</h3>\n"
1466 html "<h3> No hits</h3>\n"
1470 display-rec 1 $setMax display-brief $setNo $targetNo
1474 if {[z39search $setNo 0 $targetNo B] != "1"} {
1477 set r [$zz.$setNo resultCount]
1478 set setOffset $startPos
1479 set setMax [$zz.$setNo resultCount]
1480 if {$setMax > $endPos} {
1483 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1485 html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
1487 html "<h3> No hits</h3>\n"
1493 z39present $setNo $targetNo $setOffset $setMax display-brief B
1497 buttons-result-set-s $setNo $targetNo $setMax $startPos 1
1500 proc z39history {} {
1509 if {![info exists nextSetNo]} {
1512 html "<h2>History</h2><br>\n"
1514 html {<table width=500 border=1><tr>}
1515 html {<td align=center><b>Target</b>}
1516 html {<td align=center><b>Database</b>}
1517 html {<td align=center><b>Hits</b>}
1518 html {<td align=center><b>Query</b>}
1523 for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
1524 if {$hist($setNo,scan) > 0} continue
1525 set host $hist($setNo,0,host)
1527 html {<td align=left>}
1531 html [lindex $targets($host) 0]
1533 html {<td align=left>} [join $hist($setNo,0,database)]
1535 if {[llength [lindex $targets($host) 1]] > 1} {
1537 foreach b $hist($setNo,0,database) {
1544 html {<td align=right>}
1546 if {[info exists hist($setNo,hits)]} {
1547 html { <a href="http:} $env(SCRIPT_NAME)
1548 html / $sessionId {/search.egw/} $setNo + $targetNo + 1
1549 html + $hist($setNo,maxPresent)
1551 html {">} $hist($setNo,hits) {</a>}
1553 html {">Result</a>: } $hist($setNo,hits) { hits.}
1559 html {Search failed.}
1563 html {<td align=left>}
1567 html { <a href="http:} $env(SCRIPT_NAME)
1568 html / $sessionId {/query.egw/} $host + $setNo
1572 html {">Query</a>: }
1575 for {set i 1} {$i <= 3} {incr i} {
1576 if {[string length $hist($setNo,form,entry$i)] > 0} {
1577 html " <b>" [join $op " "] "</b> "
1578 html [join $hist($setNo,form,menu$i)] "="
1579 html $hist($setNo,form,entry$i)
1580 set op $hist($setNo,form,logic$i)
1584 html {</a><tr>} "\n"
1595 proc displayError {msga msgb} {
1596 html "<p><center>\n"
1597 html {<img src="/egwgif/noway.gif" alt="Error">}
1598 html "<h2>" $msga "</h2>\n"
1600 html "<h3>" $msgb "</h3>\n"
1602 html "</center><p>\n"
1605 proc button-europagate {} {
1607 html {<a href="http://europagate.dtv.dk/">}
1609 html {<img src="/egwgif/button-egw.gif" alt="Europagate" border=0></a>}
1611 html {Europagate</a> | }
1615 proc button-define-target {more} {
1620 html {<a href="http:} $env(SCRIPT_NAME)
1621 html / $sessionId {/tform.egw}
1623 html {"><img src="/egwgif/button-define-target.gif" }
1624 html {alt="Define Target" border=0></a>}
1626 html {">Define Target</a>}
1635 proc button-new-target {more} {
1641 html {<a href="http:} $env(SCRIPT_NAME)
1644 html {/mtargets.egw}
1649 html {"><img src="/egwgif/button-new-target.gif" }
1650 html {alt="New Target" border=0></a>}
1652 html {">New Target</a>}
1661 proc button-view-history {more} {
1667 html {<a href="http:} $env(SCRIPT_NAME)
1668 html / $sessionId {/history.egw;}
1669 catch { html "/" $nextSetNo}
1671 html {"><img src="/egwgif/button-view-history.gif" alt="View History" }
1672 html {border=0></a>}
1674 html {">View History</a>}
1683 proc button-new-query {more setNo} {
1690 html {<a href="http:} $env(SCRIPT_NAME)
1693 html {/mquery.egw/} $setNo
1695 html {/query.egw/} $hist($setNo,0,host) + $setNo
1699 html {<img src="/egwgif/button-new-query.gif" }
1700 html {alt="New Query" border=0></a>}
1702 html {New Query</a>}
1711 proc button-scan-window {more setNo} {
1718 html {<a href="http:} $env(SCRIPT_NAME)
1719 html / $sessionId {/search.egw/} $setNo + $targetNo + {scan} {">}
1721 html {<img src="/egwgif/button-scan-window.gif" }
1722 html {alt="Scan" border=0></a>}
1733 proc maintenance {} {
1734 html {<hr>This page is maintained by }
1735 html {<a href="mailto:pwh@dtv.dk"> Peter Wad Hansen </a>.}
1736 html {Last modified 29. january 1996. <br>}
1737 html {<em> This and the following pages are under construction and }
1738 html {will continue to be so until the end of January 1996.</em>}
1741 proc splitHostSpec {host} {
1742 set i [string first / $host]
1745 return [string range $host 0 $i]
1750 proc splitDatabaseSpec {host} {
1751 set i [string first / $host]
1754 regsub -all -- - [string range $host $i end] { } res
1757 regsub -all -- - $host {} res
1761 proc mergeHostSpec {host databases} {
1762 return ${host}.[join $databases -]
1765 proc mkAssoc {assoc host} {
1768 if {[catch {$assoc failback fail-response}]} {
1769 if {![string compare [lindex $targets($host) 1] WAIS]} {
1775 if {![string compare [lindex $targets($host) 1] WAIS]} {
1776 if {[$assoc comstack] == "wais"} return
1779 if {[$assoc comstack] == "tcpip"} return