Skip to content

Commit

Permalink
Merge pull request lh3#31 from arnoldrobbins/master
Browse files Browse the repository at this point in the history
Make getline handle numeric strings, and update FIXES
  • Loading branch information
onetrueawk authored Mar 3, 2019
2 parents 115fac0 + f25e845 commit 1164fa7
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2019-01-26 Arnold D. Robbins <[email protected]>

* main.c (version): Updated.

2019-01-25 Arnold D. Robbins <[email protected]>

* 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 <[email protected]>

* REGRESS: Check for existence of a.out. If not there, run
Expand Down
10 changes: 10 additions & 0 deletions FIXES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion bugs-fixed/README
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> in comp.lang.awk,
January 2019.
6 changes: 6 additions & 0 deletions bugs-fixed/getline-numeric.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
print $0, ($0 <= 50 ? "<=" : ">"), 50
getline dd < ARGV[1]
print dd, (dd <= 50 ? "<=" : ">"), 50
if (dd == $0) print "same"
}
3 changes: 3 additions & 0 deletions bugs-fixed/getline-numeric.bad
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
120 > 50
120 <= 50
same
1 change: 1 addition & 0 deletions bugs-fixed/getline-numeric.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
120
3 changes: 3 additions & 0 deletions bugs-fixed/getline-numeric.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
120 > 50
120 > 50
same
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 8 additions & 0 deletions run.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 1164fa7

Please sign in to comment.