Uses string compare instead of !=/== when possible.
[egate.git] / www / z39util.tcl
index 1d78f64..8553519 100644 (file)
@@ -1,5 +1,5 @@
 #
-# $Id: z39util.tcl,v 1.28 1996/01/29 17:31:48 adam Exp $
+# $Id: z39util.tcl,v 1.33 1996/02/21 16:57:39 adam Exp $
 #
 proc saveState {} {
     uplevel #0 {
@@ -104,7 +104,7 @@ proc display-brief {zset no tno} {
        set location [$zset getMarc $no field 260 * a] 
        set publisher [$zset getMarc $no field 260 * b]
         set year [$zset getMarc $no field 260 * c]
-    } ] } {
+    } dispError ] } {
         html { <a href="http:} $env(SCRIPT_NAME) /
         html $sessionId {/showfull.egw/} $setNo + $tno + $no + full {">}
         set p 0
@@ -140,12 +140,22 @@ proc display-brief {zset no tno} {
         if {$nope} {
             set v [join $cover ""]
             if {[string length $v] > 40} {
+                set nope 0
                 html [string range $v 0 38] "..."
-            } else {
+            } elseif {[string length $v] > 0} {
+                set nope 0
                 html $v
+            } else {
+                html "No Title"
             }
        }
         html {</a> }
+    } else {
+        html { <a href="http:} $env(SCRIPT_NAME) /
+        html $sessionId {/showfull.egw/} $setNo + $tno + $no + full {">}
+        html {No Title}
+        html {</a> }
+        html "Error: " $dispError "\n"
     }
     html "<br>\n"
 }
@@ -391,7 +401,7 @@ proc display-full {zset no tno} {
         if {"x$sp" == "x"} {
             set sp $url
         }
-        html {<dd><a href="} $url {">} [join $sp] "</a>\n"
+        html {<dd><a href="} [join $url] {">} [join $sp] "</a>\n"
     }
     dl-marc-field $zset $no 037 {[abc]} "Acquisition" {} "<br>\n"
     dl-marc-field $zset $no 037 {[f6]} "Form of issue" {} "<br>\n"
@@ -496,7 +506,7 @@ proc z39scan {setNo scanNo tno scanLines scanPos cache} {
     $zz callback ok-response
     $zz failback fail-response
     set thisHost [splitHostSpec $host]
-    if {$oldHost != $thisHost} {
+    if {[string compare $oldHost $thisHost]} {
         catch [list $zz disconnect]
 
         set sessionWait 0
@@ -601,7 +611,7 @@ proc display-scan {setNo scanNo tno} {
             set hist($setNo,[expr $scanNo + 1],scanTerm) $t
         }
     }
-    html {<table border=0><tr>}
+    html {<table width=500 border=0><tr>}
     html {<td align=left><b>Scan term</b>}
     html {<td align=right><b>Hits</b>}
     html {<tr>} \n
@@ -655,7 +665,7 @@ proc z39search {setNo piggy tno elements} {
     $zz callback ok-response
     $zz failback fail-response
     set thisHost [splitHostSpec $host]
-    if {$oldHost != $thisHost} {
+    if {[string compare $oldHost $thisHost]} {
         catch [list $zz disconnect]
 
         set sessionWait 0
@@ -696,15 +706,19 @@ proc z39search {setNo piggy tno elements} {
             displayError "Cannot initialize target $thisHost" $u
             return 0
         }
-    } else {
-        if {[info exists hist($setNo,hits)] && \
-                ![catch [list $zz.$setNo smallSetUpperBound 0]]} {
-            return 1
+    } elseif {![catch  [list $zz.$setNo smallSetUpperBound 0]]} {
+        if {$tno > 0} {
+            if {[info exists hist($setNo,$tno,hits)]} {
+                return 1
+            }
+        } else {
+            if {[info exists hist($setNo,hits)]} {
+                return 1
+            }
         }
-        
     }
     ir-set $zz.$setNo $zz
-    
+
     if {![lindex $targets($host) 5]} {
         set elements {}
     }
@@ -731,7 +745,7 @@ proc z39search {setNo piggy tno elements} {
     egw_log debug "search: $query"
     $zz.$setNo search $query
 
-    if {[catch {egw_wait sessionWait 600}]} {
+    if {[catch {egw_wait sessionWait 60}]} {
         egw_log debug "timeout/cancel in search"
         displayError "Timeout in search" {}
         html "</body></html>\n"
@@ -757,8 +771,13 @@ proc init-m-response {i} {
 
     egw_log debug "init-m-response"
 
-    set zstatus($i) 1
     incr zleft -1
+    if {![z39$i initResult]} {
+        set zstatus($i) -1
+        z39$i disconnect
+        return
+    }
+    set zstatus($i) 1
 }
 
 proc connect-m-response {i} {
@@ -790,16 +809,20 @@ proc search-m-response {setNo i start number} {
     egw_log debug "search-m-response"
     set status [z39$i.$setNo responseStatus]
     egw_log debug "search-m-response1"
-    if {[lindex $status 0] != "DBOSD"} {
+    if {[lindex $status 0] == "OK"} {
+        set nor 0
+    } elseif {[lindex $status 0] == "DBOSD"} {
+        set nor [z39$i.$setNo numberOfRecordsReturned]
+    } else {
         egw_log debug "search-m-response2"
         incr zleft -1
         set zstatus($i) 2
         return
     }
-    set nor [z39$i.$setNo numberOfRecordsReturned]
+    set hist($setNo,$i,hits) [z39$i.$setNo resultCount]
     egw_log debug "search-m-response3"
     set hist($setNo,$i,offset) [expr $start + $nor -1]
-    if {[expr $nor + $start] >= [z39$i.$setNo resultCount]} {
+    if {[expr $nor + $start] > [z39$i.$setNo resultCount]} {
         egw_log debug "search-m-response4"
         incr zleft -1
         set zstatus($i) 2
@@ -807,7 +830,7 @@ proc search-m-response {setNo i start number} {
     }
     egw_log debug "search-m-response5"
     if {$nor >= $number} {
-        egw_log debug "search-m-response6"
+        egw_log debug "search-m-response6 nor=$nor number=$number"
         incr zleft -1
         set zstatus($i) 2
         return
@@ -828,9 +851,11 @@ proc z39msearch {setNo elements start number cache} {
     global zstatus
     global hist
     global targets
+    global debug
 
     set not $hist($setNo,0,host)
 
+    egw_log debug "z39msearch start=$start number=$number elements=$elements"
     for {set i 1} {$i <= $not} {incr i} {
         set host $hist($setNo,$i,host)
         if {[catch [list z39$i failback fail-m-response $i]]} {
@@ -838,7 +863,7 @@ proc z39msearch {setNo elements start number cache} {
         }
         set oldHost [z39$i connect]
         set thisHost [splitHostSpec $host]
-        if {$oldHost != $thisHost} {
+        if {[string compare $oldHost $thisHost]} {
             catch {z39$i disconnect}
         }
         z39$i callback [list connect-m-response $i]
@@ -849,7 +874,7 @@ proc z39msearch {setNo elements start number cache} {
         set oldHost [z39$i connect]
         set host $hist($setNo,$i,host)
         set thisHost [splitHostSpec $host]
-        if {$oldHost == $thisHost} {
+        if {![string compare $oldhost $thisHost]} {
             continue
         }
         egw_log debug "old=$oldHost this=$thisHost"
@@ -868,14 +893,20 @@ proc z39msearch {setNo elements start number cache} {
     }
     set zleft 0
     for {set i 1} {$i <= $not} {incr i} {
-        html "host " [splitHostSpec $hist($setNo,$i,host)] ": "
+        if {$debug} {
+            html "host " [splitHostSpec $hist($setNo,$i,host)] ": "
+        }
         egw_log debug "i=$i zstatus=$zstatus($i)"
         if {$zstatus($i) < 1} {
-            html "fail<br>\n"
+            if {$debug} {
+                html "fail<br>\n"
+            }
             continue
         }
         if {[catch [list z39$i.$setNo preferredRecordSyntax USMARC]]} {
-            html "ok<br>\n"
+            if {$debug} {
+                html "ok<br>\n"
+            }
             ir-set z39$i.$setNo z39$i
             set hist($setNo,$i,offset) 0
             eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
@@ -923,15 +954,21 @@ proc z39msearch {setNo elements start number cache} {
             z39$i.$setNo recordElements $thisElements
 
             for {set n 0} {$n < $tnumber} {incr n} {
-                if {[z39$i.$setNo type [expr $start + $n]] == ""} {
+                if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
                     if {$n > 0} {
                         egw_log debug "failed on $n"
                     }
+                    if {$debug} {
+                        html "no record at #" [expr $start + $n]
+                        html " el=-" $thisElements "-"
+                    }
                     break
                 }
             }
             if {$n == $tnumber} {
-                html "cached<br>\n"
+                if {$debug} {
+                    html "cached<br>\n"
+                }
                 continue
             }
             
@@ -942,7 +979,9 @@ proc z39msearch {setNo elements start number cache} {
             egw_log debug "mpresent start=$start number=$tnumber"
             z39$i.$setNo present $start $tnumber
         } else {
-            html "ok<br>\n"
+            if {$debug} {
+                html "ok<br>\n"
+            }
         }
     }
     while {$zleft > 0} {
@@ -985,7 +1024,7 @@ proc z39present {setNo tno setOffset setMax dfunc elements} {
 
     while {$setMax > 0 && $toGet > 0} {
         for {set got 0} {$got < $toGet} {incr got} {
-            if {[$zz.$setNo type [expr $setOffset + $got]] == ""} {
+            if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
                 break
             }
         }
@@ -1029,10 +1068,10 @@ proc z39history {} {
     html "<h2>History</h2><br>\n"
     if {$html3} {
         html {<table width=500 border=1><tr>}
-        html {<td align=left><b>Target</b>}
-        html {<td align=left><b>Database</b>}
-        html {<td align=right><b>Hits</b>}
-        html {<td><b>Query</b>}
+        html {<td align=center><b>Target</b>}
+        html {<td align=center><b>Database</b>}
+        html {<td align=center><b>Hits</b>}
+        html {<td align=center><b>Query</b>}
         html {<tr>} "\n"
     } else {
         html {<dl>} "\n"