shithub: trueawk

Download patch

ref: ee8484a4a2cb6ac3b263f4da0fe83cabf8683ddb
parent: 908be9c222c0b7da4bcc3b8724ebb11996993a69
author: Arnold D. Robbins <arnold@skeeve.com>
date: Mon Jan 22 02:45:31 EST 2024

Restore ability to compile with g++.

--- a/FIXES
+++ b/FIXES
@@ -25,6 +25,10 @@
 This file lists all bug fixes, changes, etc., made since the 
 second edition of the AWK book was published in September 2023.
 
+Jan 22, 2024:
+	Restore the ability to compile with g++. Thanks to
+	Arnold Robbins.
+
 Dec 24, 2023:
 	matchop dereference after free problem fix when the first
 	argument is a function call. thanks to Oguz Ismail Uysal.
--- a/b.c
+++ b/b.c
@@ -116,7 +116,7 @@
 static int get_gototab(fa*, int, int);
 static int set_gototab(fa*, int, int, int);
 static void clear_gototab(fa*, int);
-extern int u8_rune(int *, const uschar *);
+extern int u8_rune(int *, const char *);
 
 static int *
 intalloc(size_t n, const char *f)
@@ -416,7 +416,7 @@
 		FATAL("out of space for character class [%.10s...] 1", p);
 	bp = buf;
 	for (i = 0; *p != 0; ) {
-		n = u8_rune(&c, p);
+		n = u8_rune(&c, (const char *) p);
 		p += n;
 		if (c == '\\') {
 			c = quoted(&p);
@@ -424,7 +424,7 @@
 			if (*p != 0) {
 				c = bp[-1];
 				/* c2 = *p++; */
-				n = u8_rune(&c2, p);
+				n = u8_rune(&c2, (const char *) p);
 				p += n;
 				if (c2 == '\\')
 					c2 = quoted(&p); /* BUG: sets p, has to be u8 size */
@@ -618,7 +618,7 @@
 
 	key.ch = ch;
 	key.state = 0;	/* irrelevant */
-	item = bsearch(& key, f->gototab[state].entries,
+	item = (gtte *) bsearch(& key, f->gototab[state].entries,
 			f->gototab[state].inuse, sizeof(gtte),
 			entry_cmp);
 
@@ -662,7 +662,7 @@
 
 		key.ch = ch;
 		key.state = 0;	/* irrelevant */
-		item = bsearch(& key, f->gototab[state].entries,
+		item = (gtte *) bsearch(& key, f->gototab[state].entries,
 				f->gototab[state].inuse, sizeof(gtte),
 				entry_cmp);
 
@@ -710,7 +710,7 @@
 		return(1);
 	do {
 		/* assert(*p < NCHARS); */
-		n = u8_rune(&rune, p);
+		n = u8_rune(&rune, (const char *) p);
 		if ((ns = get_gototab(f, s, rune)) != 0)
 			s = ns;
 		else
@@ -743,7 +743,7 @@
 			if (f->out[s])		/* final state */
 				patlen = q-p;
 			/* assert(*q < NCHARS); */
-			n = u8_rune(&rune, q);
+			n = u8_rune(&rune, (const char *) q);
 			if ((ns = get_gototab(f, s, rune)) != 0)
 				s = ns;
 			else
@@ -774,7 +774,7 @@
 		s = 2;
 		if (*p == 0)
 			break;
-		n = u8_rune(&rune, p);
+		n = u8_rune(&rune, (const char *) p);
 		p += n;
 	} while (1); /* was *p++ */
 	return (0);
@@ -799,7 +799,7 @@
 			if (f->out[s])		/* final state */
 				patlen = q-p;
 			/* assert(*q < NCHARS); */
-			n = u8_rune(&rune, q);
+			n = u8_rune(&rune, (const char *) q);
 			if ((ns = get_gototab(f, s, rune)) != 0)
 				s = ns;
 			else
@@ -887,7 +887,7 @@
 			}
 		}
 
-		j += u8_rune(&c, (uschar *)j);
+		j += u8_rune(&c, j);
 
 		if ((ns = get_gototab(pfa, s, c)) != 0)
 			s = ns;
@@ -907,7 +907,7 @@
 			break;     /* best match found */
 
 		/* no match at origin i, next i and start over */
-		i += u8_rune(&c, (uschar *)i);
+		i += u8_rune(&c, i);
 		if (c == 0)
 			break;    /* no match */
 		j = i;
@@ -1229,8 +1229,6 @@
 	return 0;
 }
 
-extern int u8_rune(int *, const uschar *); /* run.c; should be in header file */
-
 int relex(void)		/* lexical analyzer for reparse */
 {
 	int c, n;
@@ -1248,7 +1246,7 @@
 rescan:
 	starttok = prestr;
 
-	if ((n = u8_rune(&rlxval, prestr)) > 1) {
+	if ((n = u8_rune(&rlxval, (const char *) prestr)) > 1) {
 		prestr += n;
 		starttok = prestr;
 		return CHAR;
@@ -1295,7 +1293,7 @@
 		if (!adjbuf((char **) &buf, &bufsz, n, n, (char **) &bp, "relex1"))
 			FATAL("out of space for reg expr %.10s...", lastre);
 		for (; ; ) {
-			if ((n = u8_rune(&rlxval, prestr)) > 1) {
+			if ((n = u8_rune(&rlxval, (const char *) prestr)) > 1) {
 				for (i = 0; i < n; i++)
 					*bp++ = *prestr++;
 				continue;
--- a/main.c
+++ b/main.c
@@ -22,7 +22,7 @@
 THIS SOFTWARE.
 ****************************************************************/
 
-const char	*version = "version 20231228";
+const char	*version = "version 20240122";
 
 #define DEBUG
 #include <stdio.h>
--- a/run.c
+++ b/run.c
@@ -1300,7 +1300,8 @@
 
 						if (bs == NULL)	{ // invalid character
 							// use unicode invalid character, 0xFFFD
-							bs = "\357\277\275";
+							static char invalid_char[] = "\357\277\275";
+							bs = invalid_char;
 							count = 3;
 						}
 						t = bs;
@@ -2448,7 +2449,7 @@
 	start = getsval(x);
 	while (pmatch(pfa, start)) {
 		if (buf == NULL) {
-			if ((pb = buf = malloc(bufsz)) == NULL)
+			if ((pb = buf = (char *) malloc(bufsz)) == NULL)
 				FATAL("out of memory in dosub");
 			tempstat = pfa->initstat;
 			pfa->initstat = 2;
--