diff options
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | awk.h | 1 | ||||
-rw-r--r-- | eval.c | 30 | ||||
-rw-r--r-- | extension/ChangeLog | 7 | ||||
-rw-r--r-- | extension/Makefile.am | 4 | ||||
-rw-r--r-- | extension/Makefile.in | 4 | ||||
-rw-r--r-- | field.c | 21 | ||||
-rw-r--r-- | test/ChangeLog | 4 | ||||
-rw-r--r-- | test/ofs1.ok | 6 |
11 files changed, 76 insertions, 24 deletions
@@ -1,3 +1,22 @@ +2014-08-12 Arnold D. Robbins <arnold@skeeve.com> + + OFS being set should rebuild $0 using previous OFS if $0 + needs to be rebuilt. Thanks to Mike Brennan for pointing this out. + + * awk.h (rebuild_record): Declare. + * eval.c (set_OFS): If not being called from var_init(), check + if $0 needs rebuilding. If so, parse the record fully and rebuild it. + Make OFS point to a separate copy of the new OFS for next time, since + OFS_node->var_value->stptr was already updated at this point. + * field.c (rebuild_record): Is now extern instead of static. + Use OFS and OFSlen instead of the value of OFS_node. + + Unrelated: + + * Makefile.am (dist-hook): Replace use of $(RM) by rm -f; not all + versions of make set that variable. Thanks to Jeremie + Courreges-Anglas <jca@wxcvbn.org> for the report. + 2014-08-05 Arnold D. Robbins <arnold@skeeve.com> Bug fix: For MPFR sqrt(), need to set precision of result to be diff --git a/Makefile.am b/Makefile.am index 6e5715d7..c14a39b3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -176,7 +176,7 @@ dist-hook: sed -n -f configpk.sed < ../configure.ac > /tmp/tmp.sed ; \ sed -f config.sed < ../configh.in > /tmp/config.tmp ; \ sed -f /tmp/tmp.sed < /tmp/config.tmp > config.h ; \ - $(RM) /tmp/tmp.sed /tmp/config.tmp + rm -f /tmp/tmp.sed /tmp/config.tmp pwd chmod u+w $(distdir)/pc/config.h cp $(srcdir)/pc/config.h $(distdir)/pc/config.h diff --git a/Makefile.in b/Makefile.in index 2abf5b46..ae307ff4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1175,7 +1175,7 @@ dist-hook: sed -n -f configpk.sed < ../configure.ac > /tmp/tmp.sed ; \ sed -f config.sed < ../configh.in > /tmp/config.tmp ; \ sed -f /tmp/tmp.sed < /tmp/config.tmp > config.h ; \ - $(RM) /tmp/tmp.sed /tmp/config.tmp + rm -f /tmp/tmp.sed /tmp/config.tmp pwd chmod u+w $(distdir)/pc/config.h cp $(srcdir)/pc/config.h $(distdir)/pc/config.h @@ -1473,6 +1473,7 @@ extern NODE *get_actual_argument(int, bool, bool); extern void init_fields(void); extern void set_record(const char *buf, int cnt); extern void reset_record(void); +extern void rebuild_record(void); extern void set_NF(void); extern NODE **get_field(long num, Func_ptr *assign); extern NODE *do_split(int nargs); @@ -803,9 +803,35 @@ set_BINMODE() void set_OFS() { + static bool first = true; + size_t new_ofs_len; + + if (first) /* true when called from init_vars() in main() */ + first = false; + else { + /* rebuild $0 using OFS that was current when $0 changed */ + if (! field0_valid) { + get_field(UNLIMITED - 1, NULL); + rebuild_record(); + } + } + + /* + * Save OFS value for use in building record and in printing. + * Can't just have OFS point into the OFS_node since it's + * already updated when we come into this routine, and we need + * the old value to rebuild the record (see above). + */ OFS_node->var_value = force_string(OFS_node->var_value); - OFS = OFS_node->var_value->stptr; - OFSlen = OFS_node->var_value->stlen; + new_ofs_len = OFS_node->var_value->stlen; + + if (OFS == NULL) + emalloc(OFS, char *, new_ofs_len + 2, "set_OFS"); + else if (OFSlen < new_ofs_len) + erealloc(OFS, char *, new_ofs_len + 2, "set_OFS"); + + memcpy(OFS, OFS_node->var_value->stptr, OFS_node->var_value->stlen); + OFSlen = new_ofs_len; OFS[OFSlen] = '\0'; } diff --git a/extension/ChangeLog b/extension/ChangeLog index ab3d62c0..295e72cc 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,10 @@ +2014-08-12 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (install-data-hook): Replace use of $(RM) by rm -f; + not all versions of make set that variable. Thanks to Jeremie + Courreges-Anglas <jca@wxcvbn.org> for the report. + (uninstall-so): Ditto. + 2014-06-13 Paul Gortmaker <paul.gortmaker@windriver.com> * Makefile.am (uninstall-so): Came across below bug while cross diff --git a/extension/Makefile.am b/extension/Makefile.am index b6beaee3..b6c969ba 100644 --- a/extension/Makefile.am +++ b/extension/Makefile.am @@ -100,12 +100,12 @@ testext_la_LIBADD = $(MY_LIBS) install-data-hook: for i in $(pkgextension_LTLIBRARIES) ; do \ - $(RM) $(DESTDIR)$(pkgextensiondir)/$$i ; \ + rm -f $(DESTDIR)$(pkgextensiondir)/$$i ; \ done # Keep the uninstall check working: uninstall-so: - $(RM) $(DESTDIR)$(pkgextensiondir)/*.so + rm -f $(DESTDIR)$(pkgextensiondir)/*.so uninstall-recursive: uninstall-so diff --git a/extension/Makefile.in b/extension/Makefile.in index 294e4f88..692998bf 100644 --- a/extension/Makefile.in +++ b/extension/Makefile.in @@ -1231,12 +1231,12 @@ uninstall-man: uninstall-man3 install-data-hook: for i in $(pkgextension_LTLIBRARIES) ; do \ - $(RM) $(DESTDIR)$(pkgextensiondir)/$$i ; \ + rm -f $(DESTDIR)$(pkgextensiondir)/$$i ; \ done # Keep the uninstall check working: uninstall-so: - $(RM) $(DESTDIR)$(pkgextensiondir)/*.so + rm -f $(DESTDIR)$(pkgextensiondir)/*.so uninstall-recursive: uninstall-so @@ -40,7 +40,6 @@ typedef void (* Setfunc)(long, char *, long, NODE *); static long (*parse_field)(long, char **, int, NODE *, Regexp *, Setfunc, NODE *, NODE *, bool); -static void rebuild_record(void); static long re_parse_field(long, char **, int, NODE *, Regexp *, Setfunc, NODE *, NODE *, bool); static long def_parse_field(long, char **, int, NODE *, @@ -140,7 +139,7 @@ set_field(long num, /* rebuild_record --- Someone assigned a value to $(something). Fix up $0 to be right */ -static void +void rebuild_record() { /* @@ -148,9 +147,7 @@ rebuild_record() * a size_t isn't big enough. */ unsigned long tlen; - unsigned long ofslen; NODE *tmp; - NODE *ofs; char *ops; char *cops; long i; @@ -158,14 +155,12 @@ rebuild_record() assert(NF != -1); tlen = 0; - ofs = force_string(OFS_node->var_value); - ofslen = ofs->stlen; for (i = NF; i > 0; i--) { tmp = fields_arr[i]; tmp = force_string(tmp); tlen += tmp->stlen; } - tlen += (NF - 1) * ofslen; + tlen += (NF - 1) * OFSlen; if ((long) tlen < 0) tlen = 0; emalloc(ops, char *, tlen + 2, "rebuild_record"); @@ -183,11 +178,11 @@ rebuild_record() } /* copy OFS */ if (i != NF) { - if (ofslen == 1) - *cops++ = ofs->stptr[0]; - else if (ofslen != 0) { - memcpy(cops, ofs->stptr, ofslen); - cops += ofslen; + if (OFSlen == 1) + *cops++ = *OFS; + else if (OFSlen != 0) { + memcpy(cops, OFS, OFSlen); + cops += OFSlen; } } } @@ -231,7 +226,7 @@ rebuild_record() fields_arr[i] = n; assert((n->flags & WSTRCUR) == 0); } - cops += fields_arr[i]->stlen + ofslen; + cops += fields_arr[i]->stlen + OFSlen; } unref(fields_arr[0]); diff --git a/test/ChangeLog b/test/ChangeLog index db9b1e35..61b8cd3b 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2014-08-12 Arnold D. Robbins <arnold@skeeve.com> + + * ofs1.ok: Updated to match corrected behavior in gawk. + 2014-08-05 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (mpfrsqrt): New test. diff --git a/test/ofs1.ok b/test/ofs1.ok index a3a8ca7b..d01fa161 100644 --- a/test/ofs1.ok +++ b/test/ofs1.ok @@ -1,7 +1,7 @@ -a:x:c +a x c a x c a x c a -a:x:c a x c -a:x:c +a x c +a x c |