From 5826beec258141776469c5fd9b703d52c81a35fb Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Tue, 14 Jun 2016 16:35:48 -0400 Subject: Add a new boolval function to awk.h to make sure we handle this consistently. --- awk.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'awk.h') diff --git a/awk.h b/awk.h index 0cbcf049..0a7059b1 100644 --- a/awk.h +++ b/awk.h @@ -1843,6 +1843,19 @@ fixtype(NODE *n) return n; } +/* + * In `awk', a value is considered to be true if it is nonzero _or_ + * non-null. Otherwise, the value is false. + */ +static inline int +boolval(NODE *t) +{ + (void) fixtype(t); + if ((t->flags & NUMBER) != 0) + return ! iszero(t); + return (t->stlen > 0); +} + static inline void * emalloc_real(size_t count, const char *where, const char *var, const char *file, int line) { -- cgit v1.2.3