From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24120 invoked by alias); 3 Mar 2016 19:37:10 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 38080 Received: (qmail 18989 invoked from network); 3 Mar 2016 19:37:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:subject:reply-to:in-reply-to:references:mime-version:content-type; s=smtpapi; bh=Vr9/8FR+iq8GY4g8hL2d3IEuFZI=; b=YlmeDPNBsPoyAwmjPT aN9vdaUj7sV5VAQ0ywh8Ky4Ewn9W+FM4+D5JNyhhaBymdYHx5R30P56UAi9xf/OW 7UiJJhERa+KPY4n6eFqLb8nXNMScWnPQfDKO3N23KF2fTlYh4ZzJxheUlPzq9yjy WDVoaq7VtbE3Zg2sFaR4epTcw= From: Greg Klanderman To: zsh-workers@zsh.org Subject: Re: ZSH_SCRIPT Reply-To: Greg Klanderman Date: Thu, 03 Mar 2016 14:36:52 -0500 In-Reply-To: <20160303173730.45a8c8ee@pwslap01u.europe.root.pri> (Peter Stephenson's message of "Thu, 03 Mar 2016 17:37:30 +0000") Message-ID: <87bn6vl5ez.fsf@lwm.klanderman.net> User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) References: <22221.59800.803540.618862@lwm.klanderman.net> <160224143153.ZM28994@torch.brasslantern.com> <20160225093344.0d2499d5@pwslap01u.europe.root.pri> <87r3g08ycp.fsf@lwm.klanderman.net> <160225150425.ZM14095@torch.brasslantern.com> <87lh6384y5.fsf@lwm.klanderman.net> <20160301092746.1472ae95@pwslap01u.europe.root.pri> <87fuwa8dpk.fsf@lwm.klanderman.net> <20160301150707.2ee18f01@pwslap01u.europe.root.pri> <56D74063.6020202@inlv.org> <871t7s7ev6.fsf@lwm.klanderman.net> <20160303093702.7d28f80e@pwslap01u.europe.root.pri> <87mvqflbgh.fsf@lwm.klanderman.net> <20160303173730.45a8c8ee@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SG-EID: i+zOheVB0lMUqP0z3X/8PPLe+C1hDfxH7g5ommK/LCr754z6crs2yl/DvbZZJkkZ4bTY8qrJQe5BSC kOnE1uTciDiiJBqHfZR1KSwoEjZBHpwFkK4UvPpMclc6kzxTYMtklNnmWn1nceCwF/VoHHV20sko5U 2jhg/yL86Jt4SiePLkn6N0I8AACWmfmoJGoFUT3CDGgbOxOLVASU3O/bScUI3EofegVi0oNSJuXe3t c= >>>>> On March 3, 2016 Peter Stephenson wrote: > I think it needs the second, because what you pass to a parameter needs > to be uniquely managed by that parameter, so it can't point to memory > that can be referenced another way. I doubt it needs the first as well. > Actually, I don't see why you need a glboal for zsh_script at all. It's > just there to pass runscript on so it can be set later. That's better > done by passing arguments rather than globals. OK how do you like this? Greg diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index ae859ce..d23c459 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 ) 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 4097327..87e7430 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) { #ifdef USE_GETPWUID struct passwd *pswd; @@ -1042,7 +1042,7 @@ setupvals(char *cmd) createshfunctable(); /* create hash table for shell functions */ createbuiltintable(); /* create hash table for builtin commands */ createnameddirtable(); /* create hash table for named directories */ - createparamtable(); /* create parameter hash table */ + createparamtable(runscript); /* create parameter hash table */ condtab = NULL; wrappers = NULL; @@ -1660,7 +1660,7 @@ zsh_main(UNUSED(int argc), char **argv) SHTTY = -1; init_io(cmd); - setupvals(cmd); + setupvals(cmd, runscript); init_signals(); init_bltinmods(); diff --git a/Src/params.c b/Src/params.c index 8bd8a8e..ecd5bfb 100644 --- a/Src/params.c +++ b/Src/params.c @@ -667,7 +667,7 @@ split_env_string(char *env, char **name, char **value) /**/ void -createparamtable(void) +createparamtable(char *runscript) { Param ip, pm; #if !defined(HAVE_PUTENV) && !defined(USE_SET_UNSET_ENV) @@ -812,8 +812,10 @@ 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_NAME", ztrdup(zsh_name)); /* NOTE: command line arguments are metafied early in zsh_main() */ + setsparam("ZSH_ARGZERO", ztrdup(posixzero)); + if (runscript) + setsparam("ZSH_SCRIPT", ztrdup(runscript)); setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION)); setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL)); setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));