From ca9278ee5855a91a5521960d3743809f47ed27b8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Jun 2021 12:42:39 +0200 Subject: awk: rewrite "print" logic a bit to make it clearer Signed-off-by: Denys Vlasenko --- editors/awk.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'editors') diff --git a/editors/awk.c b/editors/awk.c index c05d5d6..0fbca04 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2792,7 +2792,7 @@ static var *evaluate(node *op, var *res) if (!op1) { fputs(getvar_s(intvar[F0]), F); } else { - while (op1) { + for (;;) { var *v = evaluate(nextarg(&op1), v1); if (v->type & VF_NUMBER) { fmt_num(g_buf, MAXVARFMT, getvar_s(intvar[OFMT]), @@ -2801,13 +2801,12 @@ static var *evaluate(node *op, var *res) } else { fputs(getvar_s(v), F); } - - if (op1) - fputs(getvar_s(intvar[OFS]), F); + if (!op1) + break; + fputs(getvar_s(intvar[OFS]), F); } } fputs(getvar_s(intvar[ORS]), F); - } else { /* OC_PRINTF */ char *s = awk_printf(op1, &len); #if ENABLE_FEATURE_AWK_GNU_EXTENSIONS -- cgit v1.1