diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f469d21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +a.out +maketab +proctab.c +ytab.c +ytab.h +*.o diff --git a/ChangeLog b/ChangeLog index 59d4b07..7516cd6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2019-01-26 Arnold D. Robbins + + * main.c (version): Updated. + +2019-01-25 Arnold D. Robbins + + * 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 * REGRESS: Check for existence of a.out. If not there, run diff --git a/FIXES b/FIXES index eb3b84f..2b33377 100644 --- a/FIXES +++ b/FIXES @@ -25,11 +25,21 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. -Jan 23, 2019: +Mar 5, 2019: Added support for POSIX-standard interval expressions (a.k.a. bounds, a.k.a. repetition expressions) in regular expressions, backported (via NetBSD) from Apple awk-24 (20070501). +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/b.c b/b.c index 94de52e..37ea0a5 100644 --- a/b.c +++ b/b.c @@ -27,6 +27,7 @@ THIS SOFTWARE. #define DEBUG #include +#include #include #include #include @@ -970,7 +971,7 @@ rescan: * not without first adapting the entire * program to track each string's length. */ - for (i = 1; i < NCHARS; i++) { + for (i = 1; i <= UCHAR_MAX; i++) { if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, "relex2")) FATAL("out of space for reg expr %.10s...", lastre); if (cc->cc_func(i)) { 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 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 ef5c311..f06e734 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 20190123"; +const char *version = "version 20190305"; #define DEBUG #include diff --git a/makefile b/makefile index 3f3c3c2..a4f1b8a 100644 --- a/makefile +++ b/makefile @@ -67,7 +67,7 @@ y%.c y%.h: awk.h proto.h awkgram.y ytab.h: ytab.c proctab.c: maketab - ./maketab >proctab.c + ./maketab ytab.h >proctab.c maketab: ytab.h maketab.c $(CC) $(CFLAGS) maketab.c -o maketab diff --git a/maketab.c b/maketab.c index bb8e317..dbe3d24 100644 --- a/maketab.c +++ b/maketab.c @@ -125,8 +125,12 @@ int main(int argc, char *argv[]) for (i = SIZE; --i >= 0; ) names[i] = ""; - if ((fp = fopen("ytab.h", "r")) == NULL) { - fprintf(stderr, "maketab can't open ytab.h!\n"); + if (argc != 2) { + fprintf(stderr, "usage: maketab YTAB_H\n"); + exit(1); + } + if ((fp = fopen(argv[1], "r")) == NULL) { + fprintf(stderr, "maketab can't open %s!\n", argv[1]); exit(1); } printf("static char *printname[%d] = {\n", SIZE); 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 sval)) { + x->fval = atof(x->sval); + x->tval |= NUM; + } tempfree(x); } else { /* getline sval)) { + x->fval = atof(x->sval); + x->tval |= NUM; + } tempfree(x); } }