diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-06-14 16:35:48 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-06-14 16:35:48 -0400 |
commit | 5826beec258141776469c5fd9b703d52c81a35fb (patch) | |
tree | 2d09f31301c392fa15218d5f133a19f4cfdb5fdb | |
parent | 56b1798777fe5464014fca3f9744ebdb950b8348 (diff) | |
download | egawk-5826beec258141776469c5fd9b703d52c81a35fb.tar.gz egawk-5826beec258141776469c5fd9b703d52c81a35fb.tar.bz2 egawk-5826beec258141776469c5fd9b703d52c81a35fb.zip |
Add a new boolval function to awk.h to make sure we handle this consistently.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | awk.h | 13 | ||||
-rw-r--r-- | builtin.c | 7 | ||||
-rw-r--r-- | eval.c | 17 | ||||
-rw-r--r-- | io.c | 9 |
5 files changed, 28 insertions, 26 deletions
@@ -1,5 +1,13 @@ 2016-06-14 Andrew J. Schorr <aschorr@telemetry-investments.com> + * awk.h (boolval): New inline function to standardize testing whether + a node's value is true. + * builtin.c (do_strftime): Use boolval to handle 3rd argument. + * eval.c (set_IGNORECASE, eval_condition): Use new boolval function. + * io.c (pty_vs_pipe): Use new boolval function. + +2016-06-14 Andrew J. Schorr <aschorr@telemetry-investments.com> + * builtin.c (do_strftime): Fix handling of 3rd argument to work as a standard boolean: non-null or non-zero. @@ -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) { @@ -1928,11 +1928,8 @@ do_strftime(int nargs) NODE *tmp; if (nargs == 3) { - t3 = fixtype(POP_SCALAR()); - if ((t3->flags & NUMBER) != 0) - do_gmt = ! iszero(t3); - else - do_gmt = (t3->stlen > 0); + t3 = POP_SCALAR(); + do_gmt = boolval(t3); DEREF(t3); } @@ -692,7 +692,6 @@ void set_IGNORECASE() { static bool warned = false; - NODE *n; if ((do_lint || do_traditional) && ! warned) { warned = true; @@ -701,13 +700,8 @@ set_IGNORECASE() load_casetable(); if (do_traditional) IGNORECASE = false; - else { - n = fixtype(IGNORECASE_node->var_value); - if ((n->flags & NUMBER) != 0) - IGNORECASE = ! iszero(n); - else - IGNORECASE = (n->stlen > 0); - } + else + IGNORECASE = boolval(IGNORECASE_node->var_value); set_RS(); /* set_RS() calls set_FS() if need be, for us */ } @@ -1517,12 +1511,7 @@ eval_condition(NODE *t) if (t == node_Boolean[true]) return true; - (void) fixtype(t); - - if ((t->flags & NUMBER) != 0) - return ! iszero(t); - - return (t->stlen != 0); + return boolval(t); } /* cmp_scalars -- compare two nodes on the stack */ @@ -3895,13 +3895,8 @@ pty_vs_pipe(const char *command) * in_PROCINFO function now checks that for us. */ val = in_PROCINFO(command, "pty", NULL); - if (val) { - val = fixtype(val); - if ((val->flags & NUMBER) != 0) - return ! iszero(val); - else - return (val->stlen != 0); - } + if (val) + return boolval(val); #endif /* HAVE_TERMIOS_H */ return false; } |