Make getline POSIX compliant w.r.t. numeric strings.
This commit is contained in:
parent
c3c7c1370e
commit
9dbd1f1de3
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
2018-08-29 Arnold D. Robbins <arnold@skeeve.com>
|
||||||
|
|
||||||
* REGRESS: Check for existence of a.out. If not there, run
|
* REGRESS: Check for existence of a.out. If not there, run
|
||||||
|
@ -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
|
from the freed memory and possibly produce incorrect results (depending
|
||||||
on the system's malloc()/free() behaviour.)
|
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.
|
||||||
|
6
bugs-fixed/getline-numeric.awk
Normal file
6
bugs-fixed/getline-numeric.awk
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
print $0, ($0 <= 50 ? "<=" : ">"), 50
|
||||||
|
getline dd < ARGV[1]
|
||||||
|
print dd, (dd <= 50 ? "<=" : ">"), 50
|
||||||
|
if (dd == $0) print "same"
|
||||||
|
}
|
6
bugs-fixed/getline-numeric.bad
Normal file
6
bugs-fixed/getline-numeric.bad
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
120 > 50
|
||||||
|
120 <= 50
|
||||||
|
same
|
||||||
|
120 > 50
|
||||||
|
120 <= 50
|
||||||
|
same
|
2
bugs-fixed/getline-numeric.in
Normal file
2
bugs-fixed/getline-numeric.in
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
120
|
||||||
|
120
|
6
bugs-fixed/getline-numeric.ok
Normal file
6
bugs-fixed/getline-numeric.ok
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
120 > 50
|
||||||
|
120 > 50
|
||||||
|
same
|
||||||
|
120 > 50
|
||||||
|
120 > 50
|
||||||
|
same
|
8
run.c
8
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 */
|
} else if (a[0] != NULL) { /* getline var <file */
|
||||||
x = execute(a[0]);
|
x = execute(a[0]);
|
||||||
setsval(x, buf);
|
setsval(x, buf);
|
||||||
|
if (is_number(x->sval)) {
|
||||||
|
x->fval = atof(x->sval);
|
||||||
|
x->tval |= NUM;
|
||||||
|
}
|
||||||
tempfree(x);
|
tempfree(x);
|
||||||
} else { /* getline <file */
|
} else { /* getline <file */
|
||||||
setsval(fldtab[0], buf);
|
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);
|
n = getrec(&buf, &bufsize, 0);
|
||||||
x = execute(a[0]);
|
x = execute(a[0]);
|
||||||
setsval(x, buf);
|
setsval(x, buf);
|
||||||
|
if (is_number(x->sval)) {
|
||||||
|
x->fval = atof(x->sval);
|
||||||
|
x->tval |= NUM;
|
||||||
|
}
|
||||||
tempfree(x);
|
tempfree(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user