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 UAA06332 for ; Wed, 25 Sep 1996 20:14:49 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id GAA12781; Wed, 25 Sep 1996 06:00:08 -0400 (EDT) Resent-Date: Wed, 25 Sep 1996 06:00:08 -0400 (EDT) Message-Id: <199609250959.LAA14778@sgi.ifh.de> X-Authentication-Warning: sgi.ifh.de: Host pws@localhost didn't use HELO protocol To: zsh-workers@math.gatech.edu (Zsh hackers list) Subject: Re: argzero while sourcing standard scripts In-reply-to: "Zoltan Hidvegi"'s message of "Tue, 24 Sep 1996 21:42:02 MET." <199609241942.VAA09915@bolyai.cs.elte.hu> Date: Wed, 25 Sep 1996 11:59:57 +0200 From: Peter Stephenson Resent-Message-ID: <"g43EO.0.d73.dAGIo"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2170 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Zoltan Hidvegi wrote: > Peter Stephenson wrote: > > 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. > > It is certainly wrong that the filename isn't mentioned in the error > message but setting argzero it probably the wrong solution for that. Here's another solution in which source() sets a new global variable, scriptname, whenever it is called and restores it at the end. scriptname is used by zerr() and zerrnam() (which I missed last time) if scriptname is set and the SHINSTDIN option isn't, which it won't be if source() was called. It has the feature that the error message contains the path under which the script was found (i.e. a full path unless relative to the current directory) for any sourced script even though $0 is the same as what it always has been. Nothing else should have changed. *** Src/globals.h.scrnam Wed Sep 25 10:56:30 1996 --- Src/globals.h Wed Sep 25 10:58:32 1996 *************** *** 345,350 **** --- 345,351 ---- EXTERN char *argzero; /* $0 */ EXTERN char *hackzero; + EXTERN char *scriptname; /* name of script being sourced */ EXTERN long lineno; /* $LINENO */ EXTERN long shlvl; /* $SHLVL */ *** Src/init.c.scrnam Wed Sep 25 11:09:29 1996 --- Src/init.c Wed Sep 25 11:14:27 1996 *************** *** 767,772 **** --- 767,773 ---- int tempfd, fd, cj, oldlineno; int oldshst, osubsh, oloops; FILE *obshin; + char *old_scriptname = scriptname; if (!s || (tempfd = movefd(open(unmeta(s), O_RDONLY))) == -1) { return 1; *************** *** 787,792 **** --- 788,794 ---- lineno = 0; loops = 0; dosetopt(SHINSTDIN, 0, 1); + scriptname = s; sourcelevel++; loop(0); /* loop through the file to be sourced */ *************** *** 804,809 **** --- 806,813 ---- dosetopt(SHINSTDIN, oldshst, 1); /* SHINSTDIN option */ errflag = 0; retflag = 0; + scriptname = old_scriptname; + return 0; } *** Src/utils.c.scrnam Wed Sep 25 10:59:43 1996 --- Src/utils.c Wed Sep 25 11:38:28 1996 *************** *** 52,58 **** return; errflag = 1; trashzle(); ! nicezputs(isset(SHINSTDIN) ? "zsh" : argzero, stderr); fputs(": ", stderr); zerrnam(NULL, fmt, str, num); } --- 52,64 ---- return; errflag = 1; trashzle(); ! /* ! * scriptname is set when sourcing scripts, so that we get the ! * correct name instead of the generic name of whatever ! * program/script is running. ! */ ! nicezputs(isset(SHINSTDIN) ? "zsh" : ! scriptname ? scriptname : argzero, stderr); fputs(": ", stderr); zerrnam(NULL, fmt, str, num); } *************** *** 67,73 **** errflag = 1; trashzle(); if(unset(SHINSTDIN)) { ! nicezputs(argzero, stderr); fputs(": ", stderr); } nicezputs(cmd, stderr); --- 73,79 ---- errflag = 1; trashzle(); if(unset(SHINSTDIN)) { ! nicezputs(scriptname ? scriptname : argzero, stderr); fputs(": ", stderr); } nicezputs(cmd, stderr); -- 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.