From owner-svn-src-head@freebsd.org Tue Jan 19 22:41:28 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F3E1AA871BA; Tue, 19 Jan 2016 22:41:27 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B36171299; Tue, 19 Jan 2016 22:41:27 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0JMfQvw064337; Tue, 19 Jan 2016 22:41:26 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0JMfQK4064335; Tue, 19 Jan 2016 22:41:26 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201601192241.u0JMfQK4064335@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Tue, 19 Jan 2016 22:41:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294348 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2016 22:41:28 -0000 Author: jilles Date: Tue Jan 19 22:41:26 2016 New Revision: 294348 URL: https://svnweb.freebsd.org/changeset/base/294348 Log: sh: Simplify some code related to positional parameters. Modified: head/bin/sh/options.c head/bin/sh/options.h Modified: head/bin/sh/options.c ============================================================================== --- head/bin/sh/options.c Tue Jan 19 22:07:39 2016 (r294347) +++ head/bin/sh/options.c Tue Jan 19 22:41:26 2016 (r294348) @@ -74,6 +74,7 @@ static void options(int); static void minus_o(char *, int); static void setoption(int, int); static void setoptionbyindex(int, int); +static void setparam(int, char **); static int getopts(char *, char *, char **, char ***, char **); @@ -224,7 +225,7 @@ end_options1: end_options2: if (!cmdline) { if (*argptr == NULL) - setparam(argptr); + setparam(0, argptr); return; } @@ -318,22 +319,20 @@ setoption(int flag, int val) * Set the shell parameters. */ -void -setparam(char **argv) +static void +setparam(int argc, char **argv) { char **newparam; char **ap; - int nparam; - for (nparam = 0 ; argv[nparam] ; nparam++); - ap = newparam = ckmalloc((nparam + 1) * sizeof *ap); + ap = newparam = ckmalloc((argc + 1) * sizeof *ap); while (*argv) { *ap++ = savestr(*argv++); } *ap = NULL; freeparam(&shellparam); shellparam.malloc = 1; - shellparam.nparam = nparam; + shellparam.nparam = argc; shellparam.p = newparam; shellparam.optp = NULL; shellparam.reset = 1; @@ -371,8 +370,7 @@ freeparam(struct shparam *param) int shiftcmd(int argc, char **argv) { - int n; - char **ap1, **ap2; + int i, n; n = 1; if (argc > 1) @@ -381,12 +379,11 @@ shiftcmd(int argc, char **argv) return 1; INTOFF; shellparam.nparam -= n; - for (ap1 = shellparam.p ; --n >= 0 ; ap1++) { - if (shellparam.malloc) - ckfree(*ap1); - } - ap2 = shellparam.p; - while ((*ap2++ = *ap1++) != NULL); + if (shellparam.malloc) + for (i = 0; i < n; i++) + ckfree(shellparam.p[i]); + memmove(shellparam.p, shellparam.p + n, + (shellparam.nparam + 1) * sizeof(shellparam.p[0])); shellparam.reset = 1; INTON; return 0; @@ -407,7 +404,7 @@ setcmd(int argc, char **argv) options(0); optschanged(); if (*argptr != NULL) { - setparam(argptr); + setparam(argc - (argptr - argv), argptr); } INTON; return 0; Modified: head/bin/sh/options.h ============================================================================== --- head/bin/sh/options.h Tue Jan 19 22:07:39 2016 (r294347) +++ head/bin/sh/options.h Tue Jan 19 22:41:26 2016 (r294348) @@ -108,7 +108,6 @@ extern char *nextopt_optptr; /* used by void procargs(int, char **); void optschanged(void); -void setparam(char **); void freeparam(struct shparam *); int nextopt(const char *); void getoptsreset(const char *);