diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rwxr-xr-x | configure | 34 | ||||
-rw-r--r-- | m4/ChangeLog | 6 | ||||
-rw-r--r-- | m4/readline.m4 | 23 | ||||
-rw-r--r-- | profile.c | 46 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/Makefile.am | 10 | ||||
-rw-r--r-- | test/Makefile.in | 10 | ||||
-rw-r--r-- | test/profile6.awk | 7 | ||||
-rw-r--r-- | test/profile6.ok | 10 |
10 files changed, 145 insertions, 19 deletions
@@ -1,3 +1,16 @@ +2014-10-30 Arnold D. Robbins <arnold@skeeve.com> + + * configure: Regenerated after fix to m4/readline.m4. + + Unrelated; fixes to profiling. Thanks to Hermann Peifer and + Manuel Collado for pointing out problems: + + * profile.c (pprint): For Op_unary_minus, parenthesize -(-x) + correctly. + (prec_level): Get the levels right (checked the grammar). + (is_unary_minus): New function. + (pp_concat): Add checks for unary minus; needs to be parenthesized. + 2014-10-30 Andrew J. Schorr <aschorr@telemetry-investments.com> * NEWS: Mention installation of /etc/profile.d/gawk.{csh,sh}. @@ -10431,7 +10431,39 @@ fi $as_echo_n "checking whether readline via \"$_combo\" is present and sane... " >&6; } if test "$cross_compiling" = yes; then : - _found_readline=no + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <stdio.h> +#include <readline/readline.h> +#include <readline/history.h> +int +main () +{ + + int fd; + char *line; + + close(0); + close(1); + fd = open("/dev/null", 2); /* should get fd 0 */ + dup(fd); + line = readline("giveittome> "); + + /* some printfs don't handle NULL for %s */ + printf("got <%s>\n", line ? line : "(NULL)"); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + _found_readline=yes +else + _found_readline=no + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext else cat confdefs.h - <<_ACEOF >conftest.$ac_ext diff --git a/m4/ChangeLog b/m4/ChangeLog index 81fdcec0..17c482cb 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,9 @@ +2014-10-30 Arnold D. Robbins <arnold@skeeve.com> + + * readline.m4: Enable cross compiling. Thanks to + Christer Solskogen <christer.solskogen@gmail.com> for + motivating and testing. + 2014-04-08 Arnold D. Robbins <arnold@skeeve.com> * 4.1.1: Release tar ball made. diff --git a/m4/readline.m4 b/m4/readline.m4 index 77ed8b25..740b9c7b 100644 --- a/m4/readline.m4 +++ b/m4/readline.m4 @@ -62,7 +62,28 @@ dnl action if true: dnl action if false: [_found_readline=no], dnl action if cross compiling: - [_found_readline=no] + AC_TRY_LINK([#include <stdio.h> +#include <readline/readline.h> +#include <readline/history.h>], dnl includes + dnl function body + [ + int fd; + char *line; + + close(0); + close(1); + fd = open("/dev/null", 2); /* should get fd 0 */ + dup(fd); + line = readline("giveittome> "); + + /* some printfs don't handle NULL for %s */ + printf("got <%s>\n", line ? line : "(NULL)"); +], +dnl action if found: + [_found_readline=yes], +dnl action if not found: + [_found_readline=no] + ) ) AC_MSG_RESULT([$_found_readline]) @@ -420,7 +420,8 @@ cleanup: case Op_unary_minus: case Op_not: t1 = pp_pop(); - if (is_binary(t1->type)) + if (is_binary(t1->type) + || (((OPCODE) t1->type) == pc->opcode && pc->opcode == Op_unary_minus)) pp_parenthesize(t1); /* optypes table (eval.c) includes space after ! */ @@ -1057,25 +1058,25 @@ prec_level(int type) case Op_func_call: case Op_K_delete_loop: case Op_builtin: - return 15; + return 16; case Op_field_spec: case Op_field_spec_lhs: - return 14; - - case Op_exp: - case Op_exp_i: - return 13; + return 15; case Op_preincrement: case Op_predecrement: case Op_postincrement: case Op_postdecrement: - return 12; + return 14; + + case Op_exp: + case Op_exp_i: + return 13; case Op_unary_minus: case Op_not: - return 11; + return 12; case Op_times: case Op_times_i: @@ -1083,23 +1084,26 @@ prec_level(int type) case Op_quotient_i: case Op_mod: case Op_mod_i: - return 10; + return 11; case Op_plus: case Op_plus_i: case Op_minus: case Op_minus_i: - return 9; + return 10; case Op_concat: case Op_assign_concat: - return 8; + return 9; case Op_equal: case Op_notequal: case Op_greater: + case Op_less: case Op_leq: case Op_geq: + return 8; + case Op_match: case Op_nomatch: return 7; @@ -1108,7 +1112,6 @@ prec_level(int type) case Op_K_getline_redir: return 6; - case Op_less: case Op_in_array: return 5; @@ -1417,6 +1420,14 @@ pp_list(int nargs, const char *paren, const char *delim) return str; } +/* is_unary_minus --- return true if string starts with unary minus */ + +static bool +is_unary_minus(const char *str) +{ + return str[0] == '-' && str[1] != '-'; +} + /* pp_concat --- handle concatenation and correct parenthesizing of expressions */ static char * @@ -1458,7 +1469,12 @@ pp_concat(int nargs) pl_l = prec_level(pp_args[i]->type); pl_r = prec_level(pp_args[i+1]->type); - if (is_scalar(pp_args[i]->type) && is_scalar(pp_args[i+1]->type)) { + if (i >= 2 && is_unary_minus(r->pp_str)) { + *s++ = '('; + memcpy(s, r->pp_str, r->pp_len); + s += r->pp_len; + *s++ = ')'; + } else if (is_scalar(pp_args[i]->type) && is_scalar(pp_args[i+1]->type)) { memcpy(s, r->pp_str, r->pp_len); s += r->pp_len; } else if (pl_l <= pl_r || is_scalar(pp_args[i+1]->type)) { @@ -1480,7 +1496,7 @@ pp_concat(int nargs) pl_l = prec_level(pp_args[nargs-1]->type); pl_r = prec_level(pp_args[nargs]->type); r = pp_args[nargs]; - if (pl_l >= pl_r && ! is_scalar(pp_args[nargs]->type)) { + if (is_unary_minus(r->pp_str) || ((pl_l >= pl_r && ! is_scalar(pp_args[nargs]->type)))) { *s++ = '('; memcpy(s, r->pp_str, r->pp_len); s += r->pp_len; diff --git a/test/ChangeLog b/test/ChangeLog index a9386634..614dc1d0 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2014-10-30 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (profile6): New test. + * profile6.awk, profile6.ok: New files. + 2014-10-17 Andrew J. Schorr <aschorr@telemetry-investments.com> * Makefile.am (profile1, testext): Use explicit ./foo.awk to avoid diff --git a/test/Makefile.am b/test/Makefile.am index aae27832..5f2b4c67 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -706,6 +706,8 @@ EXTRA_DIST = \ profile4.ok \ profile5.awk \ profile5.ok \ + profile6.awk \ + profile6.ok \ prt1eval.awk \ prt1eval.ok \ prtoeval.awk \ @@ -1019,7 +1021,7 @@ GAWK_EXT_TESTS = \ manyfiles match1 match2 match3 mbstr1 \ nastyparm next nondec nondec2 \ patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \ - profile1 profile2 profile3 profile4 profile5 pty1 \ + profile1 profile2 profile3 profile4 profile5 profile6 pty1 \ rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \ rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \ splitarg4 strftime \ @@ -1700,6 +1702,12 @@ profile5: @$(AWK) --pretty-print=_$@ -f "$(srcdir)"/$@.awk > /dev/null @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +profile6: + @echo $@ + @GAWK_NO_PP_RUN=1 $(AWK) --profile=ap-$@.out -f "$(srcdir)"/$@.awk > /dev/null + @sed 1,2d < ap-$@.out > _$@; rm ap-$@.out + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + posix2008sub: @echo $@ @$(AWK) --posix -f "$(srcdir)"/$@.awk > _$@ 2>&1 diff --git a/test/Makefile.in b/test/Makefile.in index 9d264be2..c7a14fcf 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -952,6 +952,8 @@ EXTRA_DIST = \ profile4.ok \ profile5.awk \ profile5.ok \ + profile6.awk \ + profile6.ok \ prt1eval.awk \ prt1eval.ok \ prtoeval.awk \ @@ -1264,7 +1266,7 @@ GAWK_EXT_TESTS = \ manyfiles match1 match2 match3 mbstr1 \ nastyparm next nondec nondec2 \ patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \ - profile1 profile2 profile3 profile4 profile5 pty1 \ + profile1 profile2 profile3 profile4 profile5 profile6 pty1 \ rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \ rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \ splitarg4 strftime \ @@ -2124,6 +2126,12 @@ profile5: @$(AWK) --pretty-print=_$@ -f "$(srcdir)"/$@.awk > /dev/null @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +profile6: + @echo $@ + @GAWK_NO_PP_RUN=1 $(AWK) --profile=ap-$@.out -f "$(srcdir)"/$@.awk > /dev/null + @sed 1,2d < ap-$@.out > _$@; rm ap-$@.out + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + posix2008sub: @echo $@ @$(AWK) --posix -f "$(srcdir)"/$@.awk > _$@ 2>&1 diff --git a/test/profile6.awk b/test/profile6.awk new file mode 100644 index 00000000..754f8ae6 --- /dev/null +++ b/test/profile6.awk @@ -0,0 +1,7 @@ +BEGIN { + x = 3 + print -(-x) + Q = "|" + print -3 Q (-4) + print -3 Q (-4) (-5) +} diff --git a/test/profile6.ok b/test/profile6.ok new file mode 100644 index 00000000..86ff68a6 --- /dev/null +++ b/test/profile6.ok @@ -0,0 +1,10 @@ + # BEGIN rule(s) + + BEGIN { + x = 3 + print -(-x) + Q = "|" + print -3 Q (-4) + print -3 Q (-4) (-5) + } + |