4 #include "chiark-tcl-base.h"
6 void cht_scriptinv_init(ScriptToInvoke *si) {
12 void cht_scriptinv_cancel(ScriptToInvoke *si) {
13 if (si->script) { Tcl_DecrRefCount(si->script); si->script= 0; }
14 if (si->xargs) { Tcl_DecrRefCount(si->xargs); si->xargs= 0; }
18 int cht_scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip,
19 Tcl_Obj *newscript, Tcl_Obj *xargs) {
22 cht_scriptinv_cancel(si);
23 if (!newscript) return 0;
25 rc= Tcl_ListObjLength(ip, newscript, &si->llen); if (rc) return rc;
26 Tcl_IncrRefCount(newscript);
29 rc= Tcl_ListObjLength(ip, xargs, &xlength); if (rc) return rc;
30 Tcl_IncrRefCount(xargs);
34 si->script= newscript;
40 int cht_scriptinv_invoke_fg(ScriptToInvoke *si, int argc,
41 Tcl_Obj *const *argv) {
45 if (!si->ipq) return TCL_OK;
47 for (i=0; i<argc; i++) Tcl_IncrRefCount(argv[i]);
49 invoke= Tcl_DuplicateObj(si->script);
50 Tcl_IncrRefCount(invoke);
53 rc= Tcl_ListObjAppendList(si->ipq, invoke, si->xargs);
57 rc= Tcl_ListObjReplace(si->ipq, invoke,si->llen,0, argc,argv);
60 rc= Tcl_EvalObjEx(si->ipq, invoke, TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT);
66 for (i=0; i<argc; i++) Tcl_DecrRefCount(argv[i]);
67 if (invoke) Tcl_DecrRefCount(invoke);
71 void cht_scriptinv_invoke(ScriptToInvoke *si, int argc, Tcl_Obj *const *argv) {
73 rc= cht_scriptinv_invoke_fg(si, argc, argv);
74 if (rc) Tcl_BackgroundError(si->ipq);