about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGreg Klanderman <gak@klanderman.net>2016-03-06 09:53:40 -0800
committerBarton E. Schaefer <schaefer@zsh.org>2016-03-06 09:53:40 -0800
commit440c6beec09b3b4ba68955d807d48acef0d4360a (patch)
tree302abbf15741bfe6e407522cd584fb45786a9823
parent77e55b1ea315776130822df92f04ba2ca999ca01 (diff)
downloadzsh-440c6beec09b3b4ba68955d807d48acef0d4360a.tar.gz
zsh-440c6beec09b3b4ba68955d807d48acef0d4360a.tar.xz
zsh-440c6beec09b3b4ba68955d807d48acef0d4360a.zip
38086: shuffle init code to localize a global, add $ZSH_ARGZERO, refine $ZSH_SCRIPT
(also a couple of ChangeLog typos corrected -- Bart)
-rw-r--r--ChangeLog10
-rw-r--r--Doc/Zsh/params.yo19
-rw-r--r--Src/init.c13
-rw-r--r--Src/params.c6
4 files changed, 30 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 28ac59bd9..734d685fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-03-06  Barton E. Schaefer  <schaefer@zsh.org>
+
+	* Greg Klanderman: 38086: Doc/Zsh/params.yo, Src/init.c,
+	Src/params.c: shuffle init code to localize a global, add
+	$ZSH_ARGZERO, refine $ZSH_SCRIPT
+
 2016-03-04  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 38084: Baruch Siach: configure.ac: use the pcre-config we
@@ -124,7 +130,7 @@
 2016-02-07  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* 37895: Src/params.c, Doc/Zsh/parmas.yo: add ZSH_SCRIPT as
-	always available form of POISX $0.
+	always available form of POSIX $0.
 
 2016-02-07  Dominik Ritter  <dritter03@googlemail.com>
 
@@ -5516,7 +5522,7 @@
 
 2014-08-01  Peter Stephenson  <p.stephenson@samsung.com>
 
-	* 32932: Src/glob.c, Src/utils.c: add hmkarray() and
+	* 32932: Src/subst.c, Src/utils.c: add hmkarray() and
 	use to fix leak.
 
 2014-07-31  Barton E. Schaefer  <schaefer@zsh.org>
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index ae859ce6c..d23c459a0 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -933,6 +933,13 @@ tt(zsh/zutil) module.
 )
 enditem()
 )
+vindex(ZSH_ARGZERO)
+item(tt(ZSH_ARGZERO))(
+If zsh was invoked to run a script, this is the name of the script.
+Otherwise, it is the name used to invoke the current shell.  This is
+the same as the value of tt($0) when the tt(POSIX_ARGZERO) option is
+set, but is always available.
+)
 vindex(ZSH_EXECUTION_STRING)
 item(tt(ZSH_EXECUTION_STRING))(
 If the shell was started with the option tt(-c), this contains
@@ -951,17 +958,15 @@ track of versions of the shell during development between releases;
 hence most users should not use it and should instead rely on
 tt($ZSH_VERSION).
 )
-vindex(ZSH_SCRIPT)
-item(tt(ZSH_SCRIPT))(
-If zsh was invoked to run a script, this is the name of the script.
-Otherwise, it is the name used to invoke the current shell.  This is
-the same as the value of tt($0) when the tt(POSIX_ARGZERO) option is
-set, but is always available.
-)
 item(tt(zsh_scheduled_events))(
 See ifzman(the section `The zsh/sched Module' in zmanref(zshmodules))\
 ifnzman(noderef(The zsh/sched Module)).
 )
+vindex(ZSH_SCRIPT)
+item(tt(ZSH_SCRIPT))(
+If zsh was invoked to run a script, this is the name of the script,
+otherwise it is unset.
+)
 vindex(ZSH_SUBSHELL <S>)
 item(tt(ZSH_SUBSHELL))(
 Readonly integer.  Initially zero, incremented each time the shell forks
diff --git a/Src/init.c b/Src/init.c
index 4097327ee..20a07eb0a 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -802,7 +802,7 @@ init_term(void)
 
 /**/
 void
-setupvals(char *cmd)
+setupvals(char *cmd, char *runscript, char *zsh_name)
 {
 #ifdef USE_GETPWUID
     struct passwd *pswd;
@@ -1089,6 +1089,9 @@ setupvals(char *cmd)
 
     if (cmd)
 	setsparam("ZSH_EXECUTION_STRING", ztrdup(cmd));
+    if (runscript)
+        setsparam("ZSH_SCRIPT", ztrdup(runscript));
+    setsparam("ZSH_NAME", ztrdup(zsh_name)); /* NOTE: already metafied early in zsh_main() */
 }
 
 /*
@@ -1270,7 +1273,7 @@ run_init_scripts(void)
 
 /**/
 void
-init_misc(char *cmd)
+init_misc(char *cmd, char *zsh_name)
 {
 #ifndef RESTRICTED_R
     if ( restricted )
@@ -1606,7 +1609,7 @@ mod_export int use_exit_printed;
 mod_export int
 zsh_main(UNUSED(int argc), char **argv)
 {
-    char **t, *runscript = NULL;
+    char **t, *runscript = NULL, *zsh_name;
     char *cmd;			/* argument to -c */
     int t0;
 #ifdef USE_LOCALE
@@ -1660,14 +1663,14 @@ zsh_main(UNUSED(int argc), char **argv)
 
     SHTTY = -1;
     init_io(cmd);
-    setupvals(cmd);
+    setupvals(cmd, runscript, zsh_name);
 
     init_signals();
     init_bltinmods();
     init_builtins();
     run_init_scripts();
     setupshin(runscript);
-    init_misc(cmd);
+    init_misc(cmd, zsh_name);
 
     for (;;) {
 	/*
diff --git a/Src/params.c b/Src/params.c
index 7c5f79fff..c6172e018 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -80,8 +80,7 @@ char *argzero,		/* $0           */
      *rprompt,		/* $RPROMPT     */
      *rprompt2,		/* $RPROMPT2    */
      *sprompt,		/* $SPROMPT     */
-     *wordchars,	/* $WORDCHARS   */
-     *zsh_name;		/* $ZSH_NAME    */
+     *wordchars;	/* $WORDCHARS   */
 /**/
 mod_export
 char *ifs,		/* $IFS         */
@@ -812,8 +811,7 @@ createparamtable(void)
     setsparam("OSTYPE", ztrdup_metafy(OSTYPE));
     setsparam("TTY", ztrdup_metafy(ttystrname));
     setsparam("VENDOR", ztrdup_metafy(VENDOR));
-    setsparam("ZSH_NAME", ztrdup_metafy(zsh_name));
-    setsparam("ZSH_SCRIPT", ztrdup(posixzero));
+    setsparam("ZSH_ARGZERO", ztrdup(posixzero));
     setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION));
     setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL));
     setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));