[Midnightbsd-cvs] src [8735] trunk/contrib/one-true-awk: merge 20121220

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 20:07:06 EDT 2016


Revision: 8735
          http://svnweb.midnightbsd.org/src/?rev=8735
Author:   laffer1
Date:     2016-09-25 20:07:06 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
merge 20121220

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

Property Changed:
----------------
    trunk/contrib/one-true-awk/

Index: trunk/contrib/one-true-awk
===================================================================
--- trunk/contrib/one-true-awk	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk	2016-09-26 00:07:06 UTC (rev 8735)

Property changes on: trunk/contrib/one-true-awk
___________________________________________________________________
Added: svn:mergeinfo
## -0,0 +1,2 ##
+/branches/BELL_LABS/contrib/one-true-awk:4237-6396
+/vendor/one-true-awk/dist:6397-8734
\ No newline at end of property
Modified: trunk/contrib/one-true-awk/FIXES
===================================================================
--- trunk/contrib/one-true-awk/FIXES	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk/FIXES	2016-09-26 00:07:06 UTC (rev 8735)
@@ -26,6 +26,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: trunk/contrib/one-true-awk/awk.1
===================================================================
--- trunk/contrib/one-true-awk/awk.1	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk/awk.1	2016-09-26 00:07:06 UTC (rev 8735)
@@ -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: trunk/contrib/one-true-awk/b.c
===================================================================
--- trunk/contrib/one-true-awk/b.c	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk/b.c	2016-09-26 00:07:06 UTC (rev 8735)
@@ -25,6 +25,8 @@
 
 /* lasciate ogne speranza, voi ch'intrate. */
 
+#include <sys/cdefs.h>
+
 #define	DEBUG
 
 #include <ctype.h>
@@ -286,9 +288,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;
@@ -307,15 +321,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;
@@ -824,7 +841,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: trunk/contrib/one-true-awk/main.c
===================================================================
--- trunk/contrib/one-true-awk/main.c	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk/main.c	2016-09-26 00:07:06 UTC (rev 8735)
@@ -23,8 +23,10 @@
 THIS SOFTWARE.
 ****************************************************************/
 
-const char	*version = "version 20110810 (MidnightBSD)";
+#include <sys/cdefs.h>
 
+const char	*version = "version 20121220 (MidnightBSD)";
+
 #define DEBUG
 #include <stdio.h>
 #include <ctype.h>
@@ -60,6 +62,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) {
@@ -71,7 +74,7 @@
 	signal(SIGFPE, fpecatch);
 
 	srand_seed = 1;
-	srand(srand_seed);
+	srandom((unsigned long) srand_seed);
 
 	yyin = NULL;
 	symtab = makesymtab(NSYMTAB/NSYMTAB);

Modified: trunk/contrib/one-true-awk/makefile
===================================================================
--- trunk/contrib/one-true-awk/makefile	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk/makefile	2016-09-26 00:07:06 UTC (rev 8735)
@@ -27,15 +27,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: trunk/contrib/one-true-awk/proto.h
===================================================================
--- trunk/contrib/one-true-awk/proto.h	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk/proto.h	2016-09-26 00:07:06 UTC (rev 8735)
@@ -47,7 +47,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 *);
@@ -133,7 +133,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: trunk/contrib/one-true-awk/run.c
===================================================================
--- trunk/contrib/one-true-awk/run.c	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk/run.c	2016-09-26 00:07:06 UTC (rev 8735)
@@ -23,6 +23,8 @@
 THIS SOFTWARE.
 ****************************************************************/
 
+#include <sys/cdefs.h>
+
 #define DEBUG
 #include <stdio.h>
 #include <ctype.h>
@@ -655,7 +657,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);
@@ -1211,13 +1213,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;
@@ -1337,6 +1339,7 @@
 	}
 	tempfree(ap);
 	tempfree(y);
+	free(origs);
 	if (a[2] != 0 && arg3type == STRING) {
 		tempfree(x);
 	}
@@ -1518,8 +1521,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 */
@@ -1527,7 +1532,7 @@
 		else
 			u = getfval(x);
 		tmp = u;
-		srand((unsigned int) u);
+		srandom((unsigned long) u);
 		u = srand_seed;
 		srand_seed = tmp;
 		break;

Modified: trunk/contrib/one-true-awk/tran.c
===================================================================
--- trunk/contrib/one-true-awk/tran.c	2016-09-26 00:05:28 UTC (rev 8734)
+++ trunk/contrib/one-true-awk/tran.c	2016-09-26 00:07:06 UTC (rev 8735)
@@ -299,6 +299,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