From f8c6df739c58cc5b8dd506abdf479b35dc19cb10 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 15 Jan 2022 10:13:09 -0800 Subject: [PATCH] lefty: return a C99 bool from 'boolop' instead of an int --- cmd/lefty/exec.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cmd/lefty/exec.c b/cmd/lefty/exec.c index ae2e05822..48aa9430f 100644 --- a/cmd/lefty/exec.c +++ b/cmd/lefty/exec.c @@ -17,6 +17,7 @@ #include "str.h" #include "exec.h" #include "internal.h" +#include #include static lvar_t *lvarp; @@ -127,7 +128,7 @@ static void eforinst (Tobj, int); static Tobj getval (Tobj, int); static int getvar (Tobj, int, tnk_t *); static void setvar (tnk_t, Tobj); -static int boolop (Tobj); +static bool boolop (Tobj); static int orderop (Tobj, int, Tobj); static Tobj arithop (Num_t *, int, Num_t *); static void err (int, int, Tobj, int); @@ -254,19 +255,19 @@ tailrec: err (ERRNORHS, ERR4, co, i1); switch (ctype) { case C_OR: - if (boolop (v1o) == TRUE) + if (boolop (v1o)) return Ttrue; if ((v1o = eeval (co, TCgetnext (co, i1))) == NULL) err (ERRNORHS, ERR4, co, TCgetnext (co, i1)); - return (boolop (v1o) == TRUE) ? Ttrue: Tfalse; + return boolop(v1o) ? Ttrue: Tfalse; case C_AND: if (boolop (v1o) == FALSE) return Tfalse; if ((v1o = eeval (co, TCgetnext (co, i1))) == NULL) err (ERRNORHS, ERR4, co, TCgetnext (co, i1)); - return (boolop (v1o) == FALSE) ? Tfalse: Ttrue; + return !boolop(v1o) ? Tfalse: Ttrue; case C_NOT: - return (boolop (v1o) == TRUE) ? Tfalse: Ttrue; + return !boolop(v1o) ? Tfalse: Ttrue; } /* NOT REACHED */ return Tfalse; @@ -379,7 +380,7 @@ tailrec: i1 = TCgetfp (co, ci); if (!(v1o = eeval (co, i1))) err (ERRNORHS, ERR5, co, i1); - if (boolop (v1o) == TRUE) { + if (boolop(v1o)) { ci = TCgetnext (co, i1); goto tailrec; } else if ((ci = TCgetnext (co, TCgetnext (co, i1))) != C_NULL) @@ -552,7 +553,7 @@ static void ewhilest (Tobj co, int ci) { for (;;) { if (!(v1o = eeval ((Tobj) c1o, ei))) err (ERRNORHS, ERR5, c1o, ei); - if (boolop (v1o) == FALSE) + if (!boolop(v1o)) break; if (setjmp (*pljbufp1)) { if (pljtype == PLJ_CONTINUE) @@ -588,7 +589,7 @@ static void eforst (Tobj co, int ci) { if (!eisnop2) { if (!(v1o = eeval ((Tobj) c1o, ei2))) err (ERRNORHS, ERR5, c1o, ei2); - if (boolop (v1o) == FALSE) + if (!boolop(v1o)) break; } if (setjmp (*pljbufp1) != 0) { @@ -814,26 +815,26 @@ static void setvar (tnk_t tnk, Tobj vo) { } } -static int boolop (Tobj vo) { +static bool boolop (Tobj vo) { long i; double d; if (!vo) - return FALSE; + return false; switch (Tgettype (vo)) { case T_INTEGER: i = Tgetinteger (vo); - return (i == 0) ? FALSE : TRUE; + return i != 0; case T_REAL: d = Tgetreal (vo); - return (d == 0.0) ? FALSE : TRUE; + return !(d == 0.0); case T_TABLE: if (vo == null) - return FALSE; - return TRUE; + return false; + return true; default: - return TRUE; + return true; } } -- 2.40.0