From d9ecc40d45e66a0a0b11c895967c9bb8f737e659 Mon Sep 17 00:00:00 2001 From: millert Date: Tue, 28 Nov 2023 20:54:38 +0000 Subject: [PATCH] Update awk to the Nov 27, 2023 version. --- usr.bin/awk/FIXES | 6 ++++++ usr.bin/awk/README.md | 2 -- usr.bin/awk/lib.c | 4 ++-- usr.bin/awk/main.c | 8 ++++++-- usr.bin/awk/run.c | 16 +++++++++------- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/usr.bin/awk/FIXES b/usr.bin/awk/FIXES index 52f49e3eed0..d77bec29c62 100644 --- a/usr.bin/awk/FIXES +++ b/usr.bin/awk/FIXES @@ -25,6 +25,12 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the second edition of the AWK book was published in September 2023. +Nov 27, 2023: + Fix exit status of system on MacOS. update to REGRESS. + Thanks to Arnold Robbins. + Fix inconsistent handling of -F and --csv, and loss of csv + mode when FS is set. Thanks to Wilbert van der Poel. + Nov 24, 2023: Fix issue #199: gototab improvements to dynamically resize the table, qsort and bsearch to improve the lookup speed as the diff --git a/usr.bin/awk/README.md b/usr.bin/awk/README.md index 89e0abfe465..e83be10d55a 100644 --- a/usr.bin/awk/README.md +++ b/usr.bin/awk/README.md @@ -32,8 +32,6 @@ Aribtrary characters may be included with `\u` followed by 1 to 8 hexadecimal di ### Regular expressions ### Regular expressions may include UTF-8 code points, including `\u`. -Character classes are likely to be limited to about 256 characters -when expanded. ### CSV ### diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index f3c4b5668a7..bb49f8e35bf 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.54 2023/10/30 17:52:54 millert Exp $ */ +/* $OpenBSD: lib.c,v 1.55 2023/11/28 20:54:38 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -396,7 +396,7 @@ void fldbld(void) /* create fields from current record */ i = 0; /* number of fields accumulated here */ if (inputFS == NULL) /* make sure we have a copy of FS */ savefs(); - if (strlen(inputFS) > 1) { /* it's a regular expression */ + if (!CSV && strlen(inputFS) > 1) { /* it's a regular expression */ i = refldbld(r, inputFS); } else if (!CSV && (sep = *inputFS) == ' ') { /* default whitespace */ for (i = 0; ; ) { diff --git a/usr.bin/awk/main.c b/usr.bin/awk/main.c index a2f53635351..3ec64332ff5 100644 --- a/usr.bin/awk/main.c +++ b/usr.bin/awk/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.66 2023/11/25 16:31:33 millert Exp $ */ +/* $OpenBSD: main.c,v 1.67 2023/11/28 20:54:38 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -23,7 +23,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ****************************************************************/ -const char *version = "version 20231124"; +const char *version = "version 20231127"; #define DEBUG #include @@ -180,6 +180,8 @@ int main(int argc, char *argv[]) } if (strcmp(argv[1], "--csv") == 0) { /* turn on csv input processing */ CSV = true; + if (fs) + WARNING("danger: don't set FS when --csv is in effect"); argc--; argv++; continue; @@ -201,6 +203,8 @@ int main(int argc, char *argv[]) break; case 'F': /* set field separator */ fs = setfs(getarg(&argc, &argv, "no field separator")); + if (CSV) + WARNING("danger: don't set FS when --csv is in effect"); break; case 'v': /* -v a=1 to be done NOW. one -v for each */ vn = getarg(&argc, &argv, "no variable name"); diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 6114768edf1..af1153f6b7d 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.82 2023/11/25 16:31:33 millert Exp $ */ +/* $OpenBSD: run.c,v 1.83 2023/11/28 20:54:38 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -2069,6 +2069,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis int status = 0; time_t tv; struct tm *tm, tmbuf; + int estatus = 0; t = ptoi(a[0]); x = execute(a[1]); @@ -2169,20 +2170,21 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis break; case FSYSTEM: fflush(stdout); /* in case something is buffered already */ - status = system(getsval(x)); - u = status; + estatus = status = system(getsval(x)); if (status != -1) { if (WIFEXITED(status)) { - u = WEXITSTATUS(status); + estatus = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { - u = WTERMSIG(status) + 256; + estatus = WTERMSIG(status) + 256; #ifdef WCOREDUMP if (WCOREDUMP(status)) - u += 256; + estatus += 256; #endif } else /* something else?!? */ - u = 0; + estatus = 0; } + /* else estatus was set to -1 */ + u = estatus; break; case FRAND: /* random() returns numbers in [0..2^31-1] -- 2.20.1