chiark / gitweb /
scriptinv supports xargs and adns uses them
authorian <ian>
Sat, 18 Dec 2004 14:33:59 +0000 (14:33 +0000)
committerian <ian>
Sat, 18 Dec 2004 14:33:59 +0000 (14:33 +0000)
adns/adns.c
base/chiark-tcl.h
base/scriptinv.c
dgram/dgram.c
hbytes/hbytes.h
tuntap/tuntap.c

index 5f26d327d0a3029c606b97ed4c250474fa44f6eb..585ce399b1fa890b3f63056876b2b2c266d8dfe2 100644 (file)
@@ -604,9 +604,9 @@ int do_adns_asynch(ClientData cd, Tcl_Interp *ip,
 
   res= op.resolver;
 
-  rc= scriptinv_set_xa(&query->on_yes, ip,on_yes);   if (rc) goto x_rc;
-  rc= scriptinv_set_xa(&query->on_no,  ip,on_no);    if (rc) goto x_rc;
-  rc= scriptinv_set_xa(&query->on_fail,ip,on_fail);  if (rc) goto x_rc;
+  rc= scriptinv_set(&query->on_yes, ip,on_yes, xargs);  if (rc) goto x_rc;
+  rc= scriptinv_set(&query->on_no,  ip,on_no,  xargs);  if (rc) goto x_rc;
+  rc= scriptinv_set(&query->on_fail,ip,on_fail,xargs);  if (rc) goto x_rc;
   query->xargs= xargs;
   Tcl_IncrRefCount(xargs);
   *result= query;
index b49301f02a935950b0c9a17c725ce395dde0671e..875b23911402d6e6e72edf8b50b83190764971d2 100644 (file)
@@ -202,11 +202,13 @@ void sockaddr_free(const SockAddr_Value*);
 typedef struct { /* semi-opaque - read only, and then only where commented */
   Tcl_Interp *ip; /* valid, non-0 and useable if set */
   Tcl_Obj *obj; /* non-0 iff set (but only test for 0/non-0) */
+  Tcl_Obj *xargs;
   int llength;
 } ScriptToInvoke;
 
 void scriptinv_init(ScriptToInvoke *si);
-int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, Tcl_Obj *newscript);
+int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip,
+                 Tcl_Obj *newscript, Tcl_Obj *xargs);
 void scriptinv_cancel(ScriptToInvoke *si); /* then don't invoke */
   /* no separate free function - just cancel */
 
index b27654e8b41827192966642af16480394a699346..1ac7e82ea14967943949bdf7f21f42aa2d236394 100644 (file)
@@ -14,16 +14,22 @@ void scriptinv_cancel(ScriptToInvoke *si) {
   }
 }
 
-int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, Tcl_Obj *newscript) {
+int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip,
+                 Tcl_Obj *newscript, Tcl_Obj *xargs) {
   int rc;
   
   scriptinv_cancel(si);
 
-  rc= Tcl_ListObjLength(ip, newscript, &si->llength);
-  if (rc) return rc;
-
+  rc= Tcl_ListObjLength(ip, newscript, &si->llength);  if (rc) return rc;
   Tcl_IncrRefCount(newscript);
+
+  if (xargs) {
+    rc= Tcl_ListObjLength(ip, xargs, &si->llength);  if (rc) return rc;
+    Tcl_IncrRefCount(xargs);
+  }
+
   si->obj= newscript;
+  si->xargs= xargs;
   si->ip= ip;
   return 0;
 }  
@@ -38,7 +44,12 @@ void scriptinv_invoke(ScriptToInvoke *si, int argc, Tcl_Obj **argv) {
   invoke= Tcl_DuplicateObj(si->obj);
   Tcl_IncrRefCount(invoke);
 
-  rc= Tcl_ListObjReplace(si->ip,invoke,si->llength,0,argc,argv);
+  if (si->xargs) {
+    rc= Tcl_ListObjAppendList(si->ip, invoke, si->xargs);
+    if (rc) goto x_rc;
+  }
+
+  rc= Tcl_ListObjReplace(si->ip, invoke,si->llength,0, argc,argv);
   for (i=0; i<argc; i++) { Tcl_DecrRefCount(argv[i]); argv[i]= 0; }
   if (rc) goto x_rc;
 
index ff16917fb352c3843f2ea911ba79185223c8fcd7..63d3b2923731552f72da76694a2fc35a030afce8 100644 (file)
@@ -142,7 +142,7 @@ int do_dgram_socket_on_receive(ClientData cd, Tcl_Interp *ip,
   cancel(sock);
   
   if (newscript) {
-    rc= scriptinv_set(&sock->script, ip, newscript);
+    rc= scriptinv_set(&sock->script, ip, newscript, 0);
     if (rc) return rc;
   }
   
index b49301f02a935950b0c9a17c725ce395dde0671e..875b23911402d6e6e72edf8b50b83190764971d2 100644 (file)
@@ -202,11 +202,13 @@ void sockaddr_free(const SockAddr_Value*);
 typedef struct { /* semi-opaque - read only, and then only where commented */
   Tcl_Interp *ip; /* valid, non-0 and useable if set */
   Tcl_Obj *obj; /* non-0 iff set (but only test for 0/non-0) */
+  Tcl_Obj *xargs;
   int llength;
 } ScriptToInvoke;
 
 void scriptinv_init(ScriptToInvoke *si);
-int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, Tcl_Obj *newscript);
+int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip,
+                 Tcl_Obj *newscript, Tcl_Obj *xargs);
 void scriptinv_cancel(ScriptToInvoke *si); /* then don't invoke */
   /* no separate free function - just cancel */
 
index f45b3c9b1419a116192684faee3064498035ebbc..9deec5745a6cea82b4ae479d51dfa55bf6068f37 100644 (file)
@@ -130,7 +130,7 @@ int do_tuntap_socket_raw_on_transmit(ClientData cd, Tcl_Interp *ip,
   cancel(sock);
   
   if (newscript) {
-    rc= scriptinv_set(&sock->script,ip,newscript);
+    rc= scriptinv_set(&sock->script,ip,newscript,0);
     if (rc) return rc;
     
     sock->mtu= mtu;