Work on search in multiple targets.
[egate.git] / www / wirtcl.c
index 672ca70..9939df8 100644 (file)
  * USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * $Log: wirtcl.c,v $
- * Revision 1.8  1995/11/06 17:44:22  adam
+ * Revision 1.9  1995/11/07 14:56:59  adam
+ * Work on search in multiple targets.
+ * New wtcl command: wlog.
+ * Optional timeout parameter to zwait.
+ *
+ * Revision 1.8  1995/11/06  17:44:22  adam
  * State reestablised when shell restarts. History of previous
  * result sets.
  *
@@ -113,7 +118,7 @@ struct tcl_info {
 };
 
 
-static int events (struct tcl_info *p, char *waitVar);
+static int events (struct tcl_info *p, char *waitVar, int tout);
 
 static int proc_zwait_invoke (ClientData clientData, Tcl_Interp *interp,
                               int argc, char **argv)
@@ -122,8 +127,7 @@ static int proc_zwait_invoke (ClientData clientData, Tcl_Interp *interp,
     
     if (argc < 2)
         return TCL_OK;
-    events (p, argv[1]);
-    return TCL_OK;
+    return events (p, argv[1], (argc == 3) ? atoi(argv[2]) : 0);
 }
 
 
@@ -185,7 +189,7 @@ static int do_exec (const char *fname, char *parms, void *mydata)
 }
 
 
-static int events (struct tcl_info *p, char *waitVar)
+static int events (struct tcl_info *p, char *waitVar, int tout)
 {
     int r, i;
     char *cp;
@@ -215,6 +219,16 @@ static int events (struct tcl_info *p, char *waitVar)
     gw_log (GW_LOG_DEBUG, mod, "Waiting %s=%s", waitVar, waitVarVal);
     while (1)
     {
+        struct timeval to, *top;
+       if (tout > 0)
+       {
+           to.tv_usec = 0;
+           to.tv_sec = tout;
+           top = &to;
+       }
+       else
+           top = 0;
+
         if (!(cp = Tcl_GetVar (p->interp, waitVar, 0)) ||
             strcmp (cp, waitVarVal))
         {
@@ -252,7 +266,7 @@ static int events (struct tcl_info *p, char *waitVar)
         FD_SET (fifo_in, &fdset_tcl_r);
 #endif
         if ((r = select(max_fd+1, &fdset_tcl_r, &fdset_tcl_w, 
-                          &fdset_tcl_x, NULL)) < 0)
+                          &fdset_tcl_x, top)) < 0)
         {
             gw_log (GW_LOG_ERRNO|GW_LOG_FATAL, mod, "select");
             exit(1);
@@ -260,12 +274,14 @@ static int events (struct tcl_info *p, char *waitVar)
         if (!r)
         {
             gw_log (GW_LOG_DEBUG, mod, "timeout");
-            break;
+            free (waitVarVal);
+            return TCL_ERROR;
         }
         if (FD_ISSET (fifo_in, &fdset_tcl_r))
         {
             gw_log (GW_LOG_DEBUG, mod, "FIFO closed");
-            break;
+            free (waitVarVal);
+            return TCL_ERROR;
         }
         for (i=0; i<=max_fd; i++)
         {