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: Mon, 16 Sep 1996 13:45:25 +0200	[thread overview]
Message-ID: <199609161145.NAA19060@hydra.ifh.de> (raw)
In-Reply-To: "Peter Stephenson"'s message of "Mon, 16 Sep 1996 12:09:10 MET." <199609161009.MAA19596@hydra.ifh.de>

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@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 12:05 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 [this message]
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=199609161145.NAA19060@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).