aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-08-15 20:58:53 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-08-15 20:58:53 +0000
commit621553dad4793230b9394ddf827a80080beff75d (patch)
tree5601379d3e2c5598d1d6c0ebcf18592801901b1b
parenta3a73fd48dd36dda96772c05563cfa65a0f98bf0 (diff)
parent2aef6cef714686121a677534bd9fb563f92ed580 (diff)
downloadplatform_external_one-true-awk-621553dad4793230b9394ddf827a80080beff75d.tar.gz
platform_external_one-true-awk-621553dad4793230b9394ddf827a80080beff75d.tar.bz2
platform_external_one-true-awk-621553dad4793230b9394ddf827a80080beff75d.zip
Upgrade one-true-awk to 9c63cb6ccd303fb64b703ff0836400f204078621 am: 2aef6cef71
Original change: https://android-review.googlesource.com/c/platform/external/one-true-awk/+/1395714 Change-Id: Ib3cd6d13cc36a5e9a6447d3db55faa084c99e62a
-rw-r--r--.gitignore2
-rw-r--r--Android.bp20
-rw-r--r--ChangeLog12
-rw-r--r--FIXES17
-rw-r--r--METADATA6
-rw-r--r--b.c4
-rw-r--r--bugs-fixed/pfile-overflow.awk1
-rw-r--r--bugs-fixed/pfile-overflow.ok4
-rw-r--r--bugs-fixed/rs_underflow.awk1
-rw-r--r--bugs-fixed/rs_underflow.in1
-rw-r--r--bugs-fixed/rs_underflow.ok1
-rw-r--r--lex.c4
-rw-r--r--lib.c1
-rw-r--r--main.c5
-rw-r--r--makefile43
-rw-r--r--maketab.c6
-rw-r--r--parse.c2
-rw-r--r--run.c32
-rwxr-xr-xtestdir/T.errmsg4
-rw-r--r--tran.c7
20 files changed, 103 insertions, 70 deletions
diff --git a/.gitignore b/.gitignore
index f469d21..c426b13 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,4 @@
a.out
maketab
proctab.c
-ytab.c
-ytab.h
*.o
diff --git a/Android.bp b/Android.bp
index def4247..1fd1ac5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -26,9 +26,9 @@ cc_defaults {
}
genrule {
- name: "ytab.c",
- cmd: "M4=$(location m4) $(location bison) -y --output=$(genDir)/ytab.c $(in)",
- out: ["ytab.c"],
+ name: "awkgram.tab.c",
+ cmd: "M4=$(location m4) $(location bison) -y --output=$(genDir)/awkgram.tab.c $(in)",
+ out: ["awkgram.tab.c"],
srcs: ["awkgram.y"],
tools: [
"bison",
@@ -37,9 +37,9 @@ genrule {
}
genrule {
- name: "ytab.h",
- cmd: "M4=$(location m4) $(location bison) -y --defines=$(genDir)/ytab.h --output=$(genDir)/ytab.c $(in)",
- out: ["ytab.h"],
+ name: "awkgram.tab.h",
+ cmd: "M4=$(location m4) $(location bison) -y --defines=$(genDir)/awkgram.tab.h --output=$(genDir)/awkgram.tab.c $(in)",
+ out: ["awkgram.tab.h"],
srcs: ["awkgram.y"],
tools: [
"bison",
@@ -52,20 +52,20 @@ genrule {
tools: ["awk-maketab"],
cmd: "$(location awk-maketab) $(in) > $(genDir)/proctab.c",
out: ["proctab.c"],
- srcs: [":ytab.h"],
+ srcs: [":awkgram.tab.h"],
}
cc_binary_host {
name: "awk-maketab",
defaults: ["awk-flags"],
- generated_headers: ["ytab.h"],
+ generated_headers: ["awkgram.tab.h"],
srcs: ["maketab.c"],
}
cc_defaults {
name: "awk-defaults",
defaults: ["awk-flags"],
- generated_headers: ["ytab.h"],
+ generated_headers: ["awkgram.tab.h"],
srcs: [
"b.c",
"lex.c",
@@ -75,7 +75,7 @@ cc_defaults {
":proctab.c",
"run.c",
"tran.c",
- ":ytab.c",
+ ":awkgram.tab.c",
],
}
diff --git a/ChangeLog b/ChangeLog
index 4e95699..6ce9417 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2020-07-30 Arnold D. Robbins <arnold@skeeve.com>
+
+ By fiat, we use bison for $(YACC). Trying to accommodate
+ different versions didn't work.
+
+ * makefile: Significant cleanup. Replace all ytab* references
+ with awkgram.tab.* and simplify definition of YACC.
+ * .gitignore: Remove ytab* references.
+ * b.c, lex.c, maketab.c, parse.c, run.c: Replace include of ytab.h
+ with awkgram.tab.h.
+ * lib.c, main.c, tran.c: Remove include of ytab.h, wasn't needed.
+
2020-01-20 Arnold D. Robbins <arnold@skeeve.com>
* run.c (openfile): Set the close-on-exec flag for file
diff --git a/FIXES b/FIXES
index 9516a36..0bfdccd 100644
--- a/FIXES
+++ b/FIXES
@@ -25,6 +25,23 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the AWK book
was sent to the printers in August, 1987.
+August 7, 2020:
+ Merge PR #93, which adds casts to (void*) for debug prints
+ using the %p format specifier. Thanks to GitHub user YongHaoWu
+ ("Chris") for the fixes.
+
+August 4, 2020:
+ In run.c, use non-restartable multibyte routines to attain
+ portability to DJGPP. Should fix Issue 92. Thanks to Albert Wik
+ for the report and to Todd Miller for the suggested fix.
+
+July 30, 2020:
+ Merge PRs 88-91 which fix small bugs. Thanks to Todd Miller and
+ Tim van der Molen for the fixes.
+
+ In order to make life easier, we move exclusively to bison
+ as the parser generator.
+
July 2, 2020:
Merge PRs 85 and 86 which fix regressions. Thanks to
Tim van der Molen for the fixes.
diff --git a/METADATA b/METADATA
index b15dff8..d9354a6 100644
--- a/METADATA
+++ b/METADATA
@@ -5,11 +5,11 @@ third_party {
type: GIT
value: "https://github.com/onetrueawk/awk.git"
}
- version: "2a4146ec3027d12e375209e03ed1c5a9ab230da4"
+ version: "9c63cb6ccd303fb64b703ff0836400f204078621"
license_type: NOTICE
last_upgrade_date {
year: 2020
- month: 7
- day: 10
+ month: 8
+ day: 13
}
}
diff --git a/b.c b/b.c
index c167b50..776a806 100644
--- a/b.c
+++ b/b.c
@@ -32,7 +32,7 @@ THIS SOFTWARE.
#include <string.h>
#include <stdlib.h>
#include "awk.h"
-#include "ytab.h"
+#include "awkgram.tab.h"
#define MAXLIN 22
@@ -684,7 +684,7 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
FATAL("stream '%.30s...' too long", buf);
buf[k++] = (c = getc(f)) != EOF ? c : 0;
}
- c = buf[j];
+ c = (uschar)buf[j];
/* assert(c < NCHARS); */
if ((ns = pfa->gototab[s][c]) != 0)
diff --git a/bugs-fixed/pfile-overflow.awk b/bugs-fixed/pfile-overflow.awk
new file mode 100644
index 0000000..b7d5379
--- /dev/null
+++ b/bugs-fixed/pfile-overflow.awk
@@ -0,0 +1 @@
+\ \ No newline at end of file
diff --git a/bugs-fixed/pfile-overflow.ok b/bugs-fixed/pfile-overflow.ok
new file mode 100644
index 0000000..a0de50f
--- /dev/null
+++ b/bugs-fixed/pfile-overflow.ok
@@ -0,0 +1,4 @@
+../a.out: syntax error at source line 1 source file pfile-overflow.awk
+ context is
+ >>> <<<
+../a.out: bailing out at source line 1 source file pfile-overflow.awk
diff --git a/bugs-fixed/rs_underflow.awk b/bugs-fixed/rs_underflow.awk
new file mode 100644
index 0000000..4cf1702
--- /dev/null
+++ b/bugs-fixed/rs_underflow.awk
@@ -0,0 +1 @@
+BEGIN { RS="zx" } { print $1 }
diff --git a/bugs-fixed/rs_underflow.in b/bugs-fixed/rs_underflow.in
new file mode 100644
index 0000000..74c8035
--- /dev/null
+++ b/bugs-fixed/rs_underflow.in
@@ -0,0 +1 @@
diff --git a/bugs-fixed/rs_underflow.ok b/bugs-fixed/rs_underflow.ok
new file mode 100644
index 0000000..74c8035
--- /dev/null
+++ b/bugs-fixed/rs_underflow.ok
@@ -0,0 +1 @@
diff --git a/lex.c b/lex.c
index 0d2142c..73cdddb 100644
--- a/lex.c
+++ b/lex.c
@@ -27,7 +27,7 @@ THIS SOFTWARE.
#include <string.h>
#include <ctype.h>
#include "awk.h"
-#include "ytab.h"
+#include "awkgram.tab.h"
extern YYSTYPE yylval;
extern bool infunc;
@@ -148,7 +148,7 @@ static int gettok(char **pbuf, int *psz) /* get next input token */
strtod(buf, &rem); /* parse the number */
if (rem == buf) { /* it wasn't a valid number at all */
buf[1] = 0; /* return one character as token */
- retc = buf[0]; /* character is its own type */
+ retc = (uschar)buf[0]; /* character is its own type */
unputstr(rem+1); /* put rest back for later */
} else { /* some prefix was a number */
unputstr(rem); /* put rest back for later */
diff --git a/lib.c b/lib.c
index ab3ae53..92f28f5 100644
--- a/lib.c
+++ b/lib.c
@@ -31,7 +31,6 @@ THIS SOFTWARE.
#include <stdarg.h>
#include <limits.h>
#include "awk.h"
-#include "ytab.h"
char EMPTY[] = { '\0' };
FILE *infile = NULL;
diff --git a/main.c b/main.c
index 535f1aa..0f3c4a7 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 20200702";
+const char *version = "version 20200807";
#define DEBUG
#include <stdio.h>
@@ -32,7 +32,6 @@ const char *version = "version 20200702";
#include <string.h>
#include <signal.h>
#include "awk.h"
-#include "ytab.h"
extern char **environ;
extern int nfields;
@@ -256,7 +255,7 @@ int pgetc(void) /* get 1 character from awk program */
char *cursource(void) /* current source file name */
{
if (npfile > 0)
- return pfile[curpfile];
+ return pfile[curpfile < npfile ? curpfile : curpfile - 1];
else
return NULL;
}
diff --git a/makefile b/makefile
index d7d4bd2..5133698 100644
--- a/makefile
+++ b/makefile
@@ -34,54 +34,43 @@ CFLAGS = -O2
HOSTCC = gcc -g -Wall -pedantic -Wcast-qual
CC = $(HOSTCC) # change this is cross-compiling.
-# yacc options. pick one; this varies a lot by system.
-#YFLAGS = -d -S
+# By fiat, to make our lives easier, yacc is now defined to be bison.
+# If you want something else, you're on your own.
YACC = bison -d
-#YACC = yacc -d
-# -S uses sprintf in yacc parser instead of sprint
OFILES = b.o main.o parse.o proctab.o tran.o lib.o run.o lex.o
-SOURCE = awk.h ytab.c ytab.h proto.h awkgram.y lex.c b.c main.c \
+SOURCE = awk.h awkgram.tab.c awkgram.tab.h proto.h awkgram.y lex.c b.c main.c \
maketab.c parse.c lib.c run.c tran.c proctab.c
LISTING = awk.h proto.h awkgram.y lex.c b.c main.c maketab.c parse.c \
lib.c run.c tran.c
-SHIP = README LICENSE FIXES $(SOURCE) ytab[ch].bak makefile \
+SHIP = README LICENSE FIXES $(SOURCE) awkgram.tab.[ch].bak makefile \
awk.1
-a.out: ytab.o $(OFILES)
- $(CC) $(CFLAGS) ytab.o $(OFILES) $(ALLOC) -lm
+a.out: awkgram.tab.o $(OFILES)
+ $(CC) $(CFLAGS) awkgram.tab.o $(OFILES) $(ALLOC) -lm
-$(OFILES): awk.h ytab.h proto.h
+$(OFILES): awk.h awkgram.tab.h proto.h
-# Clear dependency for parallel build: (make -j)
-# Depending if we used yacc or bison we can be generating different names
-# ({awkgram,y}.tab.{c,h}) so try to move both. We could be using -p to
-# specify the output prefix, but older yacc's don't support it.
-ytab.c ytab.h: awk.h proto.h awkgram.y
+awkgram.tab.c awkgram.tab.h: awk.h proto.h awkgram.y
$(YACC) $(YFLAGS) awkgram.y
- -@for i in c h; do for j in awkgram y; do \
- if [ -f "$$j.tab.$$i" ]; then mv $$j.tab.$$i ytab.$$i; fi; \
- done; done
-
-ytab.h: ytab.c
proctab.c: maketab
- ./maketab ytab.h >proctab.c
+ ./maketab awkgram.tab.h >proctab.c
-maketab: ytab.h maketab.c
+maketab: awkgram.tab.h maketab.c
$(HOSTCC) $(CFLAGS) maketab.c -o maketab
bundle:
- @cp ytab.h ytabh.bak
- @cp ytab.c ytabc.bak
+ @cp awkgram.tab.h awkgram.tab.h.bak
+ @cp awkgram.tab.c awkgram.tab.c.bak
@bundle $(SHIP)
tar:
- @cp ytab.h ytabh.bak
- @cp ytab.c ytabc.bak
+ @cp awkgram.tab.h awkgram.tab.h.bak
+ @cp awkgram.tab.c awkgram.tab.c.bak
@bundle $(SHIP) >awk.shar
@tar cf awk.tar $(SHIP)
gzip awk.tar
@@ -110,7 +99,7 @@ clean: testclean
rm -f a.out *.o *.obj maketab maketab.exe *.bb *.bbg *.da *.gcov *.gcno *.gcda # proctab.c
cleaner: testclean
- rm -f a.out *.o *.obj maketab maketab.exe *.bb *.bbg *.da *.gcov *.gcno *.gcda proctab.c ytab*
+ rm -f a.out *.o *.obj maketab maketab.exe *.bb *.bbg *.da *.gcov *.gcno *.gcda proctab.c awkgram.tab.*
# This is a bit of a band-aid until we can invest some more time
# in the test suite.
@@ -119,4 +108,4 @@ testclean:
glop glop1 glop2 lilly.diff tempbig tempsmall time
# For the habits of GNU maintainers:
-distclean: clean
+distclean: cleaner
diff --git a/maketab.c b/maketab.c
index 2384d51..433541e 100644
--- a/maketab.c
+++ b/maketab.c
@@ -25,14 +25,14 @@ THIS SOFTWARE.
/*
* this program makes the table to link function names
* and type indices that is used by execute() in run.c.
- * it finds the indices in ytab.h, produced by yacc.
+ * it finds the indices in awkgram.tab.h, produced by bison.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "awk.h"
-#include "ytab.h"
+#include "awkgram.tab.h"
struct xx
{ int token;
@@ -122,7 +122,7 @@ int main(int argc, char *argv[])
printf("#include <stdio.h>\n");
printf("#include \"awk.h\"\n");
- printf("#include \"ytab.h\"\n\n");
+ printf("#include \"awkgram.tab.h\"\n\n");
if (argc != 2) {
fprintf(stderr, "usage: maketab YTAB_H\n");
diff --git a/parse.c b/parse.c
index b13e0c4..1466c38 100644
--- a/parse.c
+++ b/parse.c
@@ -27,7 +27,7 @@ THIS SOFTWARE.
#include <string.h>
#include <stdlib.h>
#include "awk.h"
-#include "ytab.h"
+#include "awkgram.tab.h"
Node *nodealloc(int n)
{
diff --git a/run.c b/run.c
index 98787f1..01b4597 100644
--- a/run.c
+++ b/run.c
@@ -38,7 +38,7 @@ THIS SOFTWARE.
#include <sys/types.h>
#include <sys/wait.h>
#include "awk.h"
-#include "ytab.h"
+#include "awkgram.tab.h"
static void stdinit(void);
static void flush_all(void);
@@ -119,7 +119,7 @@ int adjbuf(char **pbuf, int *psiz, int minlen, int quantum, char **pbptr,
if (rminlen)
minlen += quantum - rminlen;
tbuf = realloc(*pbuf, minlen);
- DPRINTF("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, *pbuf, tbuf);
+ DPRINTF("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, (void*)*pbuf, (void*)tbuf);
if (tbuf == NULL) {
if (whatrtn)
FATAL("out of memory in %s", whatrtn);
@@ -1521,7 +1521,6 @@ static char *nawk_convert(const char *s, int (*fun_c)(int),
char *pbuf = NULL;
const char *ps = NULL;
size_t n = 0;
- mbstate_t mbs, mbs2;
wchar_t wc;
size_t sz = MB_CUR_MAX;
@@ -1536,17 +1535,24 @@ static char *nawk_convert(const char *s, int (*fun_c)(int),
/* upper/lower character may be shorter/longer */
buf = tostringN(s, strlen(s) * sz + 1);
- memset(&mbs, 0, sizeof(mbs));
- memset(&mbs2, 0, sizeof(mbs2));
+ (void) mbtowc(NULL, NULL, 0); /* reset internal state */
+ /*
+ * Reset internal state here too.
+ * Assign result to avoid a compiler warning. (Casting to void
+ * doesn't work.)
+ * Increment said variable to avoid a different warning.
+ */
+ int unused = wctomb(NULL, L'\0');
+ unused++;
ps = s;
pbuf = buf;
- while (n = mbrtowc(&wc, ps, sz, &mbs),
+ while (n = mbtowc(&wc, ps, sz),
n > 0 && n != (size_t)-1 && n != (size_t)-2)
{
ps += n;
- n = wcrtomb(pbuf, fun_wc(wc), &mbs2);
+ n = wctomb(pbuf, fun_wc(wc));
if (n == (size_t)-1)
FATAL("illegal wide character %s", s);
@@ -1837,7 +1843,7 @@ const char *filename(FILE *fp)
Cell *x;
size_t i;
bool stat;
-
+
x = execute(a[0]);
getsval(x);
stat = true;
@@ -1846,7 +1852,10 @@ const char *filename(FILE *fp)
continue;
if (ferror(files[i].fp))
FATAL("i/o error occurred on %s", files[i].fname);
- if (files[i].mode == '|' || files[i].mode == LE)
+ if (files[i].fp == stdin || files[i].fp == stdout ||
+ files[i].fp == stderr)
+ stat = freopen("/dev/null", "r+", files[i].fp) == NULL;
+ else if (files[i].mode == '|' || files[i].mode == LE)
stat = pclose(files[i].fp) == -1;
else
stat = fclose(files[i].fp) == EOF;
@@ -1856,6 +1865,7 @@ const char *filename(FILE *fp)
xfree(files[i].fname);
files[i].fname = NULL; /* watch out for ref thru this */
files[i].fp = NULL;
+ break;
}
tempfree(x);
x = gettemp();
@@ -1873,8 +1883,12 @@ void closeall(void)
continue;
if (ferror(files[i].fp))
FATAL( "i/o error occurred on %s", files[i].fname );
+ if (files[i].fp == stdin)
+ continue;
if (files[i].mode == '|' || files[i].mode == LE)
stat = pclose(files[i].fp) == -1;
+ else if (files[i].fp == stdout || files[i].fp == stderr)
+ stat = fflush(files[i].fp) == EOF;
else
stat = fclose(files[i].fp) == EOF;
if (stat)
diff --git a/testdir/T.errmsg b/testdir/T.errmsg
index fcaaf9b..bf2fd6a 100755
--- a/testdir/T.errmsg
+++ b/testdir/T.errmsg
@@ -186,7 +186,7 @@ BEGIN { foo() }
this should print a BAD message
BEGIN { print }
-!!!
+!!!!
echo ' running tests in foo.sh'
@@ -213,5 +213,3 @@ grep 'print | is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print | unsafe'
$awk -safe 'BEGIN {system("date")}' >foo 2>foo2
grep 'system is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg system unsafe'
-
-!!!!
diff --git a/tran.c b/tran.c
index f0a0a09..ee5facb 100644
--- a/tran.c
+++ b/tran.c
@@ -29,7 +29,6 @@ THIS SOFTWARE.
#include <string.h>
#include <stdlib.h>
#include "awk.h"
-#include "ytab.h"
#define FULLTAB 2 /* rehash when table gets this x full */
#define GROWTAB 4 /* grow table by this factor */
@@ -362,7 +361,7 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
fldno = atoi(vp->nval);
if (fldno > *NF)
newfld(fldno);
- DPRINTF("setting field %d to %s (%p)\n", fldno, s, s);
+ DPRINTF("setting field %d to %s (%p)\n", fldno, s, (const void*)s);
} else if (isrec(vp)) {
donefld = false; /* mark $1... invalid */
donerec = true;
@@ -379,7 +378,7 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
vp->fmt = NULL;
setfree(vp);
DPRINTF("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
- (void*)vp, NN(vp->nval), t, t, vp->tval, donerec, donefld);
+ (void*)vp, NN(vp->nval), t, (void*)t, vp->tval, donerec, donefld);
vp->sval = t;
if (&vp->fval == NF) {
donerec = false; /* mark $0 invalid */
@@ -493,7 +492,7 @@ static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cel
}
done:
DPRINTF("getsval %p: %s = \"%s (%p)\", t=%o\n",
- (void*)vp, NN(vp->nval), vp->sval, vp->sval, vp->tval);
+ (void*)vp, NN(vp->nval), vp->sval, (void*)vp->sval, vp->tval);
return(vp->sval);
}