Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Bugfix in $0 saving
- X-seq: zsh-workers 1669
- From: Zefram <A.Main@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Z Shell workers mailing list)
- Subject: Bugfix in $0 saving
- Date: Tue, 16 Jul 1996 20:43:08 +0100 (BST)
-----BEGIN PGP SIGNED MESSAGE-----
There is a problem with the conditional saving of $0 around functions
and sourcing, which was introduced a few betas ago. Try the following:
emulate zsh
ek () { emulate ksh }
ek
echo $0
There's a problem going in the other direction too. The cause of this
behaviour is that emulation is checked before and after the function
is executed, without regard for the fact that it might have changed in
the meantime.
There is also, in my opinion, a philosophical bug in the code. It checks
the emulation mode directly, but (a) it's not currently possible to
directly query the current setting, and (b) more importantly, aspects of
behaviour such as this should be settable independently -- ksh/sh/POSIX
etc. emulation should not be an all-or-nothing choice. Before the
"emulation" variable was added, compatibility behaviour was always
added by the use of separate options, and I think that was a Good Thing.
(Maybe those EMULATE_*SH constants make it too easy, eh?)
The patch below fixes both of these problems. It adds an option,
FUNCTION_ARGZERO, which is set by default unless we are emulating ksh
or sh, and $0 is changed depending on this option. Then $0 is restored
iff it was changed.
I made this patch using my working copy of zsh that has my option patch
from article 1275 applied. If you're not using that patch, then the
context for a couple of the hunks will be wrong, so you'll need to apply
them by hand. You'll also need to use "OPT_CSH|OPT_ZSH" instead of
"OPT_NONBOURNE" in the globals.h hunk.
On a completely different issue, why aren't the info files included in
the distribution any more? Not everyone has makeinfo.
-zefram
Index: Doc/zshoptions.man
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Doc/zshoptions.man,v
retrieving revision 1.10
diff -c -r1.10 zshoptions.man
*** zshoptions.man 1996/07/16 14:26:42 1.10
--- zshoptions.man 1996/07/16 16:06:04
***************
*** 194,199 ****
--- 194,203 ----
output flow control via start/stop characters (usually assigned to
^S/^Q) is disabled in the shell's editor.
.TP
+ \fBFUNCTION_ARGZERO\fP
+ When executing a shell function or sourcing a script, set $0
+ temporarily to the name of the function/script.
+ .TP
\fBGLOB\fP (+\fBF\fP, ksh: +\fBf\fP)
Perform filename generation.
.TP
Index: Src/builtin.c
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/builtin.c,v
retrieving revision 1.22
diff -c -r1.22 builtin.c
*** builtin.c 1996/07/16 14:26:48 1.22
--- builtin.c 1996/07/16 15:50:19
***************
*** 4599,4605 ****
int
bin_dot(char *name, char **argv, char *ops, int func)
{
! char **old, *old0;
int ret, diddot = 0, dotdot = 0;
char buf[PATH_MAX];
char *s, **t, *enam, *arg0;
--- 4599,4605 ----
int
bin_dot(char *name, char **argv, char *ops, int func)
{
! char **old, *old0 = NULL;
int ret, diddot = 0, dotdot = 0;
char buf[PATH_MAX];
char *s, **t, *enam, *arg0;
***************
*** 4608,4614 ****
if (!*argv)
return 0;
old = pparams;
- old0 = argzero;
/* get arguments for the script */
if (argv[1]) {
PERMALLOC {
--- 4608,4613 ----
***************
*** 4616,4623 ****
} LASTALLOC;
}
enam = arg0 = ztrdup(*argv);
! if (emulation != EMULATE_KSH && emulation != EMULATE_SH)
argzero = arg0;
s = unmeta(enam);
errno = ENOENT;
ret = 1;
--- 4615,4624 ----
} LASTALLOC;
}
enam = arg0 = ztrdup(*argv);
! if (isset(FUNCTIONARGZERO)) {
! old0 = argzero;
argzero = arg0;
+ }
s = unmeta(enam);
errno = ENOENT;
ret = 1;
***************
*** 4667,4673 ****
if (ret)
zwarnnam(name, "%e: %s", enam, errno);
zsfree(arg0);
! if (emulation != EMULATE_KSH && emulation != EMULATE_SH)
argzero = old0;
return ret ? ret : lastval;
}
--- 4668,4674 ----
if (ret)
zwarnnam(name, "%e: %s", enam, errno);
zsfree(arg0);
! if (old0)
argzero = old0;
return ret ? ret : lastval;
}
Index: Src/exec.c
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/exec.c,v
retrieving revision 1.22
diff -c -r1.22 exec.c
*** exec.c 1996/07/16 14:40:42 1.22
--- exec.c 1996/07/16 15:50:26
***************
*** 2416,2422 ****
* was executed. */
{
Param pm;
! char **tab, **x, *oargv0;
int xexittr, oldzoptind, oldlastval;
LinkList olist;
char *s, *ou;
--- 2416,2422 ----
* was executed. */
{
Param pm;
! char **tab, **x, *oargv0 = NULL;
int xexittr, oldzoptind, oldlastval;
LinkList olist;
char *s, *ou;
***************
*** 2431,2437 ****
sigtrapped[SIGEXIT] = 0;
sigfuncs[SIGEXIT] = NULL;
tab = pparams;
- oargv0 = argzero;
oldzoptind = zoptind;
zoptind = 1;
--- 2431,2436 ----
***************
*** 2448,2462 ****
node = doshargs->first;
pparams = x = (char **) zcalloc(((sizeof *x) * (1 + countlinknodes(doshargs))));
! if (emulation != EMULATE_KSH && emulation != EMULATE_SH)
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 (emulation != EMULATE_KSH && emulation != EMULATE_SH)
argzero = ztrdup(argzero);
}
PERMALLOC {
olist = locallist; /* save the old locallist since shell functions may be nested */
--- 2447,2465 ----
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);
+ }
}
PERMALLOC {
olist = locallist; /* save the old locallist since shell functions may be nested */
***************
*** 2481,2487 ****
locallist = olist; /* restore the old list of local variables */
breaks = retflag = 0;
freearray(pparams);
! if (emulation != EMULATE_KSH && emulation != EMULATE_SH) {
zsfree(argzero);
argzero = oargv0;
}
--- 2484,2490 ----
locallist = olist; /* restore the old list of local variables */
breaks = retflag = 0;
freearray(pparams);
! if (oargv0) {
zsfree(argzero);
argzero = oargv0;
}
Index: Src/globals.h
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/globals.h,v
retrieving revision 1.10
diff -c -r1.10 globals.h
*** globals.h 1996/07/16 14:26:52 1.10
--- globals.h 1996/07/16 15:52:45
***************
*** 697,702 ****
--- 697,703 ----
{"extendedglob", 0, 0, 0},
{"extendedhistory", 0, 0, OPT_EMULATE|OPT_CSH},
{"flowcontrol", 0, 0, OPT_ALL},
+ {"functionargzero", 0, 0, OPT_EMULATE|OPT_NONBOURNE},
{"glob", x'F', x'f', OPT_ALL},
{"globassign", 0, 0, OPT_EMULATE|OPT_CSH},
{"globcomplete", 0, 0, 0},
Index: Src/zsh.h
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/zsh.h,v
retrieving revision 1.13
diff -c -r1.13 zsh.h
*** zsh.h 1996/07/16 14:27:08 1.13
--- zsh.h 1996/07/16 15:50:01
***************
*** 1079,1084 ****
--- 1079,1085 ----
EXTENDEDGLOB,
EXTENDEDHISTORY,
FLOWCONTROL,
+ FUNCTIONARGZERO,
GLOBOPT,
GLOBASSIGN,
GLOBCOMPLETE,
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBMevEbXD/+HJTpU/hAQGGagQAheGD479f2GWHgBQpwCZAWwJAJrOj2dmK
+oUNCU9F6JBhw1wi2uWpaYRKf8u4R6Hxfs4c2IcoQFAC4QA9uJH8E4v8zVCVTtPk
VgMp4Pf03Uy2UQP4CATj2bdhrBten0gK/yIplTVIBYD3DO3RzgN0WantZv881ZZt
71WefyfvnVk=
=W3Jz
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author