zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: Re: argzero while sourcing standard scripts
Date: Wed, 25 Sep 1996 11:59:57 +0200	[thread overview]
Message-ID: <199609250959.LAA14778@sgi.ifh.de> (raw)
In-Reply-To: "Zoltan Hidvegi"'s message of "Tue, 24 Sep 1996 21:42:02 MET." <199609241942.VAA09915@bolyai.cs.elte.hu>

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 <pws@ifh.de>       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.


      reply	other threads:[~1996-09-25 10:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-16 10:09 Peter Stephenson
1996-09-16 11:45 ` Peter Stephenson
1996-09-24 19:42 ` Zoltan Hidvegi
1996-09-25  9:59   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199609250959.LAA14778@sgi.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).