Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: autoload +X[zk]



Bart Schaefer wrote:

> On Mar 28,  1:52pm, Sven Wischnowsky wrote:
> } Subject: Re: autoload +X[zk]
> }
> } > Note also the handling of the positional parameters. For the first
> } > call (i.e.: when the init code from the file is executed) they are not 
> } > set. Only for the appended function call are they set up. This is the
> } > behaviour the ksh I have here shows.
> } 
> } Damn. That doesn't work, because the printing functions just output
> } `foo "$@"' for the not-really-existing call.
> 
> And the    [[ -o kshautoload ]] || foo "$@"   trick doesn't work if we
> were to really emulate that ksh behavior, either, does it?

But the `foo "$@"' here isn't used when using ksh-style autoloading,
i.e. what's in the positional parameters doesn't matter here.

Anyway...

> } Hm. What are we supposed to do here? Handle positional parameters
> } differently?
> 
> For now, I think the answer is:  Handle positional parameters like zsh
> always has done for kshautoload (as you pointed out in 10298) and fix
> the problem of accurately emulating ksh at a later time.

I had hoped you would say that.

Bye
 Sven

diff -ru ../z.old/Src/exec.c Src/exec.c
--- ../z.old/Src/exec.c	Wed Mar 29 10:36:16 2000
+++ Src/exec.c	Wed Mar 29 10:41:27 2000
@@ -3249,8 +3249,6 @@
 
     pushheap();
 
- rec:
-
     oargv0 = NULL;
     obreaks = breaks;;
     if (trapreturn < 0)
@@ -3275,45 +3273,59 @@
     if (flags & PM_TAGGED)
 	opts[XTRACE] = 1;
     opts[PRINTEXITVALUE] = 0;
-    if (!(prog->flags & EF_RUN)) {
-	if (doshargs) {
-	    LinkNode node;
+    if (doshargs) {
+	LinkNode node;
 
-	    node = doshargs->first;
-	    pparams = x = (char **) zcalloc(((sizeof *x) *
+	node = doshargs->first;
+	pparams = x = (char **) zcalloc(((sizeof *x) *
 					 (1 + countlinknodes(doshargs))));
-	    if (isset(FUNCTIONARGZERO)) {
-		oargv0 = argzero;
-		argzero = ztrdup((char *) node->dat);
-	    }
-	    node = node->next;
-	    for (; node; node = node->next, x++)
-		*x = ztrdup((char *) node->dat);
-	} else {
-	    pparams = (char **) zcalloc(sizeof *pparams);
-	    if (isset(FUNCTIONARGZERO)) {
-		oargv0 = argzero;
-		argzero = ztrdup(argzero);
-	    }
+	if (isset(FUNCTIONARGZERO)) {
+	    oargv0 = argzero;
+	    argzero = ztrdup((char *) node->dat);
+	}
+	node = node->next;
+	for (; node; node = node->next, x++)
+	    *x = ztrdup((char *) node->dat);
+    } else {
+	pparams = (char **) zcalloc(sizeof *pparams);
+	if (isset(FUNCTIONARGZERO)) {
+	    oargv0 = argzero;
+	    argzero = ztrdup(argzero);
 	}
     }
     fstack.name = dupstring(name);
     fstack.prev = funcstack;
     funcstack = &fstack;
-    runshfunc(prog, ((prog->flags & EF_RUN) ? NULL : wrappers), fstack.name);
+
+    if (prog->flags & EF_RUN) {
+	Shfunc shf;
+
+	runshfunc(prog, NULL, fstack.name);
+
+	prog->flags &= ~EF_RUN;
+
+	if (!(shf = (Shfunc) shfunctab->getnode(shfunctab,
+						(name = fname)))) {
+	    zerr("%s: function not defined by file", name, 0);
+	    if (!noreturnval)
+		lastval = 1;
+	    popheap();
+	    return;
+	}
+	prog = shf->funcdef;
+    }
+    runshfunc(prog, wrappers, fstack.name);
     funcstack = fstack.prev;
     if (retflag) {
 	retflag = 0;
 	breaks = obreaks;
     }
-    if (!(prog->flags & EF_RUN)) {
-	freearray(pparams);
-	if (oargv0) {
-	    zsfree(argzero);
-	    argzero = oargv0;
-	}
-	pparams = tab;
+    freearray(pparams);
+    if (oargv0) {
+	zsfree(argzero);
+	argzero = oargv0;
     }
+    pparams = tab;
     optcind = oldoptcind;
     zoptind = oldzoptind;
     scriptname = oldscriptname;
@@ -3336,23 +3348,6 @@
 	trapreturn++;
     if (noreturnval)
 	lastval = oldlastval;
-
-    if (prog->flags & EF_RUN) {
-	Shfunc shf;
-
-	prog->flags &= ~EF_RUN;
-
-	if (!(shf = (Shfunc) shfunctab->getnode(shfunctab,
-						(name = fname)))) {
-	    zerr("%s: function not defined by file", name, 0);
-	    if (!noreturnval)
-		lastval = 1;
-	    popheap();
-	    return;
-	}
-	prog = shf->funcdef;
-	goto rec;
-    }
     popheap();
 }
 

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author