From 7cae39dfa53e17981990f649a2f6b4c1ba856112 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 6 Oct 2019 22:34:20 +0300 Subject: [PATCH] Make RS as regexp work without ifdef. Add doc, bump version. --- ChangeLog | 10 +++++++++- FIXES | 4 ++++ awk.1 | 5 +++++ lib.c | 4 ---- main.c | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7010084..e41842c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-10-06 Arnold D. Robbins + + * lib.c (readrec): Allow RS a regular expression. Imported + the code from the NetBSD awk. + * b.c (fnematch): New function for implementing the feature. + * awk.1: Updated. + * main.c (version): Updated. + 2019-06-24 Arnold D. Robbins * makefile: Revise to take into account there is no more awktest.tar, @@ -18,7 +26,7 @@ * b.c (relex): Count parentheses and treat umatched right paren as a literal character. * awktest.tar (testdir/T.re): Added a test case. - * main.c (version): Upated. + * main.c (version): Updated. 2019-05-29 Arnold D. Robbins diff --git a/FIXES b/FIXES index 9cd8d15..5a85d4a 100644 --- a/FIXES +++ b/FIXES @@ -25,6 +25,10 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. +October 6, 2019: + Import code from NetBSD awk that implements RS as a regular + expression. + September 10, 2019: Fixes for various array / memory overruns found via gcc's -fsanitize=unknown. Thanks to Alexander Richardson (Github diff --git a/awk.1 b/awk.1 index 4757914..5c05b01 100644 --- a/awk.1 +++ b/awk.1 @@ -478,6 +478,11 @@ the length of a string matched by .TP .B RS input record separator (default newline). +If empty, blank lines separate records. +If more than one character long, +.B RS +is treated as a regular expression, and records are +separated by text matching the expression. .TP .B RSTART the start position of a string matched by diff --git a/lib.c b/lib.c index b08f0ba..8a6b684 100644 --- a/lib.c +++ b/lib.c @@ -209,7 +209,6 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf * int bufsize = *pbufsize; char *rs = getsval(rsloc); -#ifdef RS_AS_REGEXP if (*rs && rs[1]) { int found; @@ -218,7 +217,6 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf * if (found) *patbeg = 0; } else { -#endif if ((sep = *rs) == 0) { sep = '\n'; while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ @@ -247,9 +245,7 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf * if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3")) FATAL("input record `%.30s...' too long", buf); *rr = 0; -#ifdef RS_AS_REGEXP } -#endif *pbuf = buf; *pbufsize = bufsize; isrec = *buf || !feof(inf); diff --git a/main.c b/main.c index 6ad7710..ed64fdf 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 20190910"; +const char *version = "version 20191006"; #define DEBUG #include