result sets.
# Europagate, 1995
#
# $Log: Makefile,v $
-# Revision 1.8 1995/11/06 10:51:14 adam
+# Revision 1.9 1995/11/06 17:44:20 adam
+# State reestablised when shell restarts. History of previous
+# result sets.
+#
+# Revision 1.8 1995/11/06 10:51:14 adam
# End of response marker in response from wsh/wproto to wcgi.
# Shells are respawned when necessary.
#
OLIB=../lib/util.a ../lib/libres+log.a
TCLLIB=/usr/local/lib/libtcl7.4.a
#
-WSCRIPTS=egwscript targets.egw query.egw search.egw showfull.egw
+WSCRIPTS=egwscript targets.egw query.egw search.egw showfull.egw z39util.tcl
HSCRIPTS=egwindex.html
CONFFILES=ztargets.conf
GIFFILES=webgate.gif
</head>
<body>
{
-# $Id: query.egw,v 1.8 1995/11/02 16:35:36 adam Exp $
+# $Id: query.egw,v 1.9 1995/11/06 17:44:20 adam Exp $
+
+ if {[info commands saveState] == ""} {
+ source z39util.tcl
+ }
+
proc fail-response {} {
global sessionWait
set sessionWait -1
}
}
set sessionWait 0
- z39 init
+ if {[catch {z39 init}]} {
+ htmlr "Cannot initialize with target ${host} <br>"
+ htmlr "</body></html>"
+ wabort
+ }
zwait sessionWait
if {$sessionWait != "1"} {
htmlr "Cannot initialize with target ${host} <br>"
}
}
<hr>
-<strong>Input your search criteria: </strong> <br>
+<h3>Input your search criteria: </h3> <br>
{
set fields [lindex $targets($host) 2]
for {set no 1} {$no < 4} {incr no} {
<a href="ccl.html"> CCL </a> here: <br>
<input type=text name="cclentry" size=52> <br>
<hr>
-<strong> Various technical parameters: </strong> <br>
+<h3> Various technical parameters: </h3> <br>
Max hits: <input type="text" name="hits" value="10" size=3>
Records are shown in:
<select name="format">
}
{
html "<hr>\n"
- html "<strong>Debug information</strong><br>\n"
+ html "<h3>Debug information</h3>\n"
html "sessionId: $sessionId <br>\n"
html "sessionParms: $sessionParms <br>\n"
foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
<html>
{
-# $Id: search.egw,v 1.7 1995/11/02 16:35:36 adam Exp $
+# $Id: search.egw,v 1.8 1995/11/06 17:44:21 adam Exp $
-proc search-response {sno} {
- global sessionWait
-
- set status [z39.$sno responseStatus]
- if {[lindex $status 0] == "NSD"} {
- z39.$sno nextResultSetPosition 0
- set code [lindex $status 1]
- set msg [lindex $status 2]
- set addinfo [lindex $status 3]
- htmlr {<strong>Error} $code {: } $msg {: } $addinfo { </strong><br>}
- set sessionWait -2
- } else {
- set sessionWait 1
- }
-}
-
-proc ok-response {} {
- global sessionWait
- set sessionWait 1
-}
-
-proc fail-response {} {
- global sessionWait
- set sessionWait -1
-}
-
-proc display-brief {zset no} {
- global env
- global setNo
- global sessionId
-
- set type [$zset type $no]
- if {$type == "SD"} {
- set err [lindex [$zset diag $no] 1]
- set add [lindex [$zset diag $no] 2]
- if {$add != {}} {
- set add " :${add}"
- }
- htmlr "${no} Error ${err}${add} <br>"
- return
- }
- if {$type != "DB"} {
- return
- }
- html "${no} "
- set rtype [$zset recordType $no]
- if {$rtype == "SUTRS"} {
- html [join [$zset getSutrs $no]]
- htmlr {<br>}
- return
- }
- if {![catch {
- set title [lindex [$zset getMarc $no field 245 * a] 0]
- set year [lindex [$zset getMarc $no field 260 * c] 0]
- } ] } {
- html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME) /
- html $sessionId {/showfull.egw/} $setNo + $no {"> } $title {</a>}
- html " <i> ${year} </i>"
- }
- htmlr {<br>}
-}
-
-proc display-full {zset no} {
- set type [$zset type $no]
- if {$type == "SD"} {
- set err [lindex [$zset diag $no] 1]
- set add [lindex [$zset diag $no] 2]
- if {$add != {}} {
- set add " :${add}"
- }
- htmlr "<hr> ${no} <br>"
- htmlr "Error ${err}${add} <br>"
- return
- }
- if {$type != "DB"} {
- return
- }
- htmlr "<hr> ${no} <br>"
- set rtype [$zset recordType $no]
- if {$rtype == "SUTRS"} {
- htmlr [join [$zset getSutrs $no]]
- return
- }
- if {[catch {set r [$zset getMarc $no line * * *]}]} {
- htmlr "Unknown record type: $rtype"
- return
- }
- foreach line $r {
- set tag [lindex $line 0]
- set indicator [lindex $line 1]
- set fields [lindex $line 2]
- set l [string length $indicator]
- html "$tag "
- if {$l > 0} {
- for {set i 0} {$i < $l} {incr i} {
- if {[string index $tag $i] == " "} {
- html "_"
- } else {
- html [string index $tag $i]
- }
- }
- }
- foreach field $fields {
- set id [lindex $field 0]
- set data [lindex $field 1]
- if {$id != ""} {
- html " <b>\$$id</b> "
- }
- html $data
- }
- htmlr {<br>}
+ if {[info commands saveState] == ""} {
+ source z39util.tcl
}
-}
-
-proc display-rec {from to} {
- global setNo
-
- while {$from <= $to} {
- display-brief z39.$setNo $from
- incr from
- }
-}
-
-proc build-query {} {
- global targets
- global t
-
- set op {}
- set q {}
- for {set i 1} {$i < 4} {incr i} {
- set term [wform entry$i]
- if {$term != ""} {
- set field [wform menu$i]
- foreach x [lindex $targets($t) 2] {
- if {[lindex $x 0] == $field} {
- set attr [lindex $x 1]
- }
- }
- switch $op {
- And
- { set q "@and $q ${attr} ${term}" }
- Or
- { set q "@or $q ${attr} ${term}" }
- {And not}
- { set q "@not $q ${attr} ${term}" }
- {}
- { set q "${attr} ${term}" }
- }
- set op [wform logic$i]
- }
- }
- return $q
-}
-
-proc research {setNo oldHost piggy} {
- global hist
- global sessionWait
-
- set host $hist($setNo,host)
- if {[catch {z39 failback fail-response}]} {
- ir z39
- }
- if {[catch {set oldHost [z39 connect]}]} {
- set oldHost ""
- }
- z39 callback ok-response
- z39 failback fail-response
- if {$oldHost != $host} {
- catch {z39 disconnect}
-
- html "Connecting to target " $host " <br>\n"
- set sessionWait 0
- if {[catch {z39 connect $host}]} {
- htmlr "Cannot connect to target ${host} <br>"
- htmlr "</body></html>"
- wabort
- } elseif {$sessionWait == 0} {
- zwait sessionWait
- if {$sessionWait != 1} {
- htmlr "Cannot connect to target ${host} <br>"
- htmlr "</body></html>"
- wabort
- }
- }
- set sessionWait 0
- z39 init
- zwait sessionWait
- if {$sessionWait != "1"} {
- htmlr "Cannot initialize with target ${host} <br>"
- htmlr "</body></html>"
- wabort
- }
- }
- if {![catch {z39.$setNo smallSetUpperBound 0}]} {
- return
- }
- ir-set z39.$setNo z39
- eval z39.$setNo databaseNames $hist($setNo,database)
-
- z39.$setNo preferredRecordSyntax USMARC
-
- z39 callback search-response $setNo
- if {$piggy} {
- z39.$setNo largeSetLowerBound 999999
- z39.$setNo smallSetUpperBound 0
- z39.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
- } else {
- z39.$setNo largeSetLowerBound 2
- z39.$setNo smallSetUpperBound 0
- z39.$setNo mediumSetPresentNumber 0
- }
- set sessionWait 0
- z39.$setNo search $hist($setNo,query)
-
- zwait sessionWait
- if {$sessionWait != 1} {
- htmlr {</body></html>}
- wabort
- }
-}
-
global sessionWait
global nextSetNo
global setNo
set oldHost $hist($setNo,host)
if {[wform menu1] == ""} {
- html "state 1<br>\n"
set setNo [lindex $sessionParms 0]
} else {
- html "state 2<br>\n"
if {![info exists hist($nextSetNo,host)]} {
set hist($nextSetNo,host) $oldHost
}
set host $hist($setNo,host)
set databases [lindex $targets($host) 1]
- htmlr {<head><title> WWW/Z39.50 Gateway Search } $host { </title>}
- htmlr {</head><body>}
- html "<h2> Search result </h2>\n"
- wflush
-
+ html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
+ html "</head><body>\n"
set startPos [lindex $sessionParms 1]
set endPos [lindex $sessionParms 2]
+ set setMax 0
+ set setOffset 0
if {$startPos == ""} {
- research $setNo $oldHost 1
-
+ if {[z39search $setNo 1] != "1"} {
+ return
+ }
set r [z39.$setNo resultCount]
- html "<h3> $r hits</h3><br>\n"
- set setOffset [z39.$setNo numberOfRecordsReturned]
- display-rec 1 $setOffset
+ html "<h2> Search result $r hits</h2>\n"
wflush
+ set setOffset [z39.$setNo numberOfRecordsReturned]
+ display-rec 1 $setOffset display-brief
incr setOffset
set setMax [z39.$setNo resultCount]
if {$setMax > $hist($setNo,maxPresent)} {
set setMax $hist($setNo,maxPresent)
}
} else {
- research $setNo $oldHost 0
-
+ if {[z39search $setNo 0] != "1"} {
+ return
+ }
+ set r [z39.$setNo resultCount]
+ html "<h2> Search result $r hits</h2>\n"
+ wflush
set setOffset $startPos
set setMax [z39.$setNo resultCount]
if {$setMax > $endPos} {
set setMax $endPos
}
}
- set toGet [expr 1 + $setMax - $setOffset]
- while {$toGet > 0} {
- for {set got 0} {$got < $toGet} {incr got} {
- if {[z39.$setNo type [expr $setOffset + $got]] == ""} {
- break
- }
- }
- if {$got < $toGet} {
- set sessionWait 0
- z39.$setNo present $setOffset $toGet
- zwait sessionWait
- if {$sessionWait != "1"} {
- break
- }
- set got [z39.$setNo numberOfRecordsReturned]
- }
- display-rec $setOffset [expr $got + $setOffset - 1]
- set setOffset [expr $got + $setOffset]
- set toGet [expr 1 + $setMax - $setOffset]
- wflush
+ if {$setMax > 0} {
+ z39present $setNo $setOffset $setMax display-brief
}
}
-{
- html "<hr>\n"
- html "<strong>Debug information</strong><br>\n"
- html "sessionId: $sessionId <br>\n"
- html "sessionParms: $sessionParms <br>\n"
- foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
- html $e {: } $env($e) {<br>} \n
- }
- html "form: " [wform] " <br>\n"
- html "target: " $host " <br>\n"
- html "databases: " $hist($setNo,database) " <br>\n"
- html "selected: " [wform base] " <br>\n"
- html "query: ->" $hist($setNo,query) "<- <br>"
- html "setNo: " $setNo " <br>\n"
- html "nextSetNo: " $nextSetNo " <br>\n"
-}
<hr>
{
html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
html + [expr $setMax + $hist($setNo,maxPresent)] {"> Next </a>} "| \n"
}
- if {$startPos != ""} {
+ if {$startPos != "" && $startPos != "1"} {
html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
html / $sessionId {/search.egw/} $setNo
if {[expr $startPos - $hist($setNo,maxPresent)] > 1} {
html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
html / $sessionId {/query.egw/} $host + $setNo {"> New query </a>}
}
+
+{
+ html "<hr>\n"
+ html "<h3>Debug information</h3>\n"
+ html "sessionId: $sessionId <br>\n"
+ html "sessionParms: $sessionParms <br>\n"
+ foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
+ html $e {: } $env($e) {<br>} \n
+ }
+ html "form: " [wform] " <br>\n"
+ html "target: " $host " <br>\n"
+ html "databases: " $hist($setNo,database) " <br>\n"
+ html "selected: " [wform base] " <br>\n"
+ html "query: --" $hist($setNo,query) "-- <br>"
+ html "setNo: " $setNo " <br>\n"
+ html "nextSetNo: " $nextSetNo " <br>\n"
+}
+
</body>
</html>
<html>
{
-# $Id: showfull.egw,v 1.2 1995/11/01 16:15:46 adam Exp $
+# $Id: showfull.egw,v 1.3 1995/11/06 17:44:21 adam Exp $
- htmlr {<head><title> WWW/Z39.50 Gateway Record } $host { </title>}
- htmlr {</head><body>}
- htmlr {sessionParms: } $sessionParms {<br>}
- wflush
+ if {[info commands saveState] == ""} {
+ source z39util.tcl
+ }
+
+ html "<head><title> WWW/Z39.50 Gateway Record " $host " </title>\n"
+ html "</head><body>\n"
+
+ global setNo
+ global hist
set sno [lindex $sessionParms 0]
set no [lindex $sessionParms 1]
- display-full z39.$sno $no
+ set setNo $sno
+
+ if {[z39search $setNo 0] != "1"} {
+ return
+ }
+ set total [z39.$setNo resultCount]
+ html "<h2>Record \#$no out of $total </h2><br>\n"
+}
+
+{
+ if {$no < [z39.$setNo resultCount]} {
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/showfull.egw/} $setNo + [expr $no + 1]
+ html {"> Next </a>} "| \n"
+ }
+ if {$no > 0} {
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/showfull.egw/} $setNo + [expr $no - 1]
+ html {"> Prev </a>} "| \n"
+ }
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/search.egw/} $setNo + 1
+ html + [expr $hist($setNo,maxPresent) - 1]
+ html {"> Result </a>} "| \n"
+
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/targets.egw"> New target </a>} " | \n"
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/query.egw/} $host + $setNo {"> New query </a>}
}
+
+{
+ z39present $setNo $no $no display-full
+# display-full z39.$sno $no
+}
+<hr>
+{
+ if {$no < [z39.$setNo resultCount]} {
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/showfull.egw/} $setNo + [expr $no + 1]
+ html {"> Next </a>} "| \n"
+ }
+ if {$no > 0} {
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/showfull.egw/} $setNo + [expr $no - 1]
+ html {"> Prev </a>} "| \n"
+ }
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/search.egw/} $setNo + 1
+ html + [expr $hist($setNo,maxPresent) - 1]
+ html {"> Result </a>} "| \n"
+
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/targets.egw"> New target </a>} " | \n"
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/query.egw/} $host + $setNo {"> New query </a>}
+}
+
</body>
</html>
<html>
{
-# $Id: targets.egw,v 1.4 1995/11/02 16:35:36 adam Exp $
+# $Id: targets.egw,v 1.5 1995/11/06 17:44:21 adam Exp $
source /usr/local/etc/httpd/conf/ztargets.conf
+ if {[info commands saveState] == ""} {
+ source z39util.tcl
+ }
}
<head>
<title> Europagate, WWW/Z39.50 Gateway </title>
Library Council <br>
Consejo Superior de Investigaciones Científicas <br>
<hr>
-<strong> Choose a Z39.50 target: </strong> <br>
+<h3> Choose a Z39.50 target: </h3>
<dl>
{
foreach t [array names targets] {
}
}
</dl>
+{
+ z39history
+}
<hr>
This page is maintained by <a href="mailto:pwh@dtv.dk"> Peter Wad Hansen </a>.
Last modified 25. september 1995. <br>
until the end of December 1995.</em>
{
html "<hr>\n"
- html "<strong>Debug information</strong><br>\n"
+ html "<h3>Debug information</h3>\n"
html "sessionId: $sessionId <br>\n"
html "sessionParms: $sessionParms <br>\n"
foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
* USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $Log: wcgi.c,v $
- * Revision 1.5 1995/11/06 10:51:15 adam
+ * Revision 1.6 1995/11/06 17:44:22 adam
+ * State reestablised when shell restarts. History of previous
+ * result sets.
+ *
+ * Revision 1.5 1995/11/06 10:51:15 adam
* End of response marker in response from wsh/wproto to wcgi.
* Shells are respawned when necessary.
*
gw_log (GW_LOG_DEBUG, prog, "Synchronizing with client");
if ((linein = open(serverp, O_RDONLY)) < 0)
{
- gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "open server %s", serverp);
+ gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "open %s", serverp);
fatal("Internal error in server.");
}
if (read(linein, combuf, 2) < 2 || strcmp(combuf, "OK"))
{
- gw_log (GW_LOG_FATAL, prog, "Failed to synchronize with client.");
+ gw_log (GW_LOG_FATAL, prog, "Failed to synchronize with client");
fatal("Internal error in server");
}
- gw_log (GW_LOG_DEBUG, prog, "Synchronized.");
+ gw_log (GW_LOG_DEBUG, prog, "Synchronized");
}
sprintf(clientp, "%s/clt%d", tmp, gw_id);
gw_log (GW_LOG_DEBUG, prog, "Opening %s", clientp);
gw_log (GW_LOG_DEBUG, prog, "Synchronizing with client");
if ((linein = open(serverp, O_RDONLY)) < 0)
{
- gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "open server %s", serverp);
+ gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "open %s", serverp);
fatal("Internal error in server");
}
if (read(linein, combuf, 2) < 2 || strcmp(combuf, "OK"))
if ((lineout = open(clientp, O_WRONLY)) < 0)
{
gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "%s", clientp);
- gw_db_close (gw_db);
- exit (1);
+ fatal("Internal error in server");
}
}
gw_db_close (gw_db);
- gw_log (GW_LOG_DEBUG, prog, "Decoding user data.");
+ gw_log (GW_LOG_DEBUG, prog, "Decoding user data");
p = combuf + sizeof(data);
strcpy(p, serverp);
p += strlen(p) + 1;
{
if (read(0, p, data) < data)
{
- gw_log (GW_LOG_FATAL, prog, "Failed to read input.");
- fatal("Internal error in server.");
+ gw_log (GW_LOG_FATAL, prog, "Failed to read input");
+ fatal("Internal error in server");
}
}
p += data;
*(p++) = '\0';
data = (p - combuf);
memcpy(combuf, &data, sizeof(data));
- gw_log (GW_LOG_DEBUG, prog, "Writing data.");
+ gw_log (GW_LOG_DEBUG, prog, "Writing data");
if (write(lineout, combuf, data) < data)
{
gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "write");
- fatal("Internal server error.");
+ fatal("Internal server error");
}
if (linein < 0 && (linein = open(serverp, O_RDONLY)) < 0)
{
- gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "open server %s", serverp);
- fatal("Internal error in server.");
+ gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "open %s", serverp);
+ fatal("Internal error in server");
}
- gw_log (GW_LOG_DEBUG, prog, "Reading response.");
+ gw_log (GW_LOG_DEBUG, prog, "Reading response");
#if 0
while ((data = read(linein, combuf, COMBUF)) > 0)
break;
if (r > 0 && FD_ISSET (1, &s_input))
{
- gw_log (GW_LOG_DEBUG, prog, "stdout closed");
- break;
+ data = read (1, combuf, COMBUF);
+ if (data == -1)
+ {
+ gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, prog, "stdout closed");
+ break;
+ }
+ if (data == 0)
+ {
+ gw_log (GW_LOG_DEBUG, prog, "stdout closed");
+ break;
+ }
+ gw_log (GW_LOG_DEBUG, prog, "stdout got %d bytes", data);
}
}
#endif
* USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $Log: winterp.h,v $
- * Revision 1.3 1995/10/27 15:12:07 adam
+ * Revision 1.4 1995/11/06 17:44:22 adam
+ * State reestablised when shell restarts. History of previous
+ * result sets.
+ *
+ * Revision 1.3 1995/10/27 15:12:07 adam
* IrTcl incorporated in the gateway.
* Better separation of script types.
* Z39.50 gateway scripts entered.
char *name;
void *(*create)(WCLIENT wcl, void *args);
int (*exec)(const char *fname, char *parms, void *private);
+ int (*load_state)(char *parms, void *private);
+ int (*save_state)(char *parms, void *private);
} *W_Interp_Type;
typedef struct w_interp {
W_Interp w_interp_create (W_Interp_Type type, WCLIENT wcl, void *args);
#define w_interp_exec(w,f,p) (*(w)->ctrl->exec)((f),(p), (w)->mydata)
+#define w_interp_load_state(w,p) (*(w)->ctrl->save_state)((p), (w)->mydata)
+#define w_interp_save_state(w,p) (*(w)->ctrl->load_state)((p), (w)->mydata)
#define w_interp_name(w) ((w)->ctrl.name)
#endif
* USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $Log: wirtcl.c,v $
- * Revision 1.7 1995/11/02 16:35:37 adam
+ * Revision 1.8 1995/11/06 17:44:22 adam
+ * State reestablised when shell restarts. History of previous
+ * result sets.
+ *
+ * Revision 1.7 1995/11/02 16:35:37 adam
* Bug fixes and select on FIFOs in wcgi - doesn't really work!
*
* Revision 1.6 1995/11/01 16:15:47 adam
static void *do_create (WCLIENT wcl, void *args);
static int do_exec (const char *fname, char *parms, void *mydata);
+static int do_load (char *parms, void *mydata);
+static int do_save (char *parms, void *mydata);
static struct w_interp_type w_interp_t = {
"irtcl",
do_create,
- do_exec
+ do_exec,
+ do_load,
+ do_save
};
W_Interp_Type w_interp_irtcl = &w_interp_t;
callback_table[fd].w_handle = NULL;
callback_table[fd].x_handle = NULL;
}
+
+static int do_load (char *parms, void *mydata)
+{
+ struct tcl_info *p = mydata;
+
+ return w_interp_load_state (p->w_interp, parms);
+}
+
+static int do_save (char *parms, void *mydata)
+{
+ struct tcl_info *p = mydata;
+
+ return w_interp_save_state (p->w_interp, parms);
+}
+
* USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $Log: wsh.c,v $
- * Revision 1.6 1995/11/06 10:51:19 adam
+ * Revision 1.7 1995/11/06 17:44:23 adam
+ * State reestablised when shell restarts. History of previous
+ * result sets.
+ *
+ * Revision 1.6 1995/11/06 10:51:19 adam
* End of response marker in response from wsh/wproto to wcgi.
* Shells are respawned when necessary.
*
#include "wtcl.h"
#include "wirtcl.h"
-#define TIMEOUT_SHORT 120
+#define TIMEOUT_SHORT 60
#define TIMEOUT_MEDIUM 1800
#define TIMEOUT_LONG 7200
*argv);
exit (1);
}
+ w_interp_load_state (w_interp, NULL);
while (wproto_process(wcl, timeout) > 0)
{
char *p;
}
wo_finish(wcl);
}
+ w_interp_save_state (w_interp, NULL);
wproto_terminate(wcl);
return 0;
}
* USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $Log: wtcl.c,v $
- * Revision 1.7 1995/10/31 16:56:25 adam
+ * Revision 1.8 1995/11/06 17:44:23 adam
+ * State reestablised when shell restarts. History of previous
+ * result sets.
+ *
+ * Revision 1.7 1995/10/31 16:56:25 adam
* Record presentation.
*
* Revision 1.6 1995/10/31 10:03:54 adam
static void *do_create (WCLIENT wcl, void *args);
static int do_exec (const char *fname, char *parms, void *mydata);
+static int do_load (char *parms, void *mydata);
+static int do_save (char *parms, void *mydata);
static struct w_interp_type w_interp_t = {
"tcl",
do_create,
- do_exec
+ do_exec,
+ do_load,
+ do_save
};
W_Interp_Type w_interp_tcl = &w_interp_t;
struct tcl_info *p = (struct tcl_info*) clientData;
p->wabort = 1;
+ if (argc > 1)
+ Tcl_AppendResult (interp, argv[1], NULL);
return TCL_RETURN;
}
fclose (inf);
return 0;
}
+
+
+static int do_load (char *parms, void *mydata)
+{
+ struct tcl_info *p = mydata;
+ char fname[80];
+ int r;
+
+ sprintf (fname, "tcl.state.%d", p->wcl->id);
+ r = Tcl_EvalFile (p->interp, fname);
+ if (r == TCL_ERROR)
+ report_error (p, p->interp->errorLine,
+ "Error in Tcl loadState in line",
+ Tcl_GetVar (p->interp, "errorInfo", 0));
+ return 0;
+}
+
+static int do_save (char *parms, void *mydata)
+{
+ struct tcl_info *p = mydata;
+ struct Tcl_CmdInfo cinfo;
+
+ if (Tcl_GetCommandInfo(p->interp, "saveState", &cinfo))
+ {
+ int r;
+
+ gw_log (GW_LOG_DEBUG, mod, "saveState");
+ r = Tcl_Eval (p->interp, "saveState\n");
+ if (r == TCL_ERROR)
+ report_error (p, p->interp->errorLine,
+ "Error in Tcl saveState in line",
+ Tcl_GetVar (p->interp, "errorInfo", 0));
+ }
+ return 0;
+}
+
--- /dev/null
+#
+# $Id: z39util.tcl,v 1.1 1995/11/06 17:44:23 adam Exp $
+#
+proc saveState {} {
+ uplevel #0 {
+ set f [open "tcl.state.${sessionId}" w]
+ foreach var [info globals] {
+ if {$var == "f"} continue
+ if {$var == "sessionId"} continue
+ if {$var == "errorInfo"} continue
+ set names [array names $var]
+ if {$names != ""} {
+ foreach n $names {
+ eval "set v \$${var}(\$n)"
+ puts $f "set ${var}($n) \{$v\}"
+ }
+ } else {
+ eval "set v \$${var}"
+ puts $f "set ${var} \{$v\}"
+ }
+ }
+ close $f
+ }
+}
+
+proc search-response {sno} {
+ global sessionWait
+
+ set status [z39.$sno responseStatus]
+ if {[lindex $status 0] == "NSD"} {
+ z39.$sno nextResultSetPosition 0
+ set code [lindex $status 1]
+ set msg [lindex $status 2]
+ set addinfo [lindex $status 3]
+ html "<h2>Error NSD$code: $msg: $addinfo </h2><br>\n"
+ set sessionWait -2
+ } else {
+ set sessionWait 1
+ }
+}
+
+proc ok-response {} {
+ global sessionWait
+ set sessionWait 1
+}
+
+proc fail-response {} {
+ global sessionWait
+ set sessionWait -1
+}
+
+proc display-brief {zset no} {
+ global env
+ global setNo
+ global sessionId
+
+ set type [$zset type $no]
+ if {$type == "SD"} {
+ set err [lindex [$zset diag $no] 1]
+ set add [lindex [$zset diag $no] 2]
+ if {$add != {}} {
+ set add " :${add}"
+ }
+ html "${no} Error ${err}${add} <br>\n"
+ return
+ }
+ if {$type != "DB"} {
+ return
+ }
+ html "${no} "
+ set rtype [$zset recordType $no]
+ if {$rtype == "SUTRS"} {
+ html [join [$zset getSutrs $no]]
+ htmlr {<br>}
+ return
+ }
+ if {![catch {
+ set title [lindex [$zset getMarc $no field 245 * a] 0]
+ set year [lindex [$zset getMarc $no field 260 * c] 0]
+ } ] } {
+ html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME) /
+ html $sessionId {/showfull.egw/} $setNo + $no {"> } $title {</a>}
+ html " <i> ${year} </i>"
+ }
+ htmlr {<br>}
+}
+
+proc display-full {zset no} {
+ set type [$zset type $no]
+ if {$type == "SD"} {
+ set err [lindex [$zset diag $no] 1]
+ set add [lindex [$zset diag $no] 2]
+ if {$add != {}} {
+ set add " :${add}"
+ }
+ htmlr "<hr> ${no} <br>"
+ htmlr "Error ${err}${add} <br>"
+ return
+ }
+ if {$type != "DB"} {
+ return
+ }
+ htmlr "<hr> ${no} <br>"
+ set rtype [$zset recordType $no]
+ if {$rtype == "SUTRS"} {
+ htmlr [join [$zset getSutrs $no]]
+ return
+ }
+ if {[catch {set r [$zset getMarc $no line * * *]}]} {
+ htmlr "Unknown record type: $rtype"
+ return
+ }
+ foreach line $r {
+ set tag [lindex $line 0]
+ set indicator [lindex $line 1]
+ set fields [lindex $line 2]
+ set l [string length $indicator]
+ html "$tag "
+ if {$l > 0} {
+ for {set i 0} {$i < $l} {incr i} {
+ if {[string index $tag $i] == " "} {
+ html "_"
+ } else {
+ html [string index $tag $i]
+ }
+ }
+ }
+ foreach field $fields {
+ set id [lindex $field 0]
+ set data [lindex $field 1]
+ if {$id != ""} {
+ html " <b>\$$id</b> "
+ }
+ html $data
+ }
+ htmlr {<br>}
+ }
+}
+
+proc display-rec {from to dfunc} {
+ global setNo
+
+ while {$from <= $to} {
+ eval "$dfunc z39.$setNo $from"
+ incr from
+ }
+}
+
+proc build-query {} {
+ global targets
+ global t
+
+ set op {}
+ set q {}
+ for {set i 1} {$i < 4} {incr i} {
+ set term1 [wform entry$i]
+ regsub {\+} $term1 " " term
+ if {$term != ""} {
+ set field [wform menu$i]
+ foreach x [lindex $targets($t) 2] {
+ if {[lindex $x 0] == $field} {
+ set attr [lindex $x 1]
+ }
+ }
+ switch $op {
+ And
+ { set q "@and $q ${attr} \{${term}\}" }
+ Or
+ { set q "@or $q ${attr} \{${term}\}" }
+ {And not}
+ { set q "@not $q ${attr} \{${term}\}" }
+ {}
+ { set q "${attr} \{${term}\}" }
+ }
+ set op [wform logic$i]
+ }
+ }
+ return $q
+}
+
+proc z39search {setNo piggy} {
+ global hist
+ global sessionWait
+
+ set host $hist($setNo,host)
+ if {[catch {z39 failback fail-response}]} {
+ ir z39
+ }
+ if {[catch {set oldHost [z39 connect]}]} {
+ set oldHost ""
+ }
+ z39 callback ok-response
+ z39 failback fail-response
+ if {$oldHost != $host} {
+ catch {z39 disconnect}
+
+ html "Connecting to target " $host " <br>\n"
+ set sessionWait 0
+ if {[catch {z39 connect $host}]} {
+ html "Cannot connect to target ${host} <br>\n"
+ return 0
+ } elseif {$sessionWait == 0} {
+ zwait sessionWait
+ if {$sessionWait != 1} {
+ html "Cannot connect to target ${host} <br>\n"
+ return 0
+ }
+ }
+ set sessionWait 0
+ if {[catch {z39 init}]} {
+ html "Cannot initialize with target ${host} <br>\n"
+ return 0
+ }
+ zwait sessionWait
+ if {$sessionWait != "1"} {
+ html "Cannot initialize with target ${host} <br>\n"
+ return 0
+ }
+ }
+ if {![catch {z39.$setNo smallSetUpperBound 0}]} {
+ return 1
+ }
+ ir-set z39.$setNo z39
+ eval z39.$setNo databaseNames $hist($setNo,database)
+
+ z39.$setNo preferredRecordSyntax USMARC
+
+ z39 callback search-response $setNo
+ if {$piggy} {
+ z39.$setNo largeSetLowerBound 999999
+ z39.$setNo smallSetUpperBound 0
+ z39.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
+ } else {
+ z39.$setNo largeSetLowerBound 2
+ z39.$setNo smallSetUpperBound 0
+ z39.$setNo mediumSetPresentNumber 0
+ }
+ set sessionWait 0
+ z39.$setNo search $hist($setNo,query)
+
+ zwait sessionWait
+ if {$sessionWait != 1} {
+ html "</body></html>\n"
+ return 0
+ }
+ set status [z39.$setNo responseStatus]
+ if {[lindex $status 0] == "NSD"} {
+ set code [lindex $status 1]
+ set msg [lindex $status 2]
+ set addinfo [lindex $status 3]
+ html "<h2>Error NSD$code: $msg: $addinfo </h2><br>\n"
+ return 0
+ }
+ set hist($setNo,hits) [z39.$setNo resultCount]
+ return 1
+}
+
+proc z39present {setNo setOffset setMax dfunc} {
+ global hist
+ global sessionWait
+
+ set toGet [expr 1 + $setMax - $setOffset]
+ while {$setMax > 0 && $toGet > 0} {
+ for {set got 0} {$got < $toGet} {incr got} {
+ if {[z39.$setNo type [expr $setOffset + $got]] == ""} {
+ break
+ }
+ }
+ if {$got < $toGet} {
+ set sessionWait 0
+ z39.$setNo present $setOffset $toGet
+ zwait sessionWait
+ if {$sessionWait != "1"} {
+ break
+ }
+ set got [z39.$setNo numberOfRecordsReturned]
+ }
+ display-rec $setOffset [expr $got + $setOffset - 1] $dfunc
+ set setOffset [expr $got + $setOffset]
+ set toGet [expr 1 + $setMax - $setOffset]
+ wflush
+ }
+}
+
+proc z39history {} {
+ global nextSetNo
+ global hist
+ global env
+ global sessionId
+
+ if {![info exists nextSetNo]} {
+ return
+ }
+ html "<hr><h3>History</h3><dl>\n"
+ for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
+ html {<dt> <a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
+ html / $sessionId {/search.egw/} $setNo + 1
+ html + [expr $hist($setNo,maxPresent) - 1]
+ html {"> } $hist($setNo,host)
+ if {[llength $hist($setNo,database)] > 1} {
+ html ": "
+ foreach b $hist($setNo,database) {
+ html " $b"
+ }
+ }
+ html "</a>\n"
+ html "<dd> "
+ if {[info exists hist($setNo,hits)]} {
+ html $hist($setNo,hits) " hits"
+ } else {
+ html failed
+ }
+ html "\n"
+ }
+ html "</dl>\n"
+}
\ No newline at end of file
-# $Id: ztargets.conf,v 1.4 1995/11/01 16:15:48 adam Exp $
+# $Id: ztargets.conf,v 1.5 1995/11/06 17:44:24 adam Exp $
set commonFields {
{ Title {@attr 1=4} }
{ Author {@attr 1=1003} }
set targets(dtbsun.dtv.dk:9999) [list \
zserver \
- {usgs esdd} \
+ {usgs esdd cd_rom unknown} \
$commonFields \
]