aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2016-06-14 16:35:48 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2016-06-14 16:35:48 -0400
commit5826beec258141776469c5fd9b703d52c81a35fb (patch)
tree2d09f31301c392fa15218d5f133a19f4cfdb5fdb
parent56b1798777fe5464014fca3f9744ebdb950b8348 (diff)
downloadegawk-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--ChangeLog8
-rw-r--r--awk.h13
-rw-r--r--builtin.c7
-rw-r--r--eval.c17
-rw-r--r--io.c9
5 files changed, 28 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 87ea1896..2f4631f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
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)
{
diff --git a/builtin.c b/builtin.c
index ede02474..4d9e1452 100644
--- a/builtin.c
+++ b/builtin.c
@@ -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);
}
diff --git a/eval.c b/eval.c
index 90947dc5..ee674911 100644
--- a/eval.c
+++ b/eval.c
@@ -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 */
diff --git a/io.c b/io.c
index 9d827d75..94a5dfc3 100644
--- a/io.c
+++ b/io.c
@@ -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;
}