zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: argzero while sourcing standard scripts
Date: Mon, 16 Sep 1996 12:09:10 +0200	[thread overview]
Message-ID: <199609161009.MAA19596@hydra.ifh.de> (raw)

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 <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-16 10:25 UTC|newest]

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

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=199609161009.MAA19596@hydra.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).