aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoronetrueawk <bwkster@gmail.com>2019-03-03 15:10:03 -0500
committerGitHub <noreply@github.com>2019-03-03 15:10:03 -0500
commit1164fa7ace1beb249c885a1d1c9b6f3eb131e8bb (patch)
tree559983bb8873c637b361cf5e382ac29c68c891b4
parent115fac05872c0def5dbc9959a3c7a4d078c454c5 (diff)
parentf25e845cf7a09d7b43c7a07e535a2e8d7f63aee1 (diff)
downloadone-true-awk-1164fa7ace1beb249c885a1d1c9b6f3eb131e8bb.tar.gz
Merge pull request #31 from arnoldrobbins/master
Make getline handle numeric strings, and update FIXES
-rw-r--r--ChangeLog9
-rw-r--r--FIXES10
-rw-r--r--bugs-fixed/README5
-rw-r--r--bugs-fixed/getline-numeric.awk6
-rw-r--r--bugs-fixed/getline-numeric.bad3
-rw-r--r--bugs-fixed/getline-numeric.in1
-rw-r--r--bugs-fixed/getline-numeric.ok3
-rw-r--r--main.c2
-rw-r--r--run.c8
9 files changed, 45 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 59d4b07..7516cd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-01-26 Arnold D. Robbins <arnold@skeeve.com>
+
+ * main.c (version): Updated.
+
+2019-01-25 Arnold D. Robbins <arnold@skeeve.com>
+
+ * run.c (awkgetline): Check for numeric value in all getline
+ variants. See the numeric-getline.* files in bugs-fixed directory.
+
2018-08-29 Arnold D. Robbins <arnold@skeeve.com>
* REGRESS: Check for existence of a.out. If not there, run
diff --git a/FIXES b/FIXES
index 909afb7..66b524b 100644
--- a/FIXES
+++ b/FIXES
@@ -25,6 +25,16 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the AWK book
was sent to the printers in August, 1987.
+Jan 25, 2019:
+ Make getline handle numeric strings properly in all cases.
+ (Thanks, Arnold.)
+
+Jan 21, 2019:
+ Merged a number of small fixes from GitHub pull requests.
+ Thanks to GitHub users Arnold Robbins (arnoldrobbins),
+ Cody Mello (melloc) and Christoph Junghans (junghans).
+ PR numbers: 13-21, 23, 24, 27.
+
Oct 25, 2018:
Added test in maketab.c to prevent generating a proctab entry
for YYSTYPE_IS_DEFINED. It was harmless but some gcc settings
diff --git a/bugs-fixed/README b/bugs-fixed/README
index 9c644f9..2f27c10 100644
--- a/bugs-fixed/README
+++ b/bugs-fixed/README
@@ -51,4 +51,7 @@ array passed as the second argument, then split() would previously read
from the freed memory and possibly produce incorrect results (depending
on the system's malloc()/free() behaviour.)
-
+15. getline-numeric: The `getline xx < file' syntax did not check if
+values were numeric, in discordance from POSIX. Test case adapted from
+one posted by Ben Bacarisse <ben.usenet@bsb.me.uk> in comp.lang.awk,
+January 2019.
diff --git a/bugs-fixed/getline-numeric.awk b/bugs-fixed/getline-numeric.awk
new file mode 100644
index 0000000..5571a95
--- /dev/null
+++ b/bugs-fixed/getline-numeric.awk
@@ -0,0 +1,6 @@
+{
+ print $0, ($0 <= 50 ? "<=" : ">"), 50
+ getline dd < ARGV[1]
+ print dd, (dd <= 50 ? "<=" : ">"), 50
+ if (dd == $0) print "same"
+}
diff --git a/bugs-fixed/getline-numeric.bad b/bugs-fixed/getline-numeric.bad
new file mode 100644
index 0000000..d911c77
--- /dev/null
+++ b/bugs-fixed/getline-numeric.bad
@@ -0,0 +1,3 @@
+120 > 50
+120 <= 50
+same
diff --git a/bugs-fixed/getline-numeric.in b/bugs-fixed/getline-numeric.in
new file mode 100644
index 0000000..52bd8e4
--- /dev/null
+++ b/bugs-fixed/getline-numeric.in
@@ -0,0 +1 @@
+120
diff --git a/bugs-fixed/getline-numeric.ok b/bugs-fixed/getline-numeric.ok
new file mode 100644
index 0000000..f7efd3d
--- /dev/null
+++ b/bugs-fixed/getline-numeric.ok
@@ -0,0 +1,3 @@
+120 > 50
+120 > 50
+same
diff --git a/main.c b/main.c
index 1c38a1e..b5c7c9f 100644
--- a/main.c
+++ b/main.c
@@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/
-const char *version = "version 20180827";
+const char *version = "version 20190125";
#define DEBUG
#include <stdio.h>
diff --git a/run.c b/run.c
index ce30e93..2dfb3e6 100644
--- a/run.c
+++ b/run.c
@@ -425,6 +425,10 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */
} else if (a[0] != NULL) { /* getline var <file */
x = execute(a[0]);
setsval(x, buf);
+ if (is_number(x->sval)) {
+ x->fval = atof(x->sval);
+ x->tval |= NUM;
+ }
tempfree(x);
} else { /* getline <file */
setsval(fldtab[0], buf);
@@ -440,6 +444,10 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */
n = getrec(&buf, &bufsize, 0);
x = execute(a[0]);
setsval(x, buf);
+ if (is_number(x->sval)) {
+ x->fval = atof(x->sval);
+ x->tval |= NUM;
+ }
tempfree(x);
}
}