mirror of
https://git.FreeBSD.org/src.git
synced 2024-10-19 02:29:40 +00:00
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
This commit is contained in:
parent
69679fc10f
commit
73f7ff91b2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=323577
@ -1476,7 +1476,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
|
|||||||
{
|
{
|
||||||
Cell *x, *y;
|
Cell *x, *y;
|
||||||
Awkfloat u;
|
Awkfloat u;
|
||||||
int t;
|
int t, i;
|
||||||
Awkfloat tmp;
|
Awkfloat tmp;
|
||||||
char *p, *buf;
|
char *p, *buf;
|
||||||
Node *nextarg;
|
Node *nextarg;
|
||||||
@ -1520,40 +1520,52 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
|
|||||||
u = ~((int)getfval(x));
|
u = ~((int)getfval(x));
|
||||||
break;
|
break;
|
||||||
case FAND:
|
case FAND:
|
||||||
if (nextarg == 0) {
|
if (nextarg == NULL) {
|
||||||
WARNING("and requires two arguments; returning 0");
|
WARNING("and requires two arguments; returning 0");
|
||||||
u = 0;
|
u = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
y = execute(a[1]->nnext);
|
i = ((int)getfval(x));
|
||||||
u = ((int)getfval(x)) & ((int)getfval(y));
|
while (nextarg != NULL) {
|
||||||
tempfree(y);
|
y = execute(nextarg);
|
||||||
nextarg = nextarg->nnext;
|
i &= (int)getfval(y);
|
||||||
|
tempfree(y);
|
||||||
|
nextarg = nextarg->nnext;
|
||||||
|
}
|
||||||
|
u = i;
|
||||||
break;
|
break;
|
||||||
case FFOR:
|
case FFOR:
|
||||||
if (nextarg == 0) {
|
if (nextarg == NULL) {
|
||||||
WARNING("or requires two arguments; returning 0");
|
WARNING("or requires two arguments; returning 0");
|
||||||
u = 0;
|
u = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
y = execute(a[1]->nnext);
|
i = ((int)getfval(x));
|
||||||
u = ((int)getfval(x)) | ((int)getfval(y));
|
while (nextarg != NULL) {
|
||||||
tempfree(y);
|
y = execute(nextarg);
|
||||||
nextarg = nextarg->nnext;
|
i |= (int)getfval(y);
|
||||||
|
tempfree(y);
|
||||||
|
nextarg = nextarg->nnext;
|
||||||
|
}
|
||||||
|
u = i;
|
||||||
break;
|
break;
|
||||||
case FXOR:
|
case FXOR:
|
||||||
if (nextarg == 0) {
|
if (nextarg == NULL) {
|
||||||
WARNING("xor requires two arguments; returning 0");
|
WARNING("xor requires two arguments; returning 0");
|
||||||
u = 0;
|
u = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
y = execute(a[1]->nnext);
|
i = ((int)getfval(x));
|
||||||
u = ((int)getfval(x)) ^ ((int)getfval(y));
|
while (nextarg != NULL) {
|
||||||
tempfree(y);
|
y = execute(nextarg);
|
||||||
nextarg = nextarg->nnext;
|
i ^= (int)getfval(y);
|
||||||
|
tempfree(y);
|
||||||
|
nextarg = nextarg->nnext;
|
||||||
|
}
|
||||||
|
u = i;
|
||||||
break;
|
break;
|
||||||
case FLSHIFT:
|
case FLSHIFT:
|
||||||
if (nextarg == 0) {
|
if (nextarg == NULL) {
|
||||||
WARNING("lshift requires two arguments; returning 0");
|
WARNING("lshift requires two arguments; returning 0");
|
||||||
u = 0;
|
u = 0;
|
||||||
break;
|
break;
|
||||||
@ -1564,7 +1576,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
|
|||||||
nextarg = nextarg->nnext;
|
nextarg = nextarg->nnext;
|
||||||
break;
|
break;
|
||||||
case FRSHIFT:
|
case FRSHIFT:
|
||||||
if (nextarg == 0) {
|
if (nextarg == NULL) {
|
||||||
WARNING("rshift requires two arguments; returning 0");
|
WARNING("rshift requires two arguments; returning 0");
|
||||||
u = 0;
|
u = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -690,12 +690,15 @@ and returns its exit status.
|
|||||||
.Bl -tag -width "lshift(a, b)"
|
.Bl -tag -width "lshift(a, b)"
|
||||||
.It Fn compl x
|
.It Fn compl x
|
||||||
Returns the bitwise complement of integer argument x.
|
Returns the bitwise complement of integer argument x.
|
||||||
.It Fn and x y
|
.It Fn and v1 v2 ...
|
||||||
Performs a bitwise AND on integer arguments x and y.
|
Performs a bitwise AND on all arguments provided, as integers.
|
||||||
.It Fn or x y
|
There must be at least two values.
|
||||||
Performs a bitwise OR on integer arguments x and y.
|
.It Fn or v1 v2 ...
|
||||||
.It Fn xor x y
|
Performs a bitwise OR on all arguments provided, as integers.
|
||||||
Performs a bitwise Exclusive-OR on integer arguments x and y.
|
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
|
.It Fn lshift x n
|
||||||
Returns integer argument x shifted by n bits to the left.
|
Returns integer argument x shifted by n bits to the left.
|
||||||
.It Fn rshift x n
|
.It Fn rshift x n
|
||||||
|
Loading…
Reference in New Issue
Block a user