[Midnightbsd-cvs] src [8733] vendor/one-true-awk/dist: one-true-awk 20121220

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 20:04:54 EDT 2016


Revision: 8733
          http://svnweb.midnightbsd.org/src/?rev=8733
Author:   laffer1
Date:     2016-09-25 20:04:54 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
one-true-awk 20121220

Modified Paths:
--------------
    vendor/one-true-awk/dist/FIXES
    vendor/one-true-awk/dist/awk.1
    vendor/one-true-awk/dist/b.c
    vendor/one-true-awk/dist/main.c
    vendor/one-true-awk/dist/makefile
    vendor/one-true-awk/dist/proto.h
    vendor/one-true-awk/dist/run.c
    vendor/one-true-awk/dist/tran.c

Modified: vendor/one-true-awk/dist/FIXES
===================================================================
--- vendor/one-true-awk/dist/FIXES	2016-09-26 00:01:21 UTC (rev 8732)
+++ vendor/one-true-awk/dist/FIXES	2016-09-26 00:04:54 UTC (rev 8733)
@@ -25,6 +25,22 @@
 This file lists all bug fixes, changes, etc., made since the AWK book
 was sent to the printers in August, 1987.
 
+Dec 20, 2012:
+	fiddled makefile to get correct yacc and bison flags.  pick yacc
+	(linux) or bison (mac) as necessary.
+
+	added  __attribute__((__noreturn__)) to a couple of lines in
+	proto.h, to silence someone's enthusiastic checker.
+
+	fixed obscure call by value bug in split(a[1],a) reported on
+	9fans.  the management of temporary values is just a mess; i
+	took a shortcut by making an extra string copy.  thanks
+	to paul patience and arnold robbins for passing it on and for
+	proposed patches.
+
+	tiny fiddle in setfval to eliminate -0 results in T.expr, which
+	has irritated me for 20+ years.
+
 Aug 10, 2011:
 	another fix to avoid core dump with delete(ARGV); again, many thanks
 	to ruslan ermilov.

Modified: vendor/one-true-awk/dist/awk.1
===================================================================
--- vendor/one-true-awk/dist/awk.1	2016-09-26 00:01:21 UTC (rev 8732)
+++ vendor/one-true-awk/dist/awk.1	2016-09-26 00:04:54 UTC (rev 8733)
@@ -208,7 +208,7 @@
 if no argument.
 .TP
 .B rand
-random number on (0,1)
+random number on [0,1)
 .TP
 .B srand
 sets seed for

Modified: vendor/one-true-awk/dist/b.c
===================================================================
--- vendor/one-true-awk/dist/b.c	2016-09-26 00:01:21 UTC (rev 8732)
+++ vendor/one-true-awk/dist/b.c	2016-09-26 00:04:54 UTC (rev 8733)
@@ -24,6 +24,8 @@
 
 /* lasciate ogne speranza, voi ch'intrate. */
 
+#include <sys/cdefs.h>
+
 #define	DEBUG
 
 #include <ctype.h>
@@ -285,9 +287,21 @@
 	return c;
 }
 
+static int collate_range_cmp(int a, int b)
+{
+	static char s[2][2];
+
+	if ((uschar)a == (uschar)b)
+		return 0;
+	s[0][0] = a;
+	s[1][0] = b;
+	return (strcoll(s[0], s[1]));
+}
+
 char *cclenter(const char *argp)	/* add a character class */
 {
 	int i, c, c2;
+	int j;
 	uschar *p = (uschar *) argp;
 	uschar *op, *bp;
 	static uschar *buf = 0;
@@ -306,15 +320,18 @@
 				c2 = *p++;
 				if (c2 == '\\')
 					c2 = quoted(&p);
-				if (c > c2) {	/* empty; ignore */
+				if (collate_range_cmp(c, c2) > 0) {
 					bp--;
 					i--;
 					continue;
 				}
-				while (c < c2) {
+				for (j = 0; j < NCHARS; j++) {
+					if ((collate_range_cmp(c, j) > 0) ||
+					    collate_range_cmp(j, c2) > 0)
+						continue;
 					if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, "cclenter1"))
 						FATAL("out of space for character class [%.10s...] 2", p);
-					*bp++ = ++c;
+					*bp++ = j;
 					i++;
 				}
 				continue;
@@ -823,7 +840,7 @@
 				if (cc->cc_name != NULL && prestr[1 + cc->cc_namelen] == ':' &&
 				    prestr[2 + cc->cc_namelen] == ']') {
 					prestr += cc->cc_namelen + 3;
-					for (i = 0; i < NCHARS; i++) {
+					for (i = 1; i < NCHARS; 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)) {

Modified: vendor/one-true-awk/dist/main.c
===================================================================
--- vendor/one-true-awk/dist/main.c	2016-09-26 00:01:21 UTC (rev 8732)
+++ vendor/one-true-awk/dist/main.c	2016-09-26 00:04:54 UTC (rev 8733)
@@ -22,8 +22,10 @@
 THIS SOFTWARE.
 ****************************************************************/
 
-const char	*version = "version 20110810";
+#include <sys/cdefs.h>
 
+const char	*version = "version 20121220 (MidnightBSD)";
+
 #define DEBUG
 #include <stdio.h>
 #include <ctype.h>
@@ -59,6 +61,7 @@
 	const char *fs = NULL;
 
 	setlocale(LC_CTYPE, "");
+	setlocale(LC_COLLATE, "");
 	setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
 	cmdname = argv[0];
 	if (argc == 1) {
@@ -70,7 +73,7 @@
 	signal(SIGFPE, fpecatch);
 
 	srand_seed = 1;
-	srand(srand_seed);
+	srandom((unsigned long) srand_seed);
 
 	yyin = NULL;
 	symtab = makesymtab(NSYMTAB/NSYMTAB);

Modified: vendor/one-true-awk/dist/makefile
===================================================================
--- vendor/one-true-awk/dist/makefile	2016-09-26 00:01:21 UTC (rev 8732)
+++ vendor/one-true-awk/dist/makefile	2016-09-26 00:04:54 UTC (rev 8733)
@@ -26,15 +26,15 @@
 CFLAGS = -O2
 CFLAGS =
 
-CC = gcc -Wall -g
-CC = cc
 CC = gcc -Wall -g -Wwrite-strings
 CC = gcc -fprofile-arcs -ftest-coverage # then gcov f1.c; cat f1.c.gcov
+CC = gcc -g -Wall -pedantic 
 CC = gcc -O4 -Wall -pedantic -fno-strict-aliasing
 
-YACC = bison -y
-YACC = yacc
-YFLAGS = -d
+YACC = bison -d -y
+YACC = yacc -d -S
+#YFLAGS = -d -S
+		# -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
 

Modified: vendor/one-true-awk/dist/proto.h
===================================================================
--- vendor/one-true-awk/dist/proto.h	2016-09-26 00:01:21 UTC (rev 8732)
+++ vendor/one-true-awk/dist/proto.h	2016-09-26 00:04:54 UTC (rev 8733)
@@ -46,7 +46,7 @@
 extern	int	hexstr(uschar **);
 extern	int	quoted(uschar **);
 extern	char	*cclenter(const char *);
-extern	void	overflo(const char *);
+extern	void	overflo(const char *) __attribute__((__noreturn__));
 extern	void	cfoll(fa *, Node *);
 extern	int	first(Node *);
 extern	void	follow(Node *);
@@ -132,7 +132,7 @@
 extern	void	bracecheck(void);
 extern	void	bcheck2(int, int, int);
 extern	void	SYNTAX(const char *, ...);
-extern	void	FATAL(const char *, ...);
+extern	void	FATAL(const char *, ...) __attribute__((__noreturn__));
 extern	void	WARNING(const char *, ...);
 extern	void	error(void);
 extern	void	eprint(void);

Modified: vendor/one-true-awk/dist/run.c
===================================================================
--- vendor/one-true-awk/dist/run.c	2016-09-26 00:01:21 UTC (rev 8732)
+++ vendor/one-true-awk/dist/run.c	2016-09-26 00:04:54 UTC (rev 8733)
@@ -22,6 +22,8 @@
 THIS SOFTWARE.
 ****************************************************************/
 
+#include <sys/cdefs.h>
+
 #define DEBUG
 #include <stdio.h>
 #include <ctype.h>
@@ -654,7 +656,7 @@
 		j = x->fval - y->fval;
 		i = j<0? -1: (j>0? 1: 0);
 	} else {
-		i = strcmp(getsval(x), getsval(y));
+		i = strcoll(getsval(x), getsval(y));
 	}
 	tempfree(x);
 	tempfree(y);
@@ -1210,13 +1212,13 @@
 Cell *split(Node **a, int nnn)	/* split(a[0], a[1], a[2]); a[3] is type */
 {
 	Cell *x = 0, *y, *ap;
-	char *s;
+	char *s, *origs;
 	int sep;
 	char *t, temp, num[50], *fs = 0;
 	int n, tempstat, arg3type;
 
 	y = execute(a[0]);	/* source string */
-	s = getsval(y);
+	origs = s = strdup(getsval(y));
 	arg3type = ptoi(a[3]);
 	if (a[2] == 0)		/* fs string */
 		fs = *FS;
@@ -1336,6 +1338,7 @@
 	}
 	tempfree(ap);
 	tempfree(y);
+	free(origs);
 	if (a[2] != 0 && arg3type == STRING) {
 		tempfree(x);
 	}
@@ -1517,8 +1520,10 @@
 		u = (Awkfloat) system(getsval(x)) / 256;   /* 256 is unix-dep */
 		break;
 	case FRAND:
-		/* in principle, rand() returns something in 0..RAND_MAX */
-		u = (Awkfloat) (rand() % RAND_MAX) / RAND_MAX;
+		/* random() returns numbers in [0..2^31-1]
+		 * in order to get a number in [0, 1), divide it by 2^31
+		 */
+		u = (Awkfloat) random() / (0x7fffffffL + 0x1UL);
 		break;
 	case FSRAND:
 		if (isrec(x))	/* no argument provided */
@@ -1526,7 +1531,7 @@
 		else
 			u = getfval(x);
 		tmp = u;
-		srand((unsigned int) u);
+		srandom((unsigned long) u);
 		u = srand_seed;
 		srand_seed = tmp;
 		break;

Modified: vendor/one-true-awk/dist/tran.c
===================================================================
--- vendor/one-true-awk/dist/tran.c	2016-09-26 00:01:21 UTC (rev 8732)
+++ vendor/one-true-awk/dist/tran.c	2016-09-26 00:04:54 UTC (rev 8733)
@@ -298,6 +298,8 @@
 		xfree(vp->sval); /* free any previous string */
 	vp->tval &= ~STR;	/* mark string invalid */
 	vp->tval |= NUM;	/* mark number ok */
+	if (f == -0)  /* who would have thought this possible? */
+		f = 0;
 	   dprintf( ("setfval %p: %s = %g, t=%o\n", (void*)vp, NN(vp->nval), f, vp->tval) );
 	return vp->fval = f;
 }



More information about the Midnightbsd-cvs mailing list