From owner-svn-src-head@FreeBSD.ORG Fri Aug 30 20:37:52 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D0B8C8C5; Fri, 30 Aug 2013 20:37:52 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A43272DD8; Fri, 30 Aug 2013 20:37:52 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7UKbqeV096716; Fri, 30 Aug 2013 20:37:52 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r7UKbqgs096715; Fri, 30 Aug 2013 20:37:52 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201308302037.r7UKbqgs096715@svn.freebsd.org> From: Jilles Tjoelker Date: Fri, 30 Aug 2013 20:37:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r255085 - 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.14 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: Fri, 30 Aug 2013 20:37:52 -0000 Author: jilles Date: Fri Aug 30 20:37:52 2013 New Revision: 255085 URL: http://svnweb.freebsd.org/changeset/base/255085 Log: sh: Separate out nbinary allocation into a function. Modified: head/bin/sh/parser.c Modified: head/bin/sh/parser.c ============================================================================== --- head/bin/sh/parser.c Fri Aug 30 20:30:33 2013 (r255084) +++ head/bin/sh/parser.c Fri Aug 30 20:37:52 2013 (r255085) @@ -114,6 +114,7 @@ static union node *pipeline(void); static union node *command(void); static union node *simplecmd(union node **, union node *); static union node *makename(void); +static union node *makebinary(int type, union node *n1, union node *n2); static void parsefname(void); static void parseheredoc(void); static int peektoken(void); @@ -257,17 +258,11 @@ list(int nlflag, int erflag) if (ntop == NULL) ntop = n2; else if (n1 == NULL) { - n1 = (union node *)stalloc(sizeof (struct nbinary)); - n1->type = NSEMI; - n1->nbinary.ch1 = ntop; - n1->nbinary.ch2 = n2; + n1 = makebinary(NSEMI, ntop, n2); ntop = n1; } else { - n3 = (union node *)stalloc(sizeof (struct nbinary)); - n3->type = NSEMI; - n3->nbinary.ch1 = n1->nbinary.ch2; - n3->nbinary.ch2 = n2; + n3 = makebinary(NSEMI, n1->nbinary.ch2, n2); n1->nbinary.ch2 = n3; n1 = n3; } @@ -312,10 +307,10 @@ list(int nlflag, int erflag) static union node * andor(void) { - union node *n1, *n2, *n3; + union node *n; int t; - n1 = pipeline(); + n = pipeline(); for (;;) { if ((t = readtoken()) == TAND) { t = NAND; @@ -323,14 +318,9 @@ andor(void) t = NOR; } else { tokpushback++; - return n1; + return n; } - n2 = pipeline(); - n3 = (union node *)stalloc(sizeof (struct nbinary)); - n3->type = t; - n3->nbinary.ch1 = n1; - n3->nbinary.ch2 = n2; - n1 = n3; + n = makebinary(t, n, pipeline()); } } @@ -437,12 +427,11 @@ command(void) break; case TWHILE: case TUNTIL: - n1 = (union node *)stalloc(sizeof (struct nbinary)); - n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL; - if ((n1->nbinary.ch1 = list(0, 0)) == NULL) + t = lasttoken; + if ((n1 = list(0, 0)) == NULL) synexpect(-1); consumetoken(TDO); - n1->nbinary.ch2 = list(0, 0); + n1 = makebinary((t == TWHILE)? NWHILE : NUNTIL, n1, list(0, 0)); consumetoken(TDONE); checkkwd = CHKKWD | CHKALIAS; break; @@ -682,6 +671,18 @@ makename(void) return n; } +static union node * +makebinary(int type, union node *n1, union node *n2) +{ + union node *n; + + n = (union node *)stalloc(sizeof (struct nbinary)); + n->type = type; + n->nbinary.ch1 = n1; + n->nbinary.ch2 = n2; + return (n); +} + void fixredir(union node *n, const char *text, int err) {