Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: argzero while sourcing standard scripts
- X-seq: zsh-workers 2143
- From: Peter Stephenson <pws@xxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Zsh hackers list)
- Subject: Re: argzero while sourcing standard scripts
- Date: Mon, 16 Sep 1996 13:45:25 +0200
- In-reply-to: "Peter Stephenson"'s message of "Mon, 16 Sep 1996 12:09:10 MET." <199609161009.MAA19596@xxxxxxxxxxxx>
Here's the alternative version of the patch keeping the old behaviour
where $0 is the argument to . or source rather than the file actually
found. One call to source() gets the original name passed down as
the second argument, the others just get NULL and use the first
argument.
*** Src/builtin.c.source Mon Sep 16 11:33:26 1996
--- Src/builtin.c Mon Sep 16 13:37:18 1996
***************
*** 4666,4672 ****
if (islogin && !subsh) {
sourcehome(".zlogout");
#ifdef GLOBAL_ZLOGOUT
! source(GLOBAL_ZLOGOUT);
#endif
}
}
--- 4666,4672 ----
if (islogin && !subsh) {
sourcehome(".zlogout");
#ifdef GLOBAL_ZLOGOUT
! source(GLOBAL_ZLOGOUT, NULL);
#endif
}
}
***************
*** 4684,4690 ****
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;
--- 4684,4690 ----
int
bin_dot(char *name, char **argv, char *ops, int func)
{
! char **old;
int ret, diddot = 0, dotdot = 0;
char buf[PATH_MAX];
char *s, **t, *enam, *arg0;
***************
*** 4700,4709 ****
} LASTALLOC;
}
enam = arg0 = ztrdup(*argv);
- if (isset(FUNCTIONARGZERO)) {
- old0 = argzero;
- argzero = arg0;
- }
s = unmeta(enam);
errno = ENOENT;
ret = 1;
--- 4700,4705 ----
***************
*** 4711,4717 ****
if (*name != '.' && access(s, F_OK) == 0
&& stat(s, &st) >= 0 && !S_ISDIR(st.st_mode)) {
diddot = 1;
! ret = source(enam);
}
if (ret) {
/* use a path with / in it */
--- 4707,4713 ----
if (*name != '.' && access(s, F_OK) == 0
&& stat(s, &st) >= 0 && !S_ISDIR(st.st_mode)) {
diddot = 1;
! ret = source(enam, NULL);
}
if (ret) {
/* use a path with / in it */
***************
*** 4723,4729 ****
else if (arg0[1] == '.' && arg0 + 2 == s)
++dotdot;
}
! ret = source(arg0);
break;
}
if (!*s || (ret && isset(PATHDIRS) && diddot < 2 && dotdot == 0)) {
--- 4719,4725 ----
else if (arg0[1] == '.' && arg0 + 2 == s)
++dotdot;
}
! ret = source(arg0, NULL);
break;
}
if (!*s || (ret && isset(PATHDIRS) && diddot < 2 && dotdot == 0)) {
***************
*** 4742,4748 ****
s = unmeta(buf);
if (access(s, F_OK) == 0 && stat(s, &st) >= 0
&& !S_ISDIR(st.st_mode)) {
! ret = source(enam = buf);
break;
}
}
--- 4738,4744 ----
s = unmeta(buf);
if (access(s, F_OK) == 0 && stat(s, &st) >= 0
&& !S_ISDIR(st.st_mode)) {
! ret = source(enam = buf, arg0);
break;
}
}
***************
*** 4756,4763 ****
if (ret)
zwarnnam(name, "%e: %s", enam, errno);
zsfree(arg0);
- if (old0)
- argzero = old0;
return ret ? ret : lastval;
}
--- 4752,4757 ----
*** Src/init.c.source Mon Sep 16 11:33:30 1996
--- Src/init.c Mon Sep 16 13:38:17 1996
***************
*** 689,695 ****
if (emulation == EMULATE_KSH || emulation == EMULATE_SH) {
if (islogin)
! source("/etc/profile");
if (unset(PRIVILEGED)) {
char *s = getsparam("ENV");
if (islogin)
--- 689,695 ----
if (emulation == EMULATE_KSH || emulation == EMULATE_SH) {
if (islogin)
! source("/etc/profile", NULL);
if (unset(PRIVILEGED)) {
char *s = getsparam("ENV");
if (islogin)
***************
*** 698,711 ****
if (s && !parsestr(s)) {
singsub(&s);
noerrs = 0;
! source(s);
}
noerrs = 0;
} else
! source("/etc/suid_profile");
} else {
#ifdef GLOBAL_ZSHENV
! source(GLOBAL_ZSHENV);
#endif
if (isset(RCS)) {
if (unset(PRIVILEGED))
--- 698,711 ----
if (s && !parsestr(s)) {
singsub(&s);
noerrs = 0;
! source(s, NULL);
}
noerrs = 0;
} else
! source("/etc/suid_profile", NULL);
} else {
#ifdef GLOBAL_ZSHENV
! source(GLOBAL_ZSHENV, NULL);
#endif
if (isset(RCS)) {
if (unset(PRIVILEGED))
***************
*** 712,718 ****
sourcehome(".zshenv");
if (islogin) {
#ifdef GLOBAL_ZPROFILE
! source(GLOBAL_ZPROFILE);
#endif
if (unset(PRIVILEGED))
sourcehome(".zprofile");
--- 712,718 ----
sourcehome(".zshenv");
if (islogin) {
#ifdef GLOBAL_ZPROFILE
! source(GLOBAL_ZPROFILE, NULL);
#endif
if (unset(PRIVILEGED))
sourcehome(".zprofile");
***************
*** 719,725 ****
}
if (interact) {
#ifdef GLOBAL_ZSHRC
! source(GLOBAL_ZSHRC);
#endif
if (unset(PRIVILEGED))
sourcehome(".zshrc");
--- 719,725 ----
}
if (interact) {
#ifdef GLOBAL_ZSHRC
! source(GLOBAL_ZSHRC, NULL);
#endif
if (unset(PRIVILEGED))
sourcehome(".zshrc");
***************
*** 726,732 ****
}
if (islogin) {
#ifdef GLOBAL_ZLOGIN
! source(GLOBAL_ZLOGIN);
#endif
if (unset(PRIVILEGED))
sourcehome(".zlogin");
--- 726,732 ----
}
if (islogin) {
#ifdef GLOBAL_ZLOGIN
! source(GLOBAL_ZLOGIN, NULL);
#endif
if (unset(PRIVILEGED))
sourcehome(".zlogin");
***************
*** 762,772 ****
/**/
int
! source(char *s)
{
int tempfd, fd, cj, oldlineno;
int oldshst, osubsh, oloops;
FILE *obshin;
if (!s || (tempfd = movefd(open(unmeta(s), O_RDONLY))) == -1) {
return 1;
--- 762,773 ----
/**/
int
! source(char *s, char *arg0)
{
int tempfd, fd, cj, oldlineno;
int oldshst, osubsh, oloops;
FILE *obshin;
+ char *old0 = NULL;
if (!s || (tempfd = movefd(open(unmeta(s), O_RDONLY))) == -1) {
return 1;
***************
*** 780,785 ****
--- 781,790 ----
oldlineno = lineno; /* store our current lineno */
oloops = loops; /* stored the # of nested loops we are in */
oldshst = opts[SHINSTDIN]; /* store current value of this option */
+ if (isset(FUNCTIONARGZERO)) {
+ old0 = argzero; /* store current name shell is running under */
+ argzero = arg0 ? arg0 : s; /* pretend shell is called arg0 or s */
+ }
SHIN = tempfd;
bshin = fdopen(SHIN, "r");
***************
*** 802,807 ****
--- 807,814 ----
lineno = oldlineno; /* our current lineno */
loops = oloops; /* the # of nested loops we are in */
dosetopt(SHINSTDIN, oldshst, 1); /* SHINSTDIN option */
+ if (old0)
+ argzero = old0; /* name under which shell is running */
errflag = 0;
retflag = 0;
return 0;
***************
*** 824,830 ****
return;
}
sprintf(buf, "%s/%s", h, s);
! source(buf);
}
/**/
--- 831,837 ----
return;
}
sprintf(buf, "%s/%s", h, s);
! source(buf, NULL);
}
/**/
--
Peter Stephenson <pws@xxxxxx> Tel: +49 33762 77366
WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author