2 # $Id: z39util.tcl,v 1.37 1996/03/08 16:47:08 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-brief {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]
87 if {$rtype == "SUTRS"} {
88 html { <a href="http:} $env(SCRIPT_NAME) /
89 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
90 html [join [$zset getSutrs $no]]
94 if {$rtype == "WAIS"} {
95 html { <a href="http:} $env(SCRIPT_NAME) /
96 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
97 html [join [$zset getWAIS $no headline]]
103 set author [$zset getMarc $no field 100 * a]
104 set corp [$zset getMarc $no field 110 * a]
105 set meet [$zset getMarc $no field 111 * a]
106 set title [$zset getMarc $no field 245 * a]
107 if {[llength $author] == 0} {
108 set cover [$zset getMarc $no field 245 * {[bc]}]
110 set cover [$zset getMarc $no field 245 * b]
112 set location [$zset getMarc $no field 260 * a]
113 set publisher [$zset getMarc $no field 260 * b]
114 set year [$zset getMarc $no field 260 * c]
116 html { <a href="http:} $env(SCRIPT_NAME) /
117 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
149 set v [join $cover ""]
150 if {[string length $v] > 40} {
152 html [string range $v 0 38] "..."
153 } elseif {[string length $v] > 0} {
162 html { <a href="http:} $env(SCRIPT_NAME) /
163 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
166 html "Error: " $dispError "\n"
171 proc display-raw {zset no tno} {
172 set type [$zset type $no]
174 set err [lindex [$zset diag $no] 1]
175 set add [lindex [$zset diag $no] 2]
179 html "<h3>${no}</h3>\n"
180 html "Error ${err}${add} <br>\n"
186 set rtype [$zset recordType $no]
187 if {$rtype == "SUTRS"} {
188 html [join [$zset getSutrs $no]] "<br>\n"
191 if {[catch {set r [$zset getMarc $no line * * *]}]} {
192 html "Unknown record type: $rtype <br>\n"
196 set tag [lindex $line 0]
197 set indicator [lindex $line 1]
198 set fields [lindex $line 2]
199 set l [string length $indicator]
202 for {set i 0} {$i < $l} {incr i} {
203 if {[string index $indicator $i] == " "} {
206 html [string index $tag $i]
211 foreach field $fields {
212 set id [lindex $field 0]
213 set data [lindex $field 1]
215 html " <b>\$$id</b> "
223 proc put-marc-contents {cc} {
225 if {[string first :// $cc] > 0} {
226 foreach urltype {gopher http ftp mailto} {
227 if {[string first ${urltype}:// $cc] == 0} {
242 proc dl-marc-field {zset no tag id la lb sep} {
244 set c [$zset getMarc $no field $tag * $id]
249 if {$len > 1 && "x$lb" != "x"} {
250 html "<dt><b>$lb</b>\n<dd>"
252 html "<dt><b>$la</b>\n<dd>"
258 put-marc-contents $cc
264 proc dd-marc-field {zset no tag id start stop} {
266 set c [$zset getMarc $no field $tag * $id]
273 put-marc-contents $cc
280 proc dl-marc-field-rec {zset no tag lead start stop startid sep} {
282 set lines [$zset getMarc $no line $tag * *]
283 foreach line $lines {
284 foreach field [lindex $line 2] {
286 html "<dt><b>$lead</b>"
289 set id [lindex $field 0]
290 if {$id == $startid} {
296 html [lindex $field 1]
299 html [lindex $field 1]
308 proc display-full-wais {zset no setNo targetNo} {
315 htmlToken l [join [$zset getWAIS $no text]] {
316 if {[string compare [string index $l 0] {<}]} {
317 set data($element) $l
325 set element dateOfLastModification
328 set element controlIdentifier
331 set element lastChecked
343 set element "$i,linkage"
346 set element "$i,title"
353 if {![info exists data(title)] || ![info exists data(linkage)]} {
354 html "<pre>" [join [$zset getWAIS $no text]] "\n</pre>\n"
357 html {Title: } {<a href="} $data(linkage) {">} $data(title) "</a><br>\n"
358 html {URL: } $data(linkage) "<br>\n"
359 html {Score: } [$zset getWAIS $no score] "<br>\n"
360 html {Lines: } [$zset getWAIS $no lines] "<br>\n"
361 if {[info exists data(bytes)]} {
362 html {Bytes: } $data(bytes) "<br>\n"
364 if {[info exists data(dateOfLastModification)]} {
365 html {Last modified: } $data(dateOfLastModification) "<br>\n"
367 if {[info exists data(lastChecked)]} {
368 html {Last checked: } $data(lastChecked) "<br>\n"
370 html {<a href="} $env(SCRIPT_NAME) / $sessionId {/sameas.egw/}
371 html $setNo + $targetNo + 1 + $hist($setNo,maxPresent) +
372 html [egw_enc [$zset getWAIS $no documentID]] {">}
373 html {Similar WAIS record</a><br>}
375 for {set i 1} {[info exists data($i,linkage)]} {incr i} {
376 html {<li><a href="} $data($i,linkage) {">}
377 html $data($i,title) "</a><br>\n"
378 html "URL: " $data($i,linkage)
383 proc display-full {zset no setNo targetNo} {
384 set type [$zset type $no]
386 set err [lindex [$zset diag $no] 1]
387 set add [lindex [$zset diag $no] 2]
391 html "Error ${err}${add} <br>\n"
397 set rtype [$zset recordType $no]
398 if {$rtype == "SUTRS"} {
400 html [join [$zset getSutrs $no]]
404 if {$rtype == "WAIS"} {
405 display-full-wais $zset $no $setNo $targetNo
408 if {[catch {set r [$zset getMarc $no line * * *]}]} {
409 html "Unknown record type: $rtype <br>\n"
413 set n [dl-marc-field $zset $no 700 a "Author" "Authors" "<br>\n"]
415 set n [dl-marc-field $zset $no 100 a "Author" "Authors" "<br>\n"]
417 set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
419 set n [dl-marc-field $zset $no 110 a "Corporate Name" {} ", "]
421 set n [dl-marc-field $zset $no 711 a "Meeting Name" {} ", "]
423 dd-marc-field $zset $no 711 {[bndc]} " " ""
425 set n [dl-marc-field $zset $no 111 a "Meeting Name" {} ", "]
427 dd-marc-field $zset $no 111 {[bndc]} " " " "
430 set n [dl-marc-field $zset $no 245 {a} "Title" {} " "]
432 dd-marc-field $zset $no 245 b "<em>" "</em>"
433 dd-marc-field $zset $no 245 c " " ""
435 dl-marc-field $zset $no 245 {[ab]} "Title" {} " "
437 dl-marc-field $zset $no 520 a "Abstract" {} ", "
438 dl-marc-field $zset $no 072 * "Subject code" "Subject codes" ", "
439 dl-marc-field $zset $no 650 * "Subject" {} ", "
440 dl-marc-field $zset $no 260 * "Publisher" {} " "
441 dl-marc-field $zset $no 300 * "Physical Description" {} " "
443 dl-marc-field-rec $zset $no 500 "Notes" "" "<br>\n" "a" ", "
445 dl-marc-field-rec $zset $no 510 "References" "" "<br>\n" "a" ", "
447 dl-marc-field-rec $zset $no 511 "Participant note" "" "<br>\n" "a" ", "
449 dl-marc-field $zset $no 513 a "Report type" {} ", "
450 dl-marc-field $zset $no 513 b "Period covered" {} ", "
451 dl-marc-field-rec $zset $no 515 "Numbering notes" "" "<br>\n" "a" ", "
452 dl-marc-field-rec $zset $no 516 "Data notes" "" "<br>\n" "a" ", "
453 dl-marc-field-rec $zset $no 518 "Date/time notes" "" "<br>\n" "a" ", "
455 dl-marc-field $zset $no 350 a "Price" {} ", "
456 dl-marc-field $zset $no 362 a "Dates of publication" {} ", "
457 dl-marc-field $zset $no 850 a "Holdings" {} ", "
459 dl-marc-field-rec $zset $no 270 "Contact name" "" "<br>\n" p ", "
461 set n [dl-marc-field $zset $no 270 p "Contact name" {} ", "]
466 dl-marc-field $zset $no 270 a "Street" {} ", "
467 dl-marc-field $zset $no 270 b "City" {} ", "
468 dl-marc-field $zset $no 270 c "State" {} ", "
469 dl-marc-field $zset $no 270 e "Zip code" {} ", "
470 dl-marc-field $zset $no 270 d "Country" {} ", "
471 dl-marc-field $zset $no 270 m "Network address" {} ", "
472 dl-marc-field $zset $no 301 a "Service hours" {} ", "
473 dl-marc-field $zset $no 270 k "Phone" {} ", "
474 dl-marc-field $zset $no 270 l "Fax" {} ", "
476 dl-marc-field $zset $no 270 {[abcedmakl]} "Address" {} "<br>\n"
482 dl-marc-field $zset $no 010 a "LC control number" {} ", "
483 dl-marc-field $zset $no 010 b "NUCMC control number" {} ", "
484 dl-marc-field $zset $no 020 a "ISBN" {} ", "
485 dl-marc-field $zset $no 022 a "ISSN" {} ", "
486 set url [$zset getMarc $no field 856 * u]
487 set sp [$zset getMarc $no field 856 * 3]
488 if {"x$url" != "x"} {
489 html "<dt><b>URL</b>\n"
493 html {<dd><a href="} [join $url] {">} [join $sp] "</a>\n"
495 dl-marc-field $zset $no 037 {[abc]} "Acquisition" {} "<br>\n"
496 dl-marc-field $zset $no 037 {[f6]} "Form of issue" {} "<br>\n"
497 dl-marc-field $zset $no 537 * "Source of data" {} "<br>\n"
498 dl-marc-field $zset $no 538 * "System details" {} "<br>\n"
499 dl-marc-field $zset $no 787 {[rstw6]} "Related information" {} "<br>\n"
500 dl-marc-field $zset $no 001 * "Local control number" {} ", "
505 proc display-rec {from to dfunc setNo targetNo} {
506 while {$from <= $to} {
507 eval "$dfunc z39${targetNo}.${setNo} $from $setNo $targetNo"
512 proc build-scan {t i} {
515 set term [egw_form entry$i]
517 set field [join [egw_form menu$i]]
519 foreach x [lindex $targets($t) 2] {
520 if {[lindex $x 0] == $field} {
521 set attr [lindex $x 1]
524 return [list $term $attr]
529 proc build-query {t ilines} {
534 for {set i 1} {$i <= $ilines} {incr i} {
535 set term [join [egw_form entry$i]]
536 if {![string compare [lindex $targets($t) 1] WAIS]} {
537 if {[string length $op] == 0} {
542 set op [egw_form logic$i]
545 if {[string length $term] > 0} {
546 set field [join [egw_form menu$i]]
548 foreach x [lindex $targets($t) 2] {
549 if {![string compare [lindex $x 0] $field]} {
550 set attr [lindex $x 1]
553 if {![info exists attr]} {
554 egw_log debug "attr failed for $t"
555 set attr [lindex [lindex [lindex $targets($t) 2] 0] 1]
559 { set q "@and $q ${attr} \"${term}\"" }
561 { set q "@or $q ${attr} \"${term}\"" }
563 { set q "@not $q ${attr} \"${term}\"" }
565 { set q "${attr} \"${term}\"" }
567 set op [egw_form logic$i]
573 proc z39scan {setNo scanNo tno scanLines scanPos cache} {
579 set host $hist($setNo,$tno,host)
580 set idAuth $hist($setNo,$tno,idAuthentication)
581 set database $hist($setNo,$tno,database)
582 set scanAttr $hist($setNo,scanAttr)
583 set scanTerm $hist($setNo,$scanNo,scanTerm)
586 if {[catch [list set oldHost [$zz connect]]]} {
589 set zs $zz.s$scanNo.$setNo
590 $zz callback ok-response
591 $zz failback fail-response
592 set thisHost [splitHostSpec $host]
593 if {[string compare $oldHost $thisHost]} {
594 catch [list $zz disconnect]
597 if {[catch [list $zz connect $thisHost]]} {
598 displayError "Cannot connect to target" $thisHost
600 } elseif {$sessionWait == 0} {
601 if {[catch {egw_wait sessionWait 300}]} {
603 displayError "Cannot connect to target" $thisHost
606 if {$sessionWait != 1} {
607 displayError "Cannot connect to target" $thisHost
611 $zz idAuthentication $idAuth
613 if {[catch {$zz init}]} {
614 displayError "Cannot initialize target" $thisHost
618 if {[catch {egw_wait sessionWait 60}]} {
619 displayError "Cannot initialize target" $thisHost
623 if {$sessionWait != "1"} {
624 displayError "Cannot initialize target" $thisHost
628 if {![$zz initResult]} {
629 set u [$zz userInformationField]
631 displayError "Cannot initialize target $thisHost" $u
635 if {$cache && ![catch [list $zs numberOfTermsRequested 5]]} {
639 eval $zz databaseNames $database
643 $zs numberOfTermsRequested $scanLines
644 $zs preferredPositionInResponse $scanPos
646 $zz callback [list scan-response $zs]
648 egw_log debug "scan: ${scanAttr} ${scanTerm}"
650 $zs scan "${scanAttr} ${scanTerm}"
652 if {[catch {egw_wait sessionWait 60}]} {
653 egw_log debug "timeout/cancel in scan"
654 displayError "Timeout in scan" {}
655 html "</body></html>\n"
659 if {$sessionWait == -1} {
660 displayError "Scan fail" "Connection closed"
661 html "</body></html>\n"
664 if {$sessionWait != 1} {
670 proc display-scan {setNo scanNo tno} {
677 set zs $zz.s$scanNo.$setNo
678 set m [$zs numberOfEntriesReturned]
681 set t [lindex [$zs scanLine 0] 1]
683 set hist($setNo,$tno,[expr $scanNo - 1],scanTerm) $t
685 set hist($setNo,[expr $scanNo - 1],scanTerm) $t
687 set t [lindex [$zs scanLine [expr $m - 1]] 1]
689 set hist($setNo,$tno,[expr $scanNo + 1],scanTerm) $t
691 set hist($setNo,[expr $scanNo + 1],scanTerm) $t
694 html {<table width=500 border=0><tr>}
695 html {<td align=left><b>Scan term</b>}
696 html {<td align=right><b>Hits</b>}
699 for {set i 0} {$i < $m} {incr i} {
700 html {<td align=left>}
702 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
703 html {<a href="http:} $env(SCRIPT_NAME)
704 html / $sessionId {/query.egw/} $hist($setNo,host) + $setNo +
705 html $hist($setNo,scan) + $tterm {">}
707 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
708 html {<a href="http:} $env(SCRIPT_NAME)
709 html / $sessionId {/search.egw/} $setNo + $tno +
710 html hyper + $tterm {">}
712 html [lindex [$zs scanLine $i] 1]
714 html {<td align=right>}
715 html [lindex [$zs scanLine $i] 2]
721 proc z39search {setNo piggy tno elements} {
727 set host $hist($setNo,$tno,host)
728 set idAuth $hist($setNo,$tno,idAuthentication)
729 set database $hist($setNo,$tno,database)
730 set query $hist($setNo,$tno,query)
731 catch {set docId $hist($setNo,$tno,queryId)}
734 if {[catch [list set oldHost [$zz connect]]]} {
737 $zz callback ok-response
738 $zz failback fail-response
739 set thisHost [splitHostSpec $host]
740 if {[string compare $oldHost $thisHost]} {
741 catch [list $zz disconnect]
744 if {[catch [list $zz connect $thisHost]]} {
745 displayError "Cannot connect to target" $thisHost
747 } elseif {$sessionWait == 0} {
748 if {[catch {egw_wait sessionWait 300}]} {
750 displayError "Cannot connect to target" $thisHost
753 if {$sessionWait != 1} {
754 displayError "Cannot connect to target" $thisHost
758 $zz idAuthentication $idAuth
760 if {[catch {$zz init}]} {
761 displayError "Cannot initialize target" $thisHost
765 if {$sessionWait == 0 && [catch {egw_wait sessionWait 60}]} {
766 displayError "Cannot initialize target" $thisHost
770 if {$sessionWait != "1"} {
771 displayError "Cannot initialize target" $thisHost
775 if {![$zz initResult]} {
776 set u [$zz userInformationField]
778 displayError "Cannot initialize target $thisHost" $u
781 } elseif {![catch [list $zz.$setNo smallSetUpperBound 0]]} {
783 if {[info exists hist($setNo,$tno,hits)]} {
787 if {[info exists hist($setNo,hits)]} {
793 if {![string compare [lindex $targets($host) 1] WAIS]} {
794 wais-set $zz.$setNo $zz
796 ir-set $zz.$setNo $zz
797 $zz.$setNo preferredRecordSyntax [lindex $targets($host) 1]
798 egw_log debug "set syntax to [lindex $targets($host) 1]"
800 if {![lindex $targets($host) 5]} {
803 $zz.$setNo smallSetElementSetNames $elements
804 $zz.$setNo mediumSetElementSetNames $elements
805 $zz.$setNo recordElements $elements
807 egw_log debug "database=$database"
808 eval $zz.$setNo databaseNames $database
810 $zz callback [list search-response $zz.$setNo]
812 $zz.$setNo largeSetLowerBound 999999
813 $zz.$setNo smallSetUpperBound 0
814 $zz.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
816 $zz.$setNo largeSetLowerBound 2
817 $zz.$setNo smallSetUpperBound 0
818 $zz.$setNo mediumSetPresentNumber 0
821 egw_log debug "search: $query"
823 if {[info exists docId]} {
824 $zz.$setNo search $query $docId
826 $zz.$setNo search $query
829 if {!$sessionWait && [catch {egw_wait sessionWait 60}]} {
830 egw_log debug "timeout/cancel in search"
831 displayError "Timeout in search" {}
832 html "</body></html>\n"
837 if {$sessionWait == -1} {
838 displayError "Search fail" "Connection closed"
839 html "</body></html>\n"
842 if {$sessionWait != 1} {
845 set hist($setNo,hits) [$zz.$setNo resultCount]
849 proc init-m-response {i} {
853 egw_log debug "init-m-response"
856 if {![z39$i initResult]} {
864 proc connect-m-response {i} {
868 egw_log debug "connect-m-response"
869 z39$i callback [list init-m-response $i]
870 if {[catch {z39$i init}]} {
876 proc fail-m-response {i} {
880 egw_log debug "fail-m-response"
885 proc search-m-response {setNo i start number} {
890 egw_log debug "search-m-response"
891 set status [z39$i.$setNo responseStatus]
892 egw_log debug "search-m-response1"
893 if {[lindex $status 0] == "OK"} {
895 } elseif {[lindex $status 0] == "DBOSD"} {
896 set nor [z39$i.$setNo numberOfRecordsReturned]
898 egw_log debug "search-m-response2"
903 set hist($setNo,$i,hits) [z39$i.$setNo resultCount]
904 egw_log debug "search-m-response3"
905 set hist($setNo,$i,offset) [expr $start + $nor -1]
906 if {[expr $nor + $start] > [z39$i.$setNo resultCount]} {
907 egw_log debug "search-m-response4"
912 egw_log debug "search-m-response5"
913 if {$nor >= $number} {
914 egw_log debug "search-m-response6 nor=$nor number=$number"
919 egw_log debug "search-m-response7"
920 set start [expr $start + $nor]
921 set number [expr $number - $nor]
922 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
923 set number [expr [z39$i.$setNo resultCount] - $start + 1]
925 z39$i callback [list search-m-response $setNo $i $start $number]
926 egw_log debug "mpresent start=$number number=$number"
927 z39$i.$setNo present $start $number
930 proc z39msearch {setNo elements start number cache} {
937 set not $hist($setNo,0,host)
939 egw_log debug "z39msearch start=$start number=$number elements=$elements"
940 for {set i 1} {$i <= $not} {incr i} {
941 set host $hist($setNo,$i,host)
943 set oldHost [z39$i connect]
944 set thisHost [splitHostSpec $host]
945 if {[string compare $oldHost $thisHost]} {
946 catch {z39$i disconnect}
948 z39$i callback [list connect-m-response $i]
949 z39$i failback [list fail-m-response $i]
952 for {set i 1} {$i <= $not} {incr i} {
953 set oldHost [z39$i connect]
954 set host $hist($setNo,$i,host)
955 set thisHost [splitHostSpec $host]
956 if {![string compare $oldHost $thisHost]} {
959 egw_log debug "old=$oldHost this=$thisHost"
960 z39$i idAuthentication $hist($setNo,$i,idAuthentication)
961 html "Connecting to target " $thisHost " <br>\n"
963 if {![catch {z39$i connect $thisHost}]} {
968 egw_log debug "Waiting for init response"
969 if {[catch {egw_wait zleft 20}]} {
974 for {set i 1} {$i <= $not} {incr i} {
975 set host $hist($setNo,$i,host)
977 html "host " [splitHostSpec $host] ": "
979 egw_log debug "i=$i zstatus=$zstatus($i)"
980 if {$zstatus($i) < 1} {
986 if {[catch [list z39$i.$setNo preferredRecordSyntax]]} {
991 if {![string compare [lindex $targets($host) 1] WAIS]} {
992 wais-set z39$i.$setNo z39$i
994 ir-set z39$i.$setNo z39$i
995 z39$i.$setNo preferredRecordSyntax [lindex $targets($host) 1]
996 egw_log debug "set syntax to [lindex $targets($host) 1]"
998 set hist($setNo,$i,offset) 0
999 eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
1001 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1004 set thisElements $elements
1006 z39$i.$setNo smallSetElementSetNames $thisElements
1007 z39$i.$setNo mediumSetElementSetNames $thisElements
1008 z39$i.$setNo elementSetNames $thisElements
1009 z39$i.$setNo recordElements $thisElements
1011 z39$i callback [list search-m-response $setNo $i $start $number]
1014 z39$i.$setNo largeSetLowerBound 999999
1015 z39$i.$setNo smallSetUpperBound 0
1016 z39$i.$setNo mediumSetPresentNumber $number
1018 z39$i.$setNo largeSetLowerBound 2
1019 z39$i.$setNo smallSetUpperBound 0
1020 z39$i.$setNo mediumSetPresentNumber 0
1024 egw_log debug "setNo=$setNo msearch " $hist($setNo,$i,query)
1025 z39$i.$setNo search $hist($setNo,$i,query)
1026 } elseif {[z39$i.$setNo resultCount] >= $start} {
1027 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1028 set tnumber [expr [z39$i.$setNo resultCount] - $start + 1]
1032 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1035 set thisElements $elements
1037 z39$i.$setNo smallSetElementSetNames $thisElements
1038 z39$i.$setNo mediumSetElementSetNames $thisElements
1039 z39$i.$setNo elementSetNames $thisElements
1040 z39$i.$setNo recordElements $thisElements
1042 for {set n 0} {$n < $tnumber} {incr n} {
1043 if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
1045 egw_log debug "failed on $n"
1048 html "no record at #" [expr $start + $n]
1049 html " el=-" $thisElements "-"
1054 if {$n == $tnumber} {
1061 html "present<br>\n"
1062 z39$i callback [list search-m-response $setNo $i $start $tnumber]
1064 egw_log debug "mpresent start=$start number=$tnumber"
1065 z39$i.$setNo present $start $tnumber
1072 while {$zleft > 0} {
1073 egw_log debug "Waiting for search/present response"
1074 if {[catch {egw_wait zleft 60}]} {
1078 for {set i 1} {$i <= $not} {incr i} {
1079 if {$zstatus($i) != 2} continue
1080 set status [z39$i.$setNo responseStatus]
1081 if {0 && [lindex $status 0] != "NSD"} {
1082 set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned]
1087 proc z39present {setNo tno setOffset setMax dfunc elements} {
1093 set host $hist($setNo,$tno,host)
1095 if {![lindex $targets($host) 5]} {
1099 $zz.$setNo elementSetNames $elements
1100 $zz.$setNo recordElements $elements
1101 set toGet [expr 1 + $setMax - $setOffset]
1103 $zz callback [list search-response $zz.$setNo]
1105 while {$setMax > 0 && $toGet > 0} {
1106 for {set got 0} {$got < $toGet} {incr got} {
1107 if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
1111 if {$got < $toGet} {
1113 $zz.$setNo present $setOffset $toGet
1114 if {[catch {egw_wait sessionWait 300}]} {
1115 egw_log debug "timeout/cancel in present"
1119 if {$sessionWait == "0"} {
1122 if {$sessionWait != "1"} {
1125 set got [$zz.$setNo numberOfRecordsReturned]
1130 display-rec $setOffset [expr $got + $setOffset - 1] $dfunc $setNo $tno
1131 set setOffset [expr $got + $setOffset]
1132 set toGet [expr 1 + $setMax - $setOffset]
1137 proc buttons-result-set-s {setNo targetNo setMax startPos after} {
1146 if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
1147 html {<a href="http:} $env(SCRIPT_NAME)
1148 html / $sessionId {/search.egw/} $setNo + $targetNo +
1149 html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
1151 html {"><img src="/egwgif/button-next-records.gif" alt="Next Records"}
1152 html { border=0></a>}
1154 html {">Next Records</a>} " | \n"
1157 if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
1158 html {<a href="http:} $env(SCRIPT_NAME)
1159 html / $sessionId {/search.egw/} $setNo + $targetNo
1160 html + [expr $startPos - $hist($setNo,maxPresent)]
1161 html + [expr $startPos - 1]
1163 html {"><img src="/egwgif/button-previous-records.gif" }
1164 html {alt="Previous Records" border=0></a>}
1166 html {">Previous Records</a>} " | \n"
1169 button-new-query 1 $setNo
1171 button-view-history 0
1176 proc display-result-set-m-score {setNo} {
1182 set not $hist($setNo,0,host)
1183 for {set i 1} {$i <= $not} {incr i} {
1184 if {[lindex $status 0] != "DBOSD"} continue
1186 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1187 set nor $hist($setNo,$i,maxPresent)
1189 set nor $hist($setNo,$i,offset)
1191 for {set j 1} {$j < $not} {incr j} {
1192 if {![string compare [z39$i.$setNo recordType] WAIS]} {
1193 lappend scoreArray [list \
1194 [z39$i.$setNo getWAIS $j score] $i $setNo $j]
1196 lappend scoreArray [list 0 $i $setNo $j]
1200 html "score merge<br>"
1203 proc display-result-set-m-server {setNo} {
1209 set not $hist($setNo,0,host)
1211 for {set i 1} {$i <= $not} {incr i} {
1212 if {$zstatus($i) != 2} continue
1213 html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
1214 set status [z39$i.$setNo responseStatus]
1215 if {[lindex $status 0] == "NSD"} {
1216 z39$i.$setNo nextResultSetPosition 0
1217 set code [lindex $status 1]
1218 set msg [lindex $status 2]
1219 set addinfo [lindex $status 3]
1220 html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
1222 set r [z39$i.$setNo resultCount]
1223 html "$r hits</h3>\n<dd>\n<ul>\n"
1225 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1226 display-rec 1 $hist($setNo,maxPresent) \
1227 display-brief $setNo $i
1229 display-rec 1 $hist($setNo,$i,offset) \
1230 display-brief $setNo $i
1239 proc display-result-set-m {setNo} {
1245 egw_log debug "sort=$hist($setNo,sort)"
1246 switch $hist($setNo,sort) {
1248 display-result-set-m-score $setNo
1251 display-result-set-m-server $setNo
1256 proc display-result-set-s {setNo targetNo startPos endPos} {
1261 set host $hist($setNo,$targetNo,host)
1262 set idAuth $hist($setNo,$targetNo,idAuthentication)
1263 set database $hist($setNo,$targetNo,database)
1264 set query $hist($setNo,$targetNo,query)
1268 if {$startPos == ""} {
1269 if {[z39search $setNo 1 $targetNo B] != "1"} {
1272 set r [$zz.$setNo resultCount]
1274 set setMax [$zz.$setNo resultCount]
1275 if {$setMax > $hist($setNo,maxPresent)} {
1276 set setMax $hist($setNo,maxPresent)
1278 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1280 set setOffset [$zz.$setNo numberOfRecordsReturned]
1282 html {<h3> Records 1-} $setMax " out of $r</h3>\n"
1284 html "<h3> No hits</h3>\n"
1288 display-rec 1 $setMax display-brief $setNo $targetNo
1292 if {[z39search $setNo 0 $targetNo B] != "1"} {
1295 set r [$zz.$setNo resultCount]
1296 set setOffset $startPos
1297 set setMax [$zz.$setNo resultCount]
1298 if {$setMax > $endPos} {
1301 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1303 html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
1305 html "<h3> No hits</h3>\n"
1311 z39present $setNo $targetNo $setOffset $setMax display-brief B
1315 buttons-result-set-s $setNo $targetNo $setMax $startPos 1
1318 proc z39history {} {
1327 if {![info exists nextSetNo]} {
1330 html "<h2>History</h2><br>\n"
1332 html {<table width=500 border=1><tr>}
1333 html {<td align=center><b>Target</b>}
1334 html {<td align=center><b>Database</b>}
1335 html {<td align=center><b>Hits</b>}
1336 html {<td align=center><b>Query</b>}
1341 for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
1342 if {$hist($setNo,scan) > 0} continue
1343 set host $hist($setNo,0,host)
1345 html {<td align=left>}
1349 html [lindex $targets($host) 0]
1351 html {<td align=left>} [join $hist($setNo,0,database)]
1353 if {[llength [lindex $targets($host) 1]] > 1} {
1355 foreach b $hist($setNo,0,database) {
1362 html {<td align=right>}
1364 if {[info exists hist($setNo,hits)]} {
1365 html { <a href="http:} $env(SCRIPT_NAME)
1366 html / $sessionId {/search.egw/} $setNo + $targetNo + 1
1367 html + $hist($setNo,maxPresent)
1369 html {">} $hist($setNo,hits) {</a>}
1371 html {">Result</a>: } $hist($setNo,hits) { hits.}
1377 html {Search failed.}
1381 html {<td align=left>}
1385 html { <a href="http:} $env(SCRIPT_NAME)
1386 html / $sessionId {/query.egw/} $host + $setNo
1390 html {">Query</a>: }
1393 for {set i 1} {$i <= 3} {incr i} {
1394 if {[string length $hist($setNo,form,entry$i)] > 0} {
1395 html " <b>" [join $op " "] "</b> "
1396 html [join $hist($setNo,form,menu$i)] "="
1397 html $hist($setNo,form,entry$i)
1398 set op $hist($setNo,form,logic$i)
1402 html {</a><tr>} "\n"
1413 proc displayError {msga msgb} {
1414 html "<p><center>\n"
1415 html {<img src="/egwgif/noway.gif" alt="Error">}
1416 html "<h2>" $msga "</h2>\n"
1418 html "<h3>" $msgb "</h3>\n"
1420 html "</center><p>\n"
1423 proc button-europagate {} {
1425 html {<a href="http://europagate.dtv.dk/">}
1427 html {<img src="/egwgif/button-egw.gif" alt="Europagate" border=0></a>}
1429 html {Europagate</a> | }
1433 proc button-define-target {more} {
1438 html {<a href="http:} $env(SCRIPT_NAME)
1439 html / $sessionId {/tform.egw}
1441 html {"><img src="/egwgif/button-define-target.gif" }
1442 html {alt="Define Target" border=0></a>}
1444 html {">Define Target</a>}
1453 proc button-new-target {more} {
1459 html {<a href="http:} $env(SCRIPT_NAME)
1462 html {/mtargets.egw}
1467 html {"><img src="/egwgif/button-new-target.gif" }
1468 html {alt="New Target" border=0></a>}
1470 html {">New Target</a>}
1479 proc button-view-history {more} {
1485 html {<a href="http:} $env(SCRIPT_NAME)
1486 html / $sessionId {/history.egw;}
1487 catch { html "/" $nextSetNo}
1489 html {"><img src="/egwgif/button-view-history.gif" alt="View History" }
1490 html {border=0></a>}
1492 html {">View History</a>}
1501 proc button-new-query {more setNo} {
1508 html {<a href="http:} $env(SCRIPT_NAME)
1511 html {/mquery.egw/} $setNo
1513 html {/query.egw/} $hist($setNo,0,host) + $setNo
1517 html {<img src="/egwgif/button-new-query.gif" }
1518 html {alt="New Query" border=0></a>}
1520 html {New Query</a>}
1529 proc button-scan-window {more setNo} {
1536 html {<a href="http:} $env(SCRIPT_NAME)
1537 html / $sessionId {/search.egw/} $setNo + $targetNo + {scan} {">}
1539 html {<img src="/egwgif/button-scan-window.gif" }
1540 html {alt="Scan" border=0></a>}
1551 proc maintenance {} {
1552 html {<hr>This page is maintained by }
1553 html {<a href="mailto:pwh@dtv.dk"> Peter Wad Hansen </a>.}
1554 html {Last modified 29. january 1996. <br>}
1555 html {<em> This and the following pages are under construction and }
1556 html {will continue to be so until the end of January 1996.</em>}
1559 proc splitHostSpec {host} {
1560 set i [string first / $host]
1563 return [string range $host 0 $i]
1568 proc splitDatabaseSpec {host} {
1569 set i [string first / $host]
1572 regsub -all -- - [string range $host $i end] { } res
1575 regsub -all -- - $host {} res
1579 proc mergeHostSpec {host databases} {
1580 return ${host}.[join $databases -]
1583 proc mkAssoc {assoc host} {
1586 if {[catch {$assoc failback fail-response}]} {
1587 if {![string compare [lindex $targets($host) 1] WAIS]} {
1593 if {![string compare [lindex $targets($host) 1] WAIS]} {
1594 if {[$assoc comstack] == "wais"} return
1597 if {[$assoc comstack] == "tcpip"} return