From owner-svn-src-all@freebsd.org Thu Sep 14 05:48:24 2017 Return-Path: Delivered-To: svn-src-all@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 6F753E013CD; Thu, 14 Sep 2017 05:48:24 +0000 (UTC) (envelope-from imp@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 4962265A76; Thu, 14 Sep 2017 05:48:24 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8E5mNtG033625; Thu, 14 Sep 2017 05:48:23 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8E5mNIf033623; Thu, 14 Sep 2017 05:48:23 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201709140548.v8E5mNIf033623@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 14 Sep 2017 05:48:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323577 - in head: contrib/one-true-awk usr.bin/awk X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head: contrib/one-true-awk usr.bin/awk X-SVN-Commit-Revision: 323577 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Sep 2017 05:48:24 -0000 Author: imp Date: Thu Sep 14 05:48:23 2017 New Revision: 323577 URL: https://svnweb.freebsd.org/changeset/base/323577 Log: Implement gawk multiple-arg extension to and, or, and xor. gawk allows multiple arguemnts to bit-wiste and, or and xor functions. Implement an arbitrary number of arguments for these functions. Also, use NULL in preference to 0 to match rest of file. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D12361 Modified: head/contrib/one-true-awk/run.c head/usr.bin/awk/awk.1 Modified: head/contrib/one-true-awk/run.c ============================================================================== --- head/contrib/one-true-awk/run.c Thu Sep 14 05:47:55 2017 (r323576) +++ head/contrib/one-true-awk/run.c Thu Sep 14 05:48:23 2017 (r323577) @@ -1476,7 +1476,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0 { Cell *x, *y; Awkfloat u; - int t; + int t, i; Awkfloat tmp; char *p, *buf; Node *nextarg; @@ -1520,40 +1520,52 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0 u = ~((int)getfval(x)); break; case FAND: - if (nextarg == 0) { + if (nextarg == NULL) { WARNING("and requires two arguments; returning 0"); u = 0; break; } - y = execute(a[1]->nnext); - u = ((int)getfval(x)) & ((int)getfval(y)); - tempfree(y); - nextarg = nextarg->nnext; + i = ((int)getfval(x)); + while (nextarg != NULL) { + y = execute(nextarg); + i &= (int)getfval(y); + tempfree(y); + nextarg = nextarg->nnext; + } + u = i; break; case FFOR: - if (nextarg == 0) { + if (nextarg == NULL) { WARNING("or requires two arguments; returning 0"); u = 0; break; } - y = execute(a[1]->nnext); - u = ((int)getfval(x)) | ((int)getfval(y)); - tempfree(y); - nextarg = nextarg->nnext; + i = ((int)getfval(x)); + while (nextarg != NULL) { + y = execute(nextarg); + i |= (int)getfval(y); + tempfree(y); + nextarg = nextarg->nnext; + } + u = i; break; case FXOR: - if (nextarg == 0) { + if (nextarg == NULL) { WARNING("xor requires two arguments; returning 0"); u = 0; break; } - y = execute(a[1]->nnext); - u = ((int)getfval(x)) ^ ((int)getfval(y)); - tempfree(y); - nextarg = nextarg->nnext; + i = ((int)getfval(x)); + while (nextarg != NULL) { + y = execute(nextarg); + i ^= (int)getfval(y); + tempfree(y); + nextarg = nextarg->nnext; + } + u = i; break; case FLSHIFT: - if (nextarg == 0) { + if (nextarg == NULL) { WARNING("lshift requires two arguments; returning 0"); u = 0; break; @@ -1564,7 +1576,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0 nextarg = nextarg->nnext; break; case FRSHIFT: - if (nextarg == 0) { + if (nextarg == NULL) { WARNING("rshift requires two arguments; returning 0"); u = 0; break; Modified: head/usr.bin/awk/awk.1 ============================================================================== --- head/usr.bin/awk/awk.1 Thu Sep 14 05:47:55 2017 (r323576) +++ head/usr.bin/awk/awk.1 Thu Sep 14 05:48:23 2017 (r323577) @@ -690,12 +690,15 @@ and returns its exit status. .Bl -tag -width "lshift(a, b)" .It Fn compl x Returns the bitwise complement of integer argument x. -.It Fn and x y -Performs a bitwise AND on integer arguments x and y. -.It Fn or x y -Performs a bitwise OR on integer arguments x and y. -.It Fn xor x y -Performs a bitwise Exclusive-OR on integer arguments x and y. +.It Fn and v1 v2 ... +Performs a bitwise AND on all arguments provided, as integers. +There must be at least two values. +.It Fn or v1 v2 ... +Performs a bitwise OR on all arguments provided, as integers. +There must be at least two values. +.It Fn xor v1 v2 ... +Performs a bitwise Exclusive-OR on all arguments provided, as integers. +There must be at least two values. .It Fn lshift x n Returns integer argument x shifted by n bits to the left. .It Fn rshift x n