From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.5/8.7.3) with ESMTP id UAA07549 for ; Mon, 16 Sep 1996 20:25:45 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id GAA12562; Mon, 16 Sep 1996 06:11:06 -0400 (EDT) Resent-Date: Mon, 16 Sep 1996 06:11:06 -0400 (EDT) Message-Id: <199609161009.MAA19596@hydra.ifh.de> X-Authentication-Warning: hydra.ifh.de: Host pws@localhost didn't use HELO protocol To: zsh-workers@math.gatech.edu (Zsh hackers list) Subject: argzero while sourcing standard scripts Date: Mon, 16 Sep 1996 12:09:10 +0200 From: Peter Stephenson Resent-Message-ID: <"rMwPo3.0.943.vUIFo"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2142 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Zsh doesn't set argzero (i.e. $0) while sourcing standard scripts, although it does when sourcing anything else so long as FUNCTIONARGZERO is set (which it is by default for native emulation and I can't think of a good reason for turning it off for a `real' zsh). This means the error messages from standard scripts are rather unhelpful in that you don't get the name of the script with the error. By moving the FUNCTIONARGZERO handling for source/dot down into the lower level source() function this can be rectified. A consequent change is that $0 is the full name of the script found, so `. foo' will set $0 to the full path to foo unless foo was found in the current directory. Maybe this is not what is wanted in this case. Since it is what is wanted when a full path is given to . or source, or in any case with the standard scripts, putting this back the way it was would require passing more information to source(). I am happy to do this if the older behaviour is preferable. With ksh there would be the argument that 'ksh foo', which searches the path for foo, leaves $0 as foo even if it's in another directory, but zsh doesn't search the path in that case anyway. *** Src/builtin.c.source Mon Sep 16 11:33:26 1996 --- Src/builtin.c Mon Sep 16 11:37:58 1996 *************** *** 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 ---- *************** *** 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 11:49:33 1996 *************** *** 767,772 **** --- 767,773 ---- 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 = s; /* pretend shell is called 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; -- Peter Stephenson 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.