diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2020-01-19 20:52:46 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2020-01-19 20:52:46 +0200 |
commit | 15db23b88c2866ed900177cbf11ce37e373e5e20 (patch) | |
tree | 4adfc1f12e9877e5c567e46c4702400054bc8d2a /profile.c | |
parent | a2a6e548bc3afcbf4c7401ebdfa8213dbe4e8dea (diff) | |
download | egawk-15db23b88c2866ed900177cbf11ce37e373e5e20.tar.gz egawk-15db23b88c2866ed900177cbf11ce37e373e5e20.tar.bz2 egawk-15db23b88c2866ed900177cbf11ce37e373e5e20.zip |
Fix a pretty-printer error with print[f].
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -196,6 +196,10 @@ pp_pop() return n; } +/* pp_top --- look at what's on the top of the stack */ + +#define pp_top() pp_stack + /* pp_free --- release a pretty printed node */ static void @@ -665,9 +669,20 @@ cleanup: if (pc->opcode == Op_K_print_rec) // instead of `print $0', just `print' tmp = strdup(""); - else if (pc->redir_type != 0) - tmp = pp_list(pc->expr_count, "()", ", "); - else { + else if (pc->redir_type != 0) { + // Avoid turning printf("hello\n") into printf(("hello\n")) + NODE *n = pp_top(); + + if (pc->expr_count == 1 + && n->pp_str[0] == '(' + && n->pp_str[n->pp_len - 1] == ')') { + n = pp_pop(); + + tmp = strdup(n->pp_str); + pp_free(n); + } else + tmp = pp_list(pc->expr_count, "()", ", "); + } else { tmp = pp_list(pc->expr_count, " ", ", "); tmp[strlen(tmp) - 1] = '\0'; /* remove trailing space */ } |