From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4008 invoked by alias); 3 Dec 2015 14:24:05 -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: 37287 Received: (qmail 28509 invoked from network); 3 Dec 2015 14:24:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f79b16d000005389-3b-5660507fc754 Date: Thu, 03 Dec 2015 14:23:55 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: a way to get the value of the -c option Message-id: <20151203142355.31af16ce@pwslap01u.europe.root.pri> In-reply-to: <20151203140118.5ca77f8c@pwslap01u.europe.root.pri> References: <20151203115449.GA19846@zira.vinc17.org> <20151203124554.3b93281f@pwslap01u.europe.root.pri> <20151203133626.GA29715@zira.vinc17.org> <20151203140118.5ca77f8c@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrELMWRmVeSWpSXmKPExsVy+t/xq7r1AQlhBm+f6FocbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujJnHDjAW9MlWPFm2iKmBcZFYFyMnh4SAicSPFwdZIGwxiQv3 1rN1MXJxCAksZZR4O/MjI4Qzg0ni8of5UJnTjBLvt0+HypxhlNh8/B4zSD+LgKrE7fb1YDab gKHE1E2zGUFsEQFxibNrz4PtEAbad7llKxOIzStgL7H80192EJtTwEGiqfMGE9yG9W9fgw3i F9CXuPr3ExPEgfYSM6+cYYRoFpT4Mfke2FBmAS2JzduaWCFseYnNa96C9QoJqEvcuLubfQKj 8CwkLbOQtMxC0rKAkXkVo2hqaXJBcVJ6rpFecWJucWleul5yfu4mRkhIf93BuPSY1SFGAQ5G JR5eAc/4MCHWxLLiytxDjBIczEoivFFuCWFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeWfueh8i JJCeWJKanZpakFoEk2Xi4JRqYNxm6rP+ynPW5IjZQg+7dp7aUMv9tbxobWevyI+KnRWZp+co fLxydd2qyQYZ3J8e/Lm1cIfewrzpl5X/cX8q3Cb76q27sYp0voK84D7F80nXnS9vymxOjYjt UFkdECWiszdxdwj7tL1lbi8v9h35Nlfbu8CfnX/fpBX/uxpbc95LqeQqmd0/pKvEUpyRaKjF XFScCAA+e0nNZQIAAA== ...and how about getting rid of that unsightly static "cmd" at the same time? I'm wondering about that "restricted", too (defined just below). It's only there as a flag between option parsing and init_misc() where the option is actually set. This raises the question of what should we do when when parseopts is called from emulate and any "restricted" setting currently disappears into the ether. That can't be right, can it? Do we honour it, or we do we print an error? pws diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 21bb874..8ef5485 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -933,6 +933,11 @@ tt(zsh/zutil) module. ) enditem() ) +vindex(ZSH_CMD_ARG) +item(tt(ZSH_CMD_ARG))( +If the shell was started with the option tt(-c), this contains +the argument passed to the option. Otherwise it is not set. +) vindex(ZSH_NAME) item(tt(ZSH_NAME))( Expands to the basename of the command used to invoke this instance diff --git a/Src/init.c b/Src/init.c index dcce1d7..65b7777 100644 --- a/Src/init.c +++ b/Src/init.c @@ -240,13 +240,11 @@ loop(int toplevel, int justonce) return LOOP_OK; } -/* Shared among parseargs(), parseopts(), init_io(), and init_misc() */ -static char *cmd; static int restricted; /**/ static void -parseargs(char **argv, char **runscript) +parseargs(char **argv, char **runscript, char **cmdptr) { char **x; LinkList paramlist; @@ -272,7 +270,7 @@ parseargs(char **argv, char **runscript) opts[SHINSTDIN] = 0; opts[SINGLECOMMAND] = 0; - if (parseopts(NULL, &argv, opts, &cmd, NULL)) + if (parseopts(NULL, &argv, opts, cmdptr, NULL)) exit(1); /* @@ -290,7 +288,7 @@ parseargs(char **argv, char **runscript) if (*argv) { if (unset(SHINSTDIN)) { posixzero = *argv; - if (cmd) + if (*cmdptr) argzero = *argv; else *runscript = *argv; @@ -299,7 +297,7 @@ parseargs(char **argv, char **runscript) } while (*argv) zaddlinknode(paramlist, ztrdup(*argv++)); - } else if (!cmd) + } else if (!*cmdptr) opts[SHINSTDIN] = 1; if(isset(SINGLECOMMAND)) opts[INTERACTIVE] &= 1; @@ -497,7 +495,7 @@ printhelp(void) /**/ mod_export void -init_io(void) +init_io(char *cmd) { static char outbuf[BUFSIZ], errbuf[BUFSIZ]; @@ -802,7 +800,7 @@ init_term(void) /**/ void -setupvals(void) +setupvals(char *cmd) { #ifdef USE_GETPWUID struct passwd *pswd; @@ -1086,6 +1084,9 @@ setupvals(void) /* Colour sequences for outputting colours in prompts and zle */ set_default_colour_sequences(); + + if (cmd) + setsparam("ZSH_CMD_ARG", ztrdup(cmd)); } /* @@ -1267,7 +1268,7 @@ run_init_scripts(void) /**/ void -init_misc(void) +init_misc(char *cmd) { #ifndef RESTRICTED_R if ( restricted ) @@ -1604,6 +1605,7 @@ mod_export int zsh_main(UNUSED(int argc), char **argv) { char **t, *runscript = NULL; + char *cmd; /* argument to -c */ int t0; #ifdef USE_LOCALE setlocale(LC_ALL, ""); @@ -1652,18 +1654,18 @@ zsh_main(UNUSED(int argc), char **argv) opts[LOGINSHELL] = (**argv == '-'); opts[PRIVILEGED] = (getuid() != geteuid() || getgid() != getegid()); /* sets ZLE, INTERACTIVE, SHINSTDIN and SINGLECOMMAND */ - parseargs(argv, &runscript); + parseargs(argv, &runscript, &cmd); SHTTY = -1; - init_io(); - setupvals(); + init_io(cmd); + setupvals(cmd); init_signals(); init_bltinmods(); init_builtins(); run_init_scripts(); setupshin(runscript); - init_misc(); + init_misc(cmd); for (;;) { /*