|
|
54a5e1 |
From c1f670b26671cc8d60d967bbcb42cb8deb3baf2b Mon Sep 17 00:00:00 2001
|
|
|
54a5e1 |
From: "Arnold D. Robbins" <arnold@skeeve.com>
|
|
|
54a5e1 |
Date: Tue, 31 Jul 2018 21:40:49 +0300
|
|
|
54a5e1 |
Subject: Fix assigning $0 from a number.
|
|
|
54a5e1 |
|
|
|
54a5e1 |
---
|
|
|
54a5e1 |
ChangeLog | 6 ++++++
|
|
|
54a5e1 |
interpret.h | 1 +
|
|
|
54a5e1 |
test/ChangeLog | 5 +++++
|
|
|
54a5e1 |
test/Makefile.am | 5 ++++-
|
|
|
54a5e1 |
test/Makefile.in | 10 +++++++++-
|
|
|
54a5e1 |
test/Maketests | 5 +++++
|
|
|
54a5e1 |
test/assignnumfield.awk | 1 +
|
|
|
54a5e1 |
test/assignnumfield.in | 5 +++++
|
|
|
54a5e1 |
test/assignnumfield.ok | 5 +++++
|
|
|
54a5e1 |
9 files changed, 41 insertions(+), 2 deletions(-)
|
|
|
54a5e1 |
create mode 100644 test/assignnumfield.awk
|
|
|
54a5e1 |
create mode 100644 test/assignnumfield.in
|
|
|
54a5e1 |
create mode 100644 test/assignnumfield.ok
|
|
|
54a5e1 |
|
|
|
54a5e1 |
diff --git a/ChangeLog b/ChangeLog
|
|
|
54a5e1 |
index 904e984c..68210057 100644
|
|
|
54a5e1 |
--- a/ChangeLog
|
|
|
54a5e1 |
+++ b/ChangeLog
|
|
|
54a5e1 |
@@ -1,3 +1,9 @@
|
|
|
54a5e1 |
+2018-07-31 Arnold D. Robbins <arnold@skeeve.com>
|
|
|
54a5e1 |
+
|
|
|
54a5e1 |
+ * interpret.h (unfield): Add a call to force_string() on
|
|
|
54a5e1 |
+ new value. See test/assignnumfield.awk. Thanks to
|
|
|
54a5e1 |
+ Ralph Corderoy <ralph@inputplus.co.uk> for the bug report.
|
|
|
54a5e1 |
+
|
|
|
54a5e1 |
2018-02-25 Arnold D. Robbins <arnold@skeeve.com>
|
|
|
54a5e1 |
|
|
|
54a5e1 |
* 4.2.1: Release tar ball made.
|
|
|
54a5e1 |
diff --git a/interpret.h b/interpret.h
|
|
|
54a5e1 |
index 8408a532..fed0078c 100644
|
|
|
54a5e1 |
--- a/interpret.h
|
|
|
54a5e1 |
+++ b/interpret.h
|
|
|
54a5e1 |
@@ -46,16 +46,25 @@ unfield(NODE **l, NODE **r)
|
|
|
54a5e1 |
* valref 1, that effectively means that this is an assignment like "$n = $n",
|
|
|
54a5e1 |
* so a no-op, other than triggering $0 reconstitution.
|
|
|
54a5e1 |
*/
|
|
|
54a5e1 |
-#define UNFIELD(l, r) \
|
|
|
54a5e1 |
-{ \
|
|
|
54a5e1 |
- /* if was a field, turn it into a var */ \
|
|
|
54a5e1 |
- if ((r->flags & MALLOC) != 0 || r->valref == 1) { \
|
|
|
54a5e1 |
- l = r; \
|
|
|
54a5e1 |
- } else { \
|
|
|
54a5e1 |
- l = dupnode(r); \
|
|
|
54a5e1 |
- DEREF(r); \
|
|
|
54a5e1 |
- } \
|
|
|
54a5e1 |
-}
|
|
|
54a5e1 |
+// not a macro so we can step into it with a debugger
|
|
|
54a5e1 |
+#ifndef UNFIELD_DEFINED
|
|
|
54a5e1 |
+#define UNFIELD_DEFINED 1
|
|
|
54a5e1 |
+static inline void
|
|
|
54a5e1 |
+unfield(NODE **l, NODE **r)
|
|
|
54a5e1 |
+{
|
|
|
54a5e1 |
+ /* if was a field, turn it into a var */
|
|
|
54a5e1 |
+ if (((*r)->flags & MALLOC) != 0 || (*r)->valref == 1) {
|
|
|
54a5e1 |
+ (*l) = (*r);
|
|
|
54a5e1 |
+ } else {
|
|
|
54a5e1 |
+ (*l) = dupnode(*r);
|
|
|
54a5e1 |
+ DEREF(*r);
|
|
|
54a5e1 |
+ }
|
|
|
54a5e1 |
+ force_string(*l);
|
|
|
54a5e1 |
+}
|
|
|
54a5e1 |
+
|
|
|
54a5e1 |
+#define UNFIELD(l, r) unfield(& (l), & (r))
|
|
|
54a5e1 |
+#endif
|
|
|
54a5e1 |
+
|
|
|
54a5e1 |
int
|
|
|
54a5e1 |
r_interpret(INSTRUCTION *code)
|
|
|
54a5e1 |
{
|
|
|
54a5e1 |
diff --git a/test/ChangeLog b/test/ChangeLog
|
|
|
54a5e1 |
index 392d593b..2af89e66 100644
|
|
|
54a5e1 |
--- a/test/ChangeLog
|
|
|
54a5e1 |
+++ b/test/ChangeLog
|
|
|
54a5e1 |
@@ -1,3 +1,8 @@
|
|
|
54a5e1 |
+2018-07-31 Arnold D. Robbins <arnold@skeeve.com>
|
|
|
54a5e1 |
+
|
|
|
54a5e1 |
+ * Makefile.am (EXTRA_DIST): Add assignnumfield files.
|
|
|
54a5e1 |
+ * assignnumfield.awk, assignnumfield.in, assignnumfield.ok: New files.
|
|
|
54a5e1 |
+
|
|
|
54a5e1 |
2018-02-25 Arnold D. Robbins <arnold@skeeve.com>
|
|
|
54a5e1 |
|
|
|
54a5e1 |
* 4.2.1: Release tar ball made.
|
|
|
54a5e1 |
diff --git a/test/Makefile.am b/test/Makefile.am
|
|
|
54a5e1 |
index e6f1e223..774424f7 100644
|
|
|
54a5e1 |
--- a/test/Makefile.am
|
|
|
54a5e1 |
+++ b/test/Makefile.am
|
|
|
54a5e1 |
@@ -121,6 +121,9 @@ EXTRA_DIST = \
|
|
|
54a5e1 |
asort.ok \
|
|
|
54a5e1 |
asorti.awk \
|
|
|
54a5e1 |
asorti.ok \
|
|
|
54a5e1 |
+ assignnumfield.awk \
|
|
|
54a5e1 |
+ assignnumfield.in \
|
|
|
54a5e1 |
+ assignnumfield.ok \
|
|
|
54a5e1 |
awkpath.ok \
|
|
|
54a5e1 |
back89.awk \
|
|
|
54a5e1 |
back89.in \
|
|
|
54a5e1 |
@@ -1235,7 +1238,7 @@ BASIC_TESTS = \
|
|
|
54a5e1 |
addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm \
|
|
|
54a5e1 |
arrayprm2 arrayprm3 arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 \
|
|
|
54a5e1 |
arynasty arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
|
|
|
54a5e1 |
- aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \
|
|
|
54a5e1 |
+ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath assignnumfield \
|
|
|
54a5e1 |
back89 backgsub badassign1 badbuild \
|
|
|
54a5e1 |
callparam childin clobber closebad clsflnam compare compare2 \
|
|
|
54a5e1 |
concat1 concat2 concat3 concat4 concat5 convfmt \
|
|
|
54a5e1 |
diff --git a/test/Makefile.in b/test/Makefile.in
|
|
|
54a5e1 |
index 532aca07..69b86d07 100644
|
|
|
54a5e1 |
--- a/test/Makefile.in
|
|
|
54a5e1 |
+++ b/test/Makefile.in
|
|
|
54a5e1 |
@@ -379,6 +379,9 @@ EXTRA_DIST = \
|
|
|
54a5e1 |
asort.ok \
|
|
|
54a5e1 |
asorti.awk \
|
|
|
54a5e1 |
asorti.ok \
|
|
|
54a5e1 |
+ assignnumfield.awk \
|
|
|
54a5e1 |
+ assignnumfield.in \
|
|
|
54a5e1 |
+ assignnumfield.ok \
|
|
|
54a5e1 |
awkpath.ok \
|
|
|
54a5e1 |
back89.awk \
|
|
|
54a5e1 |
back89.in \
|
|
|
54a5e1 |
@@ -1493,7 +1496,7 @@ BASIC_TESTS = \
|
|
|
54a5e1 |
addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm \
|
|
|
54a5e1 |
arrayprm2 arrayprm3 arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 \
|
|
|
54a5e1 |
arynasty arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
|
|
|
54a5e1 |
- aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \
|
|
|
54a5e1 |
+ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath assignnumfield \
|
|
|
54a5e1 |
back89 backgsub badassign1 badbuild \
|
|
|
54a5e1 |
callparam childin clobber closebad clsflnam compare compare2 \
|
|
|
54a5e1 |
concat1 concat2 concat3 concat4 concat5 convfmt \
|
|
|
54a5e1 |
@@ -2787,6 +2790,11 @@ asgext:
|
|
|
54a5e1 |
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
54a5e1 |
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
|
|
|
54a5e1 |
|
|
|
54a5e1 |
+assignnumfield:
|
|
|
54a5e1 |
+ @echo $@
|
|
|
54a5e1 |
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
54a5e1 |
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
|
|
|
54a5e1 |
+
|
|
|
54a5e1 |
back89:
|
|
|
54a5e1 |
@echo $@
|
|
|
54a5e1 |
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
54a5e1 |
diff --git a/test/Maketests b/test/Maketests
|
|
|
54a5e1 |
index 8c604222..eb7c4651 100644
|
|
|
54a5e1 |
--- a/test/Maketests
|
|
|
54a5e1 |
+++ b/test/Maketests
|
|
|
54a5e1 |
@@ -140,6 +140,11 @@ asgext:
|
|
|
54a5e1 |
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
54a5e1 |
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
|
|
|
54a5e1 |
|
|
|
54a5e1 |
+assignnumfield:
|
|
|
54a5e1 |
+ @echo $@
|
|
|
54a5e1 |
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
54a5e1 |
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
|
|
|
54a5e1 |
+
|
|
|
54a5e1 |
back89:
|
|
|
54a5e1 |
@echo $@
|
|
|
54a5e1 |
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
54a5e1 |
diff --git a/test/assignnumfield.awk b/test/assignnumfield.awk
|
|
|
54a5e1 |
new file mode 100644
|
|
|
54a5e1 |
index 00000000..3a056cb0
|
|
|
54a5e1 |
--- /dev/null
|
|
|
54a5e1 |
+++ b/test/assignnumfield.awk
|
|
|
54a5e1 |
@@ -0,0 +1 @@
|
|
|
54a5e1 |
+{$0 = ++i} 1
|
|
|
54a5e1 |
diff --git a/test/assignnumfield.in b/test/assignnumfield.in
|
|
|
54a5e1 |
new file mode 100644
|
|
|
54a5e1 |
index 00000000..b82c4b2d
|
|
|
54a5e1 |
--- /dev/null
|
|
|
54a5e1 |
+++ b/test/assignnumfield.in
|
|
|
54a5e1 |
@@ -0,0 +1,5 @@
|
|
|
54a5e1 |
+a b c
|
|
|
54a5e1 |
+a b c
|
|
|
54a5e1 |
+a b c
|
|
|
54a5e1 |
+a b c
|
|
|
54a5e1 |
+a b c
|
|
|
54a5e1 |
diff --git a/test/assignnumfield.ok b/test/assignnumfield.ok
|
|
|
54a5e1 |
new file mode 100644
|
|
|
54a5e1 |
index 00000000..8a1218a1
|
|
|
54a5e1 |
--- /dev/null
|
|
|
54a5e1 |
+++ b/test/assignnumfield.ok
|
|
|
54a5e1 |
@@ -0,0 +1,5 @@
|
|
|
54a5e1 |
+1
|
|
|
54a5e1 |
+2
|
|
|
54a5e1 |
+3
|
|
|
54a5e1 |
+4
|
|
|
54a5e1 |
+5
|
|
|
54a5e1 |
--
|
|
|
54a5e1 |
cgit v1.2.1
|
|
|
54a5e1 |
|