CVS commit: src/external/historical/nawk/dist

2020-11-02 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Nov  2 22:58:51 UTC 2020

Modified Files:
src/external/historical/nawk/dist: tran.c

Log Message:
>From wajap at github:
- eat whitespace in infnan checks
- set fval to 0 if we are not a floating point number


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.14 src/external/historical/nawk/dist/tran.c:1.15
--- src/external/historical/nawk/dist/tran.c:1.14	Mon Aug 31 20:35:29 2020
+++ src/external/historical/nawk/dist/tran.c	Mon Nov  2 17:58:51 2020
@@ -399,11 +399,15 @@ static int checkstr(const char *s, const
 {
 	while (*s && tolower((unsigned char)*s) == *v)
 		s++, v++;
+	while (isspace((unsigned char)*s))
+		s++;
 	return !(*s || *v);
 }
 
 static int checkinfnan(const char *s)
 {
+	while (isspace((unsigned char)*s))
+		s++;
 	if (*s == '+' || *s == '-')
 		s++;
 	switch (tolower((unsigned char)*s)) {
@@ -427,6 +431,8 @@ Awkfloat getfval(Cell *vp)	/* get float 
 	if (!isnum(vp)) {	/* not a number */
 		if (checkinfnan(vp->sval))
 			vp->fval = atof(vp->sval);	/* best guess */
+		else
+			vp->fval = 0.0;
 		if (is_number(vp->sval) && !(vp->tval&CON)) {
 			vp->tval |= NUM;	/* make NUM only sparingly */
 		}



CVS commit: src/external/historical/nawk/dist

2020-08-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 31 23:36:58 UTC 2020

Modified Files:
src/external/historical/nawk/dist: tran.c

Log Message:
Don't try so hard to convert strings into numbers. Results in bogus
conversions like:

% awk 'BEGIN { print "nanotime" + 123 }'
nan
% awk 'BEGIN { print "microtime" + 123 }'
123
% awk 'BEGIN { print "inftime" + 123 }'
inf


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.11 src/external/historical/nawk/dist/tran.c:1.12
--- src/external/historical/nawk/dist/tran.c:1.11	Tue Feb 18 16:12:21 2020
+++ src/external/historical/nawk/dist/tran.c	Mon Aug 31 19:36:58 2020
@@ -404,9 +404,12 @@ Awkfloat getfval(Cell *vp)	/* get float 
 	else if (isrec(vp) && !donerec)
 		recbld();
 	if (!isnum(vp)) {	/* not a number */
-		vp->fval = atof(vp->sval);	/* best guess */
-		if (is_number(vp->sval) && !(vp->tval&CON))
+		if (is_number(vp->sval) && !(vp->tval&CON)) {
+			vp->fval = atof(vp->sval);	/* best guess */
 			vp->tval |= NUM;	/* make NUM only sparingly */
+		} else {
+			vp->fval = 0;
+		}
 	}
 	   dprintf( ("getfval %p: %s = %g, t=%o\n",
 		(void*)vp, NN(vp->nval), vp->fval, vp->tval) );



CVS commit: src/external/historical/nawk/dist

2020-08-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 31 23:37:55 UTC 2020

Modified Files:
src/external/historical/nawk/dist: lib.c proto.h run.c

Log Message:
Add a check_number function that does what is repeated in many places in
the code, but better.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/external/historical/nawk/dist/lib.c \
src/external/historical/nawk/dist/run.c
cvs rdiff -u -r1.11 -r1.12 src/external/historical/nawk/dist/proto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.12 src/external/historical/nawk/dist/lib.c:1.13
--- src/external/historical/nawk/dist/lib.c:1.12	Fri Apr 17 18:35:18 2020
+++ src/external/historical/nawk/dist/lib.c	Mon Aug 31 19:37:55 2020
@@ -191,10 +191,7 @@ int getrec(char **pbuf, int *pbufsize, b
 	xfree(fldtab[0]->sval);
 fldtab[0]->sval = buf;	/* buf == record */
 fldtab[0]->tval = REC | STR | DONTFREE;
-if (is_number(fldtab[0]->sval)) {
-	fldtab[0]->fval = atof(fldtab[0]->sval);
-	fldtab[0]->tval |= NUM;
-}
+check_number(fldtab[0]);
 			}
 			setfval(nrloc, nrloc->fval+1);
 			setfval(fnrloc, fnrloc->fval+1);
@@ -306,10 +303,7 @@ void setclvar(char *s)	/* set var=value 
 	p = qstring(p, '\0');
 	q = setsymtab(s, p, 0.0, STR, symtab);
 	setsval(q, p);
-	if (is_number(q->sval)) {
-		q->fval = atof(q->sval);
-		q->tval |= NUM;
-	}
+	check_number(q);
 	   dprintf( ("command line set %s to |%s|\n", s, p) );
 }
 
@@ -407,10 +401,7 @@ void fldbld(void)	/* create fields from 
 	donefld = true;
 	for (j = 1; j <= lastfld; j++) {
 		p = fldtab[j];
-		if(is_number(p->sval)) {
-			p->fval = atof(p->sval);
-			p->tval |= NUM;
-		}
+		check_number(p);
 	}
 	setfval(nfloc, (Awkfloat) lastfld);
 	donerec = true; /* restore */
@@ -763,7 +754,8 @@ int isclvar(const char *s)	/* is s of fo
 /* wrong: violates 4.10.1.4 of ansi C standard */
 
 #include 
-int is_number(const char *s)
+
+static int get_number(const char *s, double *res)
 {
 	double r;
 	char *ep;
@@ -773,8 +765,20 @@ int is_number(const char *s)
 		return 0;
 	while (*ep == ' ' || *ep == '\t' || *ep == '\n')
 		ep++;
-	if (*ep == '\0')
-		return 1;
-	else
+	if (*ep != '\0')
 		return 0;
+	if (res)		
+		*res = r;
+	return 1;
+}
+
+void check_number(Cell *x)
+{
+	if (get_number(x->sval, &x->fval))
+		x->tval |= NUM;
+}
+
+int is_number(const char *s)
+{
+	return get_number(s, NULL);
 }
Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.12 src/external/historical/nawk/dist/run.c:1.13
--- src/external/historical/nawk/dist/run.c:1.12	Thu Feb 20 14:59:12 2020
+++ src/external/historical/nawk/dist/run.c	Mon Aug 31 19:37:55 2020
@@ -432,17 +432,11 @@ Cell *awkgetline(Node **a, int n)	/* get
 		} else if (a[0] != NULL) {	/* getline var sval)) {
-x->fval = atof(x->sval);
-x->tval |= NUM;
-			}
+			check_number(x);
 			tempfree(x);
 		} else {			/* getline sval)) {
-fldtab[0]->fval = atof(fldtab[0]->sval);
-fldtab[0]->tval |= NUM;
-			}
+			check_number(fldtab[0]);
 		}
 	} else {			/* bare getline; use current input */
 		if (a[0] == NULL)	/* getline */
@@ -451,10 +445,7 @@ Cell *awkgetline(Node **a, int n)	/* get
 			n = getrec(&buf, &bufsize, false);
 			x = execute(a[0]);
 			setsval(x, buf);
-			if (is_number(x->sval)) {
-x->fval = atof(x->sval);
-x->tval |= NUM;
-			}
+			check_number(x);
 			tempfree(x);
 		}
 	}

Index: src/external/historical/nawk/dist/proto.h
diff -u src/external/historical/nawk/dist/proto.h:1.11 src/external/historical/nawk/dist/proto.h:1.12
--- src/external/historical/nawk/dist/proto.h:1.11	Thu Feb 20 14:59:12 2020
+++ src/external/historical/nawk/dist/proto.h	Mon Aug 31 19:37:55 2020
@@ -149,6 +149,7 @@ extern	void	bclass(int);
 extern	double	errcheck(double, const char *);
 extern	int	isclvar(const char *);
 extern	int	is_number(const char *);
+extern	void	check_number(Cell *);
 
 extern	int	adjbuf(char **, int *, int, int, char **, const char *);
 extern	void	run(Node *);



CVS commit: src/external/historical/nawk/dist

2020-08-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep  1 00:21:02 UTC 2020

Modified Files:
src/external/historical/nawk/dist: tran.c

Log Message:
check explicitly for inf and nan. We can't check if it is a number,
because awk parses 1a as 1...


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.12 src/external/historical/nawk/dist/tran.c:1.13
--- src/external/historical/nawk/dist/tran.c:1.12	Mon Aug 31 19:36:58 2020
+++ src/external/historical/nawk/dist/tran.c	Mon Aug 31 20:21:01 2020
@@ -395,6 +395,25 @@ char *setsval(Cell *vp, const char *s)	/
 	return(vp->sval);
 }
 
+static int checkstr(const char *s, const char *v)
+{
+	while (*s && tolower((unsigned char)*s) == *v)
+		s++, v++;
+	return !(*s || *v);
+}
+
+static int checkinfnan(const char *s)
+{
+	switch (tolower((unsigned char)*s)) {
+	case 'i':
+		return checkstr(s, "inf") || checkstr(s, "infinity");
+	case 'n':
+		return checkstr(s, "nan");
+	default:
+		return 1;
+	}
+}
+
 Awkfloat getfval(Cell *vp)	/* get float val of a Cell */
 {
 	if ((vp->tval & (NUM | STR)) == 0)
@@ -404,11 +423,10 @@ Awkfloat getfval(Cell *vp)	/* get float 
 	else if (isrec(vp) && !donerec)
 		recbld();
 	if (!isnum(vp)) {	/* not a number */
-		if (is_number(vp->sval) && !(vp->tval&CON)) {
+		if (checkinfnan(vp->sval))
 			vp->fval = atof(vp->sval);	/* best guess */
+		if (is_number(vp->sval) && !(vp->tval&CON)) {
 			vp->tval |= NUM;	/* make NUM only sparingly */
-		} else {
-			vp->fval = 0;
 		}
 	}
 	   dprintf( ("getfval %p: %s = %g, t=%o\n",



CVS commit: src/external/historical/nawk/dist

2020-08-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep  1 00:35:30 UTC 2020

Modified Files:
src/external/historical/nawk/dist: tran.c

Log Message:
eat the sign, pointed out by uwe@


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.13 src/external/historical/nawk/dist/tran.c:1.14
--- src/external/historical/nawk/dist/tran.c:1.13	Mon Aug 31 20:21:01 2020
+++ src/external/historical/nawk/dist/tran.c	Mon Aug 31 20:35:29 2020
@@ -404,6 +404,8 @@ static int checkstr(const char *s, const
 
 static int checkinfnan(const char *s)
 {
+	if (*s == '+' || *s == '-')
+		s++;
 	switch (tolower((unsigned char)*s)) {
 	case 'i':
 		return checkstr(s, "inf") || checkstr(s, "infinity");



CVS commit: src/external/historical/nawk/dist

2020-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Sep  2 18:09:04 UTC 2020

Modified Files:
src/external/historical/nawk/dist: run.c

Log Message:
Nix trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.13 src/external/historical/nawk/dist/run.c:1.14
--- src/external/historical/nawk/dist/run.c:1.13	Mon Aug 31 23:37:55 2020
+++ src/external/historical/nawk/dist/run.c	Wed Sep  2 18:09:04 2020
@@ -1916,7 +1916,7 @@ const char *filename(FILE *fp)
  	Cell *x;
 	size_t i;
 	bool stat;
- 
+
  	x = execute(a[0]);
  	getsval(x);
 	stat = true;
@@ -2194,7 +2194,7 @@ Cell *gensub(Node **a, int nnn)	/* globa
 FATAL("gensub doesn't support backreferences (subst \"%s\")", rptr);
 			}
 		}
-		
+
 		do {
 			if (whichm >= 0 && whichm != num) {
 num++;



CVS commit: src/external/historical/nawk/dist

2020-04-17 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Apr 17 22:35:18 UTC 2020

Modified Files:
src/external/historical/nawk/dist: lib.c

Log Message:
Now that inputFS is dynamically allocated, make sure it's always non-NULL.
Fixes core dumps when building CDE.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/external/historical/nawk/dist/lib.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.11 src/external/historical/nawk/dist/lib.c:1.12
--- src/external/historical/nawk/dist/lib.c:1.11	Thu Feb 20 19:59:12 2020
+++ src/external/historical/nawk/dist/lib.c	Fri Apr 17 22:35:18 2020
@@ -48,7 +48,7 @@ int	fieldssize = RECSIZE;
 
 Cell	**fldtab;	/* pointers to Cells */
 static size_t	len_inputFS = 0;
-static char	*inputFS = NULL; /* FS at time of input, for field splitting */
+static char	*inputFS; /* FS at time of input, for field splitting */
 
 #define	MAXFLD	2
 int	nfields	= MAXFLD;	/* last allocated slot for $i */
@@ -75,6 +75,7 @@ void recinit(unsigned int n)
 	fldtab[0]->sval = record;
 	fldtab[0]->nval = tostring("0");
 	makefields(1, nfields);
+	inputFS = strdup("");
 }
 
 void makefields(int n1, int n2)		/* create $n1..$n2 inclusive */



CVS commit: src/external/historical/nawk/dist

2015-11-03 Thread Mateusz Kocielski
Module Name:src
Committed By:   shm
Date:   Tue Nov  3 14:15:08 UTC 2015

Modified Files:
src/external/historical/nawk/dist: run.c

Log Message:
PR/50199 - fix for strftime called with empty string.
Patch written by Juho Salminen


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.8 src/external/historical/nawk/dist/run.c:1.9
--- src/external/historical/nawk/dist/run.c:1.8	Sun Dec 15 06:41:18 2013
+++ src/external/historical/nawk/dist/run.c	Tue Nov  3 14:15:08 2015
@@ -1660,7 +1660,7 @@ Cell *bltin(Node **a, int n)	/* builtin 
 		do {
 			if ((buf = realloc(buf, (sz *= 2))) == NULL)
 FATAL("out of memory in strftime");
-		} while(strftime(buf, sz, fmt, tm) == 0);
+		} while(strftime(buf, sz, fmt, tm) == 0 && fmt[0] != '\0');
 
 		y = gettemp();
 		setsval(y, buf);



CVS commit: src/external/historical/nawk/dist

2020-02-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb 18 21:29:31 UTC 2020

Modified Files:
src/external/historical/nawk/dist: maketab.c

Log Message:
use the correct header name.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/maketab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/maketab.c
diff -u src/external/historical/nawk/dist/maketab.c:1.3 src/external/historical/nawk/dist/maketab.c:1.4
--- src/external/historical/nawk/dist/maketab.c:1.3	Tue Feb 18 16:12:21 2020
+++ src/external/historical/nawk/dist/maketab.c	Tue Feb 18 16:29:30 2020
@@ -36,7 +36,7 @@ THIS SOFTWARE.
 #include 
 #include 
 #include "awk.h"
-#include "awktab.h"
+#include "awkgram.h"
 
 struct xx
 {	int token;



CVS commit: src/external/historical/nawk/dist

2020-02-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb 18 21:29:39 UTC 2020

Modified Files:
src/external/historical/nawk/dist: proctab.c

Log Message:
regen


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/external/historical/nawk/dist/proctab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/proctab.c
diff -u src/external/historical/nawk/dist/proctab.c:1.5 src/external/historical/nawk/dist/proctab.c:1.6
--- src/external/historical/nawk/dist/proctab.c:1.5	Tue Feb 18 16:12:21 2020
+++ src/external/historical/nawk/dist/proctab.c	Tue Feb 18 16:29:39 2020
@@ -1,55 +1,52 @@
-#if HAVE_NBTOOL_CONFIG_H
-#include "nbtool_config.h"
-#endif
-
 #include 
 #include "awk.h"
-#include "awkgram.h"
+#include "ytab.h"
 
-static const char * const printname[95] = {
-	"FIRSTTOKEN",	/* 258 */
-	"PROGRAM",	/* 259 */
-	"PASTAT",	/* 260 */
-	"PASTAT2",	/* 261 */
-	"XBEGIN",	/* 262 */
-	"XEND",	/* 263 */
-	"NL",	/* 264 */
-	"ARRAY",	/* 265 */
-	"MATCH",	/* 266 */
-	"NOTMATCH",	/* 267 */
-	"MATCHOP",	/* 268 */
-	"FINAL",	/* 269 */
-	"DOT",	/* 270 */
-	"ALL",	/* 271 */
-	"CCL",	/* 272 */
-	"NCCL",	/* 273 */
-	"CHAR",	/* 274 */
-	"OR",	/* 275 */
-	"STAR",	/* 276 */
-	"QUEST",	/* 277 */
-	"PLUS",	/* 278 */
-	"EMPTYRE",	/* 279 */
-	"ZERO",	/* 280 */
-	"AND",	/* 281 */
-	"BOR",	/* 282 */
-	"APPEND",	/* 283 */
-	"EQ",	/* 284 */
-	"GE",	/* 285 */
-	"GT",	/* 286 */
-	"LE",	/* 287 */
-	"LT",	/* 288 */
-	"NE",	/* 289 */
-	"IN",	/* 290 */
-	"ARG",	/* 291 */
-	"BLTIN",	/* 292 */
-	"BREAK",	/* 293 */
-	"CLOSE",	/* 294 */
-	"CONTINUE",	/* 295 */
-	"DELETE",	/* 296 */
-	"DO",	/* 297 */
-	"EXIT",	/* 298 */
-	"FOR",	/* 299 */
-	"FUNC",	/* 300 */
+static const char * const printname[96] = {
+	"FIRSTTOKEN",	/* 257 */
+	"PROGRAM",	/* 258 */
+	"PASTAT",	/* 259 */
+	"PASTAT2",	/* 260 */
+	"XBEGIN",	/* 261 */
+	"XEND",	/* 262 */
+	"NL",	/* 263 */
+	"ARRAY",	/* 264 */
+	"MATCH",	/* 265 */
+	"NOTMATCH",	/* 266 */
+	"MATCHOP",	/* 267 */
+	"FINAL",	/* 268 */
+	"DOT",	/* 269 */
+	"ALL",	/* 270 */
+	"CCL",	/* 271 */
+	"NCCL",	/* 272 */
+	"CHAR",	/* 273 */
+	"OR",	/* 274 */
+	"STAR",	/* 275 */
+	"QUEST",	/* 276 */
+	"PLUS",	/* 277 */
+	"EMPTYRE",	/* 278 */
+	"ZERO",	/* 279 */
+	"AND",	/* 280 */
+	"BOR",	/* 281 */
+	"APPEND",	/* 282 */
+	"EQ",	/* 283 */
+	"GE",	/* 284 */
+	"GT",	/* 285 */
+	"LE",	/* 286 */
+	"LT",	/* 287 */
+	"NE",	/* 288 */
+	"IN",	/* 289 */
+	"ARG",	/* 290 */
+	"BLTIN",	/* 291 */
+	"BREAK",	/* 292 */
+	"CLOSE",	/* 293 */
+	"CONTINUE",	/* 294 */
+	"DELETE",	/* 295 */
+	"DO",	/* 296 */
+	"EXIT",	/* 297 */
+	"FOR",	/* 298 */
+	"FUNC",	/* 299 */
+	"GENSUB",	/* 300 */
 	"SUB",	/* 301 */
 	"GSUB",	/* 302 */
 	"IF",	/* 303 */
@@ -105,7 +102,7 @@ static const char * const printname[95] 
 };
 
 
-Cell *(*proctab[95])(Node **, int) = {
+Cell *(*proctab[96])(Node **, int) = {
 	nullproc,	/* FIRSTTOKEN */
 	program,	/* PROGRAM */
 	pastat,	/* PASTAT */
@@ -149,6 +146,7 @@ Cell *(*proctab[95])(Node **, int) = {
 	jump,	/* EXIT */
 	forstat,	/* FOR */
 	nullproc,	/* FUNC */
+	gensub,	/* GENSUB */
 	sub,	/* SUB */
 	gsub,	/* GSUB */
 	ifstat,	/* IF */



CVS commit: src/external/historical/nawk/dist

2020-02-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 20 19:59:12 UTC 2020

Modified Files:
src/external/historical/nawk/dist: lex.c lib.c main.c proto.h run.c

Log Message:
Fix failing unittests (by restoring old changes).


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/historical/nawk/dist/lex.c
cvs rdiff -u -r1.10 -r1.11 src/external/historical/nawk/dist/lib.c \
src/external/historical/nawk/dist/main.c \
src/external/historical/nawk/dist/proto.h
cvs rdiff -u -r1.11 -r1.12 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lex.c
diff -u src/external/historical/nawk/dist/lex.c:1.6 src/external/historical/nawk/dist/lex.c:1.7
--- src/external/historical/nawk/dist/lex.c:1.6	Tue Feb 18 16:12:21 2020
+++ src/external/historical/nawk/dist/lex.c	Thu Feb 20 14:59:12 2020
@@ -401,6 +401,7 @@ int string(void)
 		case '\\':
 			c = input();
 			switch (c) {
+			case '\n': break;
 			case '"': *bp++ = '"'; break;
 			case 'n': *bp++ = '\n'; break;
 			case 't': *bp++ = '\t'; break;

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.10 src/external/historical/nawk/dist/lib.c:1.11
--- src/external/historical/nawk/dist/lib.c:1.10	Tue Feb 18 16:12:21 2020
+++ src/external/historical/nawk/dist/lib.c	Thu Feb 20 14:59:12 2020
@@ -39,6 +39,7 @@ THIS SOFTWARE.
 
 char	EMPTY[] = { '\0' };
 FILE	*infile	= NULL;
+bool	innew;		/* true = infile has not been read by readrec */
 char	*file	= EMPTY;
 char	*record;
 int	recsize	= RECSIZE;
@@ -110,6 +111,7 @@ void initgetrec(void)
 		argno++;
 	}
 	infile = stdin;		/* no filenames, so use stdin */
+	innew = true;
 }
 
 /*
@@ -179,7 +181,9 @@ int getrec(char **pbuf, int *pbufsize, b
 FATAL("can't open file %s", file);
 			setfval(fnrloc, 0.0);
 		}
-		c = readrec(&buf, &bufsize, infile);
+		c = readrec(&buf, &bufsize, infile, innew);
+		if (innew)
+			innew = false;
 		if (c != 0 || buf[0] != '\0') {	/* normal record */
 			if (isrecord) {
 if (freeable(fldtab[0]))
@@ -217,7 +221,7 @@ void nextfile(void)
 	argno++;
 }
 
-int readrec(char **pbuf, int *pbufsize, FILE *inf)	/* read one record into buf */
+int readrec(char **pbuf, int *pbufsize, FILE *inf, bool newflag)	/* read one record into buf */
 {
 	int sep, c, isrec;
 	char *rr, *buf = *pbuf;
@@ -228,7 +232,14 @@ int readrec(char **pbuf, int *pbufsize, 
 		bool found;
 
 		fa *pfa = makedfa(rs, 1);
-		found = fnematch(pfa, inf, &buf, &bufsize, recsize);
+		if (newflag)
+			found = fnematch(pfa, inf, &buf, &bufsize, recsize);
+		else {
+			int tempstat = pfa->initstat;
+			pfa->initstat = 2;
+			found = fnematch(pfa, inf, &buf, &bufsize, recsize);
+			pfa->initstat = tempstat;
+		}
 		if (found)
 			setptr(patbeg, '\0');
 	} else {
Index: src/external/historical/nawk/dist/main.c
diff -u src/external/historical/nawk/dist/main.c:1.10 src/external/historical/nawk/dist/main.c:1.11
--- src/external/historical/nawk/dist/main.c:1.10	Tue Feb 18 16:12:21 2020
+++ src/external/historical/nawk/dist/main.c	Thu Feb 20 14:59:12 2020
@@ -218,7 +218,9 @@ int main(int argc, char *argv[])
 	if (!safe)
 		envinit(environ);
 	yyparse();
+#if 0
 	setlocale(LC_NUMERIC, ""); /* back to whatever it is locally */
+#endif
 	if (fs)
 		*FS = qstring(fs, '\0');
 	   dprintf( ("errorflag=%d\n", errorflag) );
Index: src/external/historical/nawk/dist/proto.h
diff -u src/external/historical/nawk/dist/proto.h:1.10 src/external/historical/nawk/dist/proto.h:1.11
--- src/external/historical/nawk/dist/proto.h:1.10	Tue Feb 18 16:12:21 2020
+++ src/external/historical/nawk/dist/proto.h	Thu Feb 20 14:59:12 2020
@@ -124,7 +124,7 @@ extern	void	growfldtab(int n);
 extern	void	savefs(void);
 extern	int	getrec(char **, int *, bool);
 extern	void	nextfile(void);
-extern	int	readrec(char **, int *, FILE *);
+extern	int	readrec(char **, int *, FILE *, bool);
 extern	char	*getargv(int);
 extern	void	setclvar(char *);
 extern	void	fldbld(void);
@@ -193,7 +193,7 @@ extern	Cell	*bltin(Node **, int);
 extern	Cell	*printstat(Node **, int);
 extern	Cell	*nullproc(Node **, int);
 extern	FILE	*redirect(int, Node *);
-extern	FILE	*openfile(int, const char *);
+extern	FILE	*openfile(int, const char *, bool *);
 extern	const char	*filename(FILE *);
 extern	Cell	*closefile(Node **, int);
 extern	void	closeall(void);

Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.11 src/external/historical/nawk/dist/run.c:1.12
--- src/external/historical/nawk/dist/run.c:1.11	Tue Feb 18 16:12:21 2020
+++ src/external/historical/nawk/dist/run.c	Thu Feb 20 14:59:12 2020
@@ -409,6 +409,7 @@ Cell *awkgetline(Node **a, int n)	/* get
 	char *buf;
 	int bufsize = recsize;
 	int mode;
+	bool newflag;
 
 	if ((buf = malloc(bufsize)) == NULL)
 		FATAL("out of memory in getline");
@@ -420,12 +421,12 @@ Ce

CVS commit: src/external/historical/nawk/dist

2018-06-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Jun 12 13:24:28 UTC 2018

Modified Files:
src/external/historical/nawk/dist: lex.c

Log Message:
Do not use index out of bounds in nawk

$ awk '{w=$1}' < /dev/null
/public/src.git/external/historical/nawk/bin/../dist/lex.c:476:16: runtime 
error: index -1 out of bounds for type 'const Keyword [46]'

There used to be documented a bug in the code that index ouf of bounds
can in theory fault (by daniel barrett).

Before assigning the pointer, first check for the index whether it's not
not -1. This was a suggested solution in the comment in the code.

The sanitizer is overcautious as this pointer wasn't dereferenced, but
fix is nonetheless.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/lex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lex.c
diff -u src/external/historical/nawk/dist/lex.c:1.3 src/external/historical/nawk/dist/lex.c:1.4
--- src/external/historical/nawk/dist/lex.c:1.3	Fri Sep  1 07:01:06 2017
+++ src/external/historical/nawk/dist/lex.c	Tue Jun 12 13:24:28 2018
@@ -472,9 +472,9 @@ int word(char *w) 
 	int c, n;
 
 	n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
-/* BUG: this ought to be inside the if; in theory could fault (daniel barrett) */
-	kp = keywords + n;
+
 	if (n != -1) {	/* found in table */
+		kp = keywords + n;
 		yylval.i = kp->sub;
 		switch (kp->type) {	/* special handling */
 		case BLTIN:



CVS commit: src/external/historical/nawk/dist

2019-01-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 19 00:37:42 UTC 2019

Modified Files:
src/external/historical/nawk/dist: b.c

Log Message:
PR/53885: Martijn Dekker: Add ERE support from
https://opensource.apple.com/tarballs/awk/awk-24.tar.gz


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/external/historical/nawk/dist/b.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/b.c
diff -u src/external/historical/nawk/dist/b.c:1.5 src/external/historical/nawk/dist/b.c:1.6
--- src/external/historical/nawk/dist/b.c:1.5	Wed Jan  2 08:46:17 2013
+++ src/external/historical/nawk/dist/b.c	Fri Jan 18 19:37:41 2019
@@ -70,6 +70,11 @@ int	rlxval;
 static const uschar	*rlxstr;
 static const uschar	*prestr;	/* current position in current re */
 static const uschar	*lastre;	/* origin of last re */
+static const uschar	*lastatom;	/* origin of last Atom */
+static const uschar	*starttok;
+static const uschar 	*basestr;	/* starts with original, replaced during
+	   repetition processing */
+static const uschar 	*firstbasestr;
 
 static	int setcnt;
 static	int poscnt;
@@ -176,6 +181,8 @@ fa *mkdfa(const char *s, int anchor)	/* 
 	Node *p, *p1;
 	fa *f;
 
+	firstbasestr = s;
+	basestr = firstbasestr;
 	p = reparse(s);
 	p1 = op2(CAT, op2(STAR, op2(ALL, NIL, NIL), NIL), p);
 		/* put ALL STAR in front of reg.  exp. */
@@ -198,6 +205,10 @@ fa *mkdfa(const char *s, int anchor)	/* 
 	f->initstat = makeinit(f, anchor);
 	f->anchor = anchor;
 	f->restr = (uschar *) tostring(s);
+	if (firstbasestr != basestr) {
+		if (basestr)
+			free(__UNCONST(basestr));
+	}
 	return f;
 }
 
@@ -740,9 +751,11 @@ Node *regexp(void)	/* top-level parse of
 Node *primary(void)
 {
 	Node *np;
+	int savelastatom;
 
 	switch (rtok) {
 	case CHAR:
+		lastatom = starttok;
 		np = op2(CHAR, NIL, itonp(rlxval));
 		rtok = relex();
 		return (unary(np));
@@ -751,16 +764,19 @@ Node *primary(void)
 		return (unary(op2(ALL, NIL, NIL)));
 	case EMPTYRE:
 		rtok = relex();
-		return (unary(op2(ALL, NIL, NIL)));
+		return (unary(op2(EMPTYRE, NIL, NIL)));
 	case DOT:
+		lastatom = starttok;
 		rtok = relex();
 		return (unary(op2(DOT, NIL, NIL)));
 	case CCL:
 		np = op2(CCL, NIL, (Node*) cclenter((const char *) rlxstr));
+		lastatom = starttok;
 		rtok = relex();
 		return (unary(np));
 	case NCCL:
 		np = op2(NCCL, NIL, (Node *) cclenter((const char *) rlxstr));
+		lastatom = starttok;
 		rtok = relex();
 		return (unary(np));
 	case '^':
@@ -770,6 +786,8 @@ Node *primary(void)
 		rtok = relex();
 		return (unary(op2(CHAR, NIL, NIL)));
 	case '(':
+		lastatom = starttok;
+		savelastatom = starttok - basestr; /* Retain over recursion */
 		rtok = relex();
 		if (rtok == ')') {	/* special pleading for () */
 			rtok = relex();
@@ -777,6 +795,7 @@ Node *primary(void)
 		}
 		np = regexp();
 		if (rtok == ')') {
+			lastatom = basestr + savelastatom; /* Restore */
 			rtok = relex();
 			return (unary(np));
 		}
@@ -791,8 +810,12 @@ Node *primary(void)
 Node *concat(Node *np)
 {
 	switch (rtok) {
-	case CHAR: case DOT: case ALL: case EMPTYRE: case CCL: case NCCL: case '$': case '(':
+	case CHAR: case DOT: case ALL: case CCL: case NCCL: case '$': case '(':
 		return (concat(op2(CAT, np, primary(;
+	case EMPTYRE:
+		rtok = relex();
+		return (concat(op2(CAT, op2(CCL, NIL, (Node *) tostring("")),
+primary(;
 	}
 	return (np);
 }
@@ -869,6 +892,115 @@ static const struct charclass {
 	{ NULL,		0,	NULL },
 };
 
+#define REPEAT_SIMPLE		0
+#define REPEAT_PLUS_APPENDED	1
+#define REPEAT_WITH_Q		2
+#define REPEAT_ZERO		3
+
+static int
+replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom,
+	   int atomlen, int firstnum, int secondnum, int special_case)
+{
+	int i, j;
+	uschar *buf = 0;
+	int ret = 1;
+	int init_q = (firstnum==0);		/* first added char will be ? */
+	int n_q_reps = secondnum-firstnum;	/* m>n, so reduce until {1,m-n} left  */ 
+	int prefix_length = reptok - basestr;	/* prefix includes first rep	*/ 
+	int suffix_length = strlen(reptok) - reptoklen;	/* string after rep specifier	*/
+	int size = prefix_length +  suffix_length;
+
+	if (firstnum > 1) {	/* add room for reps 2 through firstnum */
+		size += atomlen*(firstnum-1);
+	}
+
+	/* Adjust size of buffer for special cases */
+	if (special_case == REPEAT_PLUS_APPENDED) {
+		size++;		/* for the final + */
+	} else if (special_case == REPEAT_WITH_Q) {
+		size += init_q + (atomlen+1)* n_q_reps;
+	} else if (special_case == REPEAT_ZERO) {
+		size += 2;	/* just a null ERE: () */
+	}
+	if ((buf = (uschar *) malloc(size+1)) == NULL)
+		FATAL("out of space in reg expr %.10s..", lastre);
+	memcpy(buf, basestr, prefix_length);	/* copy prefix	*/ 
+	j = prefix_length;
+	if (special_case == REPEAT_ZERO) {
+		j -= atomlen;
+		buf[j++] = '(';
+		buf[j++] = ')';
+	}
+	for (i=1; i < firstnum; i++) {		/* copy x reps 	*/
+		memcpy(&bu

CVS commit: src/external/historical/nawk/dist

2017-09-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Sep  1 07:01:06 UTC 2017

Modified Files:
src/external/historical/nawk/dist: lex.c

Log Message:
PR/52516: Guy Incognito: Fix memory leak; setsymtab already calls tostring()
for the buffer, don't do it twice.
XXX: pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/lex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lex.c
diff -u src/external/historical/nawk/dist/lex.c:1.2 src/external/historical/nawk/dist/lex.c:1.3
--- src/external/historical/nawk/dist/lex.c:1.2	Thu Aug 26 10:55:19 2010
+++ src/external/historical/nawk/dist/lex.c	Fri Sep  1 03:01:06 2017
@@ -201,7 +201,7 @@ int yylex(void)
 		if (isalpha(c) || c == '_')
 			return word(buf);
 		if (isdigit(c)) {
-			yylval.cp = setsymtab(buf, tostring(buf), atof(buf), CON|NUM, symtab);
+			yylval.cp = setsymtab(buf, buf, atof(buf), CON|NUM, symtab);
 			/* should this also have STR set? */
 			RET(NUMBER);
 		}



CVS commit: src/external/historical/nawk/dist

2012-12-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Dec 29 02:14:53 UTC 2012

Update of /cvsroot/src/external/historical/nawk/dist
In directory ivanova.netbsd.org:/tmp/cvs-serv29526

Log Message:
from http://www.cs.princeton.edu/~bwk/btl.mirror/

Status:

Vendor Tag: NAWK
Release Tags:   NAWK20121220

C src/external/historical/nawk/dist/awkgram.y
U src/external/historical/nawk/dist/README
U src/external/historical/nawk/dist/FIXES
U src/external/historical/nawk/dist/awk.h
N src/external/historical/nawk/dist/ytab.c
N src/external/historical/nawk/dist/ytab.h
C src/external/historical/nawk/dist/proto.h
U src/external/historical/nawk/dist/maketab.c
C src/external/historical/nawk/dist/lex.c
C src/external/historical/nawk/dist/b.c
C src/external/historical/nawk/dist/main.c
C src/external/historical/nawk/dist/proctab.c
U src/external/historical/nawk/dist/parse.c
C src/external/historical/nawk/dist/lib.c
C src/external/historical/nawk/dist/run.c
C src/external/historical/nawk/dist/tran.c
C src/external/historical/nawk/dist/makefile
U src/external/historical/nawk/dist/awk.1

10 conflicts created by this import.
Use the following command to help the merge:

cvs checkout -jNAWK:yesterday -jNAWK src/external/historical/nawk/dist



CVS commit: src/external/historical/nawk/dist

2012-12-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Dec 29 02:44:26 UTC 2012

Modified Files:
src/external/historical/nawk/dist: awkgram.y b.c lib.c main.c makefile
proctab.c proto.h run.c tran.c

Log Message:
merge 2012-12-20


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/awkgram.y \
src/external/historical/nawk/dist/b.c \
src/external/historical/nawk/dist/proctab.c
cvs rdiff -u -r1.5 -r1.6 src/external/historical/nawk/dist/lib.c \
src/external/historical/nawk/dist/run.c
cvs rdiff -u -r1.7 -r1.8 src/external/historical/nawk/dist/main.c
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/makefile
cvs rdiff -u -r1.6 -r1.7 src/external/historical/nawk/dist/proto.h \
src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/awkgram.y
diff -u src/external/historical/nawk/dist/awkgram.y:1.3 src/external/historical/nawk/dist/awkgram.y:1.4
--- src/external/historical/nawk/dist/awkgram.y:1.3	Sat May 28 11:13:04 2011
+++ src/external/historical/nawk/dist/awkgram.y	Fri Dec 28 21:44:26 2012
@@ -179,8 +179,8 @@ pa_pat:
 pa_stat:
 	  pa_pat			{ $$ = stat2(PASTAT, $1, stat2(PRINT, rectonode(), NIL)); }
 	| pa_pat lbrace stmtlist '}'	{ $$ = stat2(PASTAT, $1, $3); }
-	| pa_pat ',' pa_pat		{ $$ = pa2stat($1, $3, stat2(PRINT, rectonode(), NIL)); }
-	| pa_pat ',' pa_pat lbrace stmtlist '}'	{ $$ = pa2stat($1, $3, $5); }
+	| pa_pat ',' opt_nl pa_pat		{ $$ = pa2stat($1, $4, stat2(PRINT, rectonode(), NIL)); }
+	| pa_pat ',' opt_nl pa_pat lbrace stmtlist '}'	{ $$ = pa2stat($1, $4, $6); }
 	| lbrace stmtlist '}'		{ $$ = stat2(PASTAT, NIL, $2); }
 	| XBEGIN lbrace stmtlist '}'
 		{ beginloc = linkum(beginloc, $3); $$ = 0; }
Index: src/external/historical/nawk/dist/b.c
diff -u src/external/historical/nawk/dist/b.c:1.3 src/external/historical/nawk/dist/b.c:1.4
--- src/external/historical/nawk/dist/b.c:1.3	Sat Mar 10 14:18:48 2012
+++ src/external/historical/nawk/dist/b.c	Fri Dec 28 21:44:26 2012
@@ -843,7 +843,7 @@ Node *unary(Node *np)
  * to nelson beebe for the suggestion; let's see if it works everywhere.
  */
 
-/* #define HAS_ISBLANK */
+#define HAS_ISBLANK
 
 static const struct charclass {
 	const char *cc_name;
@@ -852,7 +852,11 @@ static const struct charclass {
 } charclasses[] = {
 	{ "alnum",	5,	isalnum },
 	{ "alpha",	5,	isalpha },
+#ifndef HAS_ISBLANK
+	{ "blank",	5,	isspace }, /* was isblank */
+#else
 	{ "blank",	5,	isblank },
+#endif
 	{ "cntrl",	5,	iscntrl },
 	{ "digit",	5,	isdigit },
 	{ "graph",	5,	isgraph },
Index: src/external/historical/nawk/dist/proctab.c
diff -u src/external/historical/nawk/dist/proctab.c:1.3 src/external/historical/nawk/dist/proctab.c:1.4
--- src/external/historical/nawk/dist/proctab.c:1.3	Fri Aug 27 12:49:47 2010
+++ src/external/historical/nawk/dist/proctab.c	Fri Dec 28 21:44:26 2012
@@ -7,100 +7,100 @@
 #include "awkgram.h"
 
 static const char * const printname[94] = {
-	"FIRSTTOKEN",	/* 257 */
-	"PROGRAM",	/* 258 */
-	"PASTAT",	/* 259 */
-	"PASTAT2",	/* 260 */
-	"XBEGIN",	/* 261 */
-	"XEND",	/* 262 */
-	"NL",	/* 263 */
-	"ARRAY",	/* 264 */
-	"MATCH",	/* 265 */
-	"NOTMATCH",	/* 266 */
-	"MATCHOP",	/* 267 */
-	"FINAL",	/* 268 */
-	"DOT",	/* 269 */
-	"ALL",	/* 270 */
-	"CCL",	/* 271 */
-	"NCCL",	/* 272 */
-	"CHAR",	/* 273 */
-	"OR",	/* 274 */
-	"STAR",	/* 275 */
-	"QUEST",	/* 276 */
-	"PLUS",	/* 277 */
-	"EMPTYRE",	/* 278 */
-	"AND",	/* 279 */
-	"BOR",	/* 280 */
-	"APPEND",	/* 281 */
-	"EQ",	/* 282 */
-	"GE",	/* 283 */
-	"GT",	/* 284 */
-	"LE",	/* 285 */
-	"LT",	/* 286 */
-	"NE",	/* 287 */
-	"IN",	/* 288 */
-	"ARG",	/* 289 */
-	"BLTIN",	/* 290 */
-	"BREAK",	/* 291 */
-	"CLOSE",	/* 292 */
-	"CONTINUE",	/* 293 */
-	"DELETE",	/* 294 */
-	"DO",	/* 295 */
-	"EXIT",	/* 296 */
-	"FOR",	/* 297 */
-	"FUNC",	/* 298 */
-	"SUB",	/* 299 */
-	"GSUB",	/* 300 */
-	"IF",	/* 301 */
-	"INDEX",	/* 302 */
-	"LSUBSTR",	/* 303 */
-	"MATCHFCN",	/* 304 */
-	"NEXT",	/* 305 */
-	"NEXTFILE",	/* 306 */
-	"ADD",	/* 307 */
-	"MINUS",	/* 308 */
-	"MULT",	/* 309 */
-	"DIVIDE",	/* 310 */
-	"MOD",	/* 311 */
-	"ASSIGN",	/* 312 */
-	"ASGNOP",	/* 313 */
-	"ADDEQ",	/* 314 */
-	"SUBEQ",	/* 315 */
-	"MULTEQ",	/* 316 */
-	"DIVEQ",	/* 317 */
-	"MODEQ",	/* 318 */
-	"POWEQ",	/* 319 */
-	"PRINT",	/* 320 */
-	"PRINTF",	/* 321 */
-	"SPRINTF",	/* 322 */
-	"ELSE",	/* 323 */
-	"INTEST",	/* 324 */
-	"CONDEXPR",	/* 325 */
-	"POSTINCR",	/* 326 */
-	"PREINCR",	/* 327 */
-	"POSTDECR",	/* 328 */
-	"PREDECR",	/* 329 */
-	"VAR",	/* 330 */
-	"IVAR",	/* 331 */
-	"VARNF",	/* 332 */
-	"CALL",	/* 333 */
-	"NUMBER",	/* 334 */
-	"STRING",	/* 335 */
-	"REGEXPR",	/* 336 */
-	"GETLINE",	/* 337 */
-	"GENSUB",	/* 338 */
-	"RETURN",	/* 339 */
-	"SPLIT",	/* 340 */
-	"SUBSTR",	/* 341 */
-	"WHILE",	/* 342 */
-	"CAT",	/* 343 */
-	"NOT",	/* 344 */
-	"UMINUS",	/* 345 */
-	"POWER",	/* 346 */
-	"DECR",	/* 347 */

CVS commit: src/external/historical/nawk/dist

2012-12-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Dec 29 14:51:41 UTC 2012

Modified Files:
src/external/historical/nawk/dist: lib.c

Log Message:
remove useless cast.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/historical/nawk/dist/lib.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.6 src/external/historical/nawk/dist/lib.c:1.7
--- src/external/historical/nawk/dist/lib.c:1.6	Fri Dec 28 21:44:26 2012
+++ src/external/historical/nawk/dist/lib.c	Sat Dec 29 09:51:41 2012
@@ -546,7 +546,7 @@ void recbld(void)	/* create $0 from $1..
 	fldtab[0]->tval = REC | STR | DONTFREE;
 	fldtab[0]->sval = record;
 
-	   dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) );
+	   dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, fldtab[0]) );
 	   dprintf( ("recbld = |%s|\n", record) );
 	donerec = 1;
 }



CVS commit: src/external/historical/nawk/dist

2013-01-02 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan  2 13:46:17 UTC 2013

Modified Files:
src/external/historical/nawk/dist: b.c

Log Message:
we define HAS_ISBLANK in the Makefile


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/historical/nawk/dist/b.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/b.c
diff -u src/external/historical/nawk/dist/b.c:1.4 src/external/historical/nawk/dist/b.c:1.5
--- src/external/historical/nawk/dist/b.c:1.4	Fri Dec 28 21:44:26 2012
+++ src/external/historical/nawk/dist/b.c	Wed Jan  2 08:46:17 2013
@@ -843,7 +843,7 @@ Node *unary(Node *np)
  * to nelson beebe for the suggestion; let's see if it works everywhere.
  */
 
-#define HAS_ISBLANK
+/* #define HAS_ISBLANK */
 
 static const struct charclass {
 	const char *cc_name;



CVS commit: src/external/historical/nawk/dist

2013-02-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 11 00:32:08 UTC 2013

Modified Files:
src/external/historical/nawk/dist: tran.c

Log Message:
PR/47553: Aleksev Cheusov: awk segfault: NULL dereference.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.7 src/external/historical/nawk/dist/tran.c:1.8
--- src/external/historical/nawk/dist/tran.c:1.7	Fri Dec 28 21:44:26 2012
+++ src/external/historical/nawk/dist/tran.c	Sun Feb 10 19:32:07 2013
@@ -358,7 +358,7 @@ char *setsval(Cell *vp, const char *s)	/
 		donefld = 0;	/* mark $1... invalid */
 		donerec = 1;
 	}
-	t = tostring(s);	/* in case it's self-assign */
+	t = s ? tostring(s) : tostring("");	/* in case it's self-assign */
 	if (freeable(vp))
 		xfree(vp->sval);
 	vp->tval &= ~NUM;



CVS commit: src/external/historical/nawk/dist

2012-03-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 10 19:18:48 UTC 2012

Modified Files:
src/external/historical/nawk/dist: b.c lib.c proto.h run.c

Log Message:
PR/46155: Miguel Pi�eiro Jr: Fix RS processing. Apply the gawk-like patch
from the excellent PR. Many thanks for all the work you put on this,
explanation, tests, and patch!


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/b.c
cvs rdiff -u -r1.4 -r1.5 src/external/historical/nawk/dist/lib.c \
src/external/historical/nawk/dist/run.c
cvs rdiff -u -r1.5 -r1.6 src/external/historical/nawk/dist/proto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/b.c
diff -u src/external/historical/nawk/dist/b.c:1.2 src/external/historical/nawk/dist/b.c:1.3
--- src/external/historical/nawk/dist/b.c:1.2	Thu Aug 26 10:55:19 2010
+++ src/external/historical/nawk/dist/b.c	Sat Mar 10 14:18:48 2012
@@ -624,6 +624,96 @@ int nematch(fa *f, const char *p0)	/* no
 	return (0);
 }
 
+
+/*
+ * NAME
+ * fnematch
+ *
+ * DESCRIPTION
+ * A stream-fed version of nematch which transfers characters to a
+ * null-terminated buffer. All characters up to and including the last
+ * character of the matching text or EOF are placed in the buffer. If
+ * a match is found, patbeg and patlen are set appropriately.
+ *
+ * RETURN VALUES
+ * 0No match found.
+ * 1Match found.
+ */  
+
+int fnematch(fa *pfa, FILE *f, uschar **pbuf, int *pbufsize, int quantum)	
+{
+	uschar *buf = *pbuf;
+	int bufsize = *pbufsize;
+	int c, i, j, k, ns, s;
+
+	s = pfa->initstat;
+	assert(s < pfa->state_count);
+	patlen = 0;
+
+	/*
+	 * All indices relative to buf.
+	 * i <= j <= k <= bufsize
+	 *
+	 * i: origin of active substring
+	 * j: current character
+	 * k: destination of next getc()
+	 */
+	i = -1, k = 0;
+do {
+		j = i++;
+		do {
+			if (++j == k) {
+if (k == bufsize)
+	if (!adjbuf(&buf, &bufsize, bufsize+1, quantum, 0, "fnematch"))
+		FATAL("stream '%.30s...' too long", buf);	
+buf[k++] = (c = getc(f)) != EOF ? c : 0;
+			}
+			c = buf[j];
+			/* assert(c < NCHARS); */
+
+			if ((ns = pfa->gototab[s][c]) != 0)
+s = ns;
+			else
+s = cgoto(pfa, s, c);
+			assert(s < pfa->state_count);
+
+			if (pfa->out[s]) {	/* final state */
+patlen = j - i + 1;
+if (c == 0)	/* don't count $ */
+	patlen--;
+			}
+		} while (buf[j] && s != 1);
+		s = 2;
+	} while (buf[i] && !patlen);
+
+	/* adjbuf() may have relocated a resized buffer. Inform the world. */
+	*pbuf = buf;
+	*pbufsize = bufsize;
+
+	if (patlen) {
+		patbeg = buf + i;
+		/*
+		 * Under no circumstances is the last character fed to
+		 * the automaton part of the match. It is EOF's nullbyte,
+		 * or it sent the automaton into a state with no further
+		 * transitions available (s==1), or both. Room for a
+		 * terminating nullbyte is guaranteed.
+		 *
+		 * ungetc any chars after the end of matching text
+		 * (except for EOF's nullbyte, if present) and null
+		 * terminate the buffer.
+		 */
+		do
+			if (buf[--k] && ungetc(buf[k], f) == EOF)
+FATAL("unable to ungetc '%c'", buf[k]);	
+		while (k > i + patlen);
+		buf[k] = 0;
+		return 1;
+	}
+	else
+		return 0;
+}
+
 Node *reparse(const char *p)	/* parses regular expression pointed to by p */
 {			/* uses relex() to scan regular expression */
 	Node *np;

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.4 src/external/historical/nawk/dist/lib.c:1.5
--- src/external/historical/nawk/dist/lib.c:1.4	Thu Jan 20 16:23:11 2011
+++ src/external/historical/nawk/dist/lib.c	Sat Mar 10 14:18:48 2012
@@ -38,6 +38,7 @@ THIS SOFTWARE.
 
 char	EMPTY[] = { '\0' };
 FILE	*infile	= NULL;
+int	innew;		/* 1 = infile has not been read by readrec */
 char	*file	= EMPTY;
 uschar	*record;
 int	recsize	= RECSIZE;
@@ -104,6 +105,7 @@ void initgetrec(void)
 		argno++;
 	}
 	infile = stdin;		/* no filenames, so use stdin */
+	innew = 1;
 }
 
 static int firsttime = 1;
@@ -146,9 +148,12 @@ int getrec(uschar **pbuf, int *pbufsize,
 infile = stdin;
 			else if ((infile = fopen(file, "r")) == NULL)
 FATAL("can't open file %s", file);
+			innew = 1;
 			setfval(fnrloc, 0.0);
 		}
-		c = readrec(&buf, &bufsize, infile);
+		c = readrec(&buf, &bufsize, infile, innew);
+		if (innew)
+			innew = 0;
 		if (c != 0 || buf[0] != '\0') {	/* normal record */
 			if (isrecord) {
 if (freeable(fldtab[0]))
@@ -186,9 +191,9 @@ void nextfile(void)
 	argno++;
 }
 
-int readrec(uschar **pbuf, int *pbufsize, FILE *inf)	/* read one record into buf */
+int readrec(uschar **pbuf, int *pbufsize, FILE *inf, int newflag)	/* read one record into buf */
 {
-	int sep, c;
+	int sep, c, isrec, found, tempstat;
 	uschar *rr, *buf = *pbuf;
 	int bufsize = *pbufsize;
 	size_t len;
@@ -202,48 +207,26 @@ int readrec(uschar **pbuf, int *p

CVS commit: src/external/historical/nawk/dist

2012-03-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar 12 18:17:12 UTC 2012

Modified Files:
src/external/historical/nawk/dist: main.c

Log Message:
don't switch back LC_NUMERIC after parsing the command line, we always want
to format numbers in the C locale.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/historical/nawk/dist/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/main.c
diff -u src/external/historical/nawk/dist/main.c:1.6 src/external/historical/nawk/dist/main.c:1.7
--- src/external/historical/nawk/dist/main.c:1.6	Fri Sep 16 12:09:46 2011
+++ src/external/historical/nawk/dist/main.c	Mon Mar 12 14:17:12 2012
@@ -211,7 +211,6 @@ int main(int argc, char *argv[])
 	if (!safe)
 		envinit(environ);
 	yyparse();
-	setlocale(LC_NUMERIC, ""); /* back to whatever it is locally */
 	if (fs)
 		*FS = qstring(fs, '\0');
 	   dprintf( ("errorflag=%d\n", errorflag) );



CVS commit: src/external/historical/nawk/dist

2012-12-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 10 19:49:05 UTC 2012

Modified Files:
src/external/historical/nawk/dist: tran.c

Log Message:
PR/47306: Aleksey Cheusov: Don't free strings of symbols where we maintain
pointers to.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.5 src/external/historical/nawk/dist/tran.c:1.6
--- src/external/historical/nawk/dist/tran.c:1.5	Sat May 28 11:13:04 2011
+++ src/external/historical/nawk/dist/tran.c	Mon Dec 10 14:49:05 2012
@@ -71,6 +71,18 @@ Cell	*literal0;
 
 extern Cell **fldtab;
 
+static void
+setfree(Cell *vp)
+{
+	if (&vp->sval == FS || &vp->sval == RS ||
+	&vp->sval == OFS || &vp->sval == ORS ||
+	&vp->sval == OFMT || &vp->sval == CONVFMT ||
+	&vp->sval == FILENAME || &vp->sval == SUBSEP)
+		vp->tval |= DONTFREE;
+	else
+		vp->tval &= ~DONTFREE;
+}
+
 void syminit(void)	/* initialize symbol table with builtin vars */
 {
 	literal0 = setsymtab("0", "0", 0.0, NUM|STR|CON|DONTFREE, symtab);
@@ -349,7 +361,7 @@ char *setsval(Cell *vp, const char *s)	/
 		xfree(vp->sval);
 	vp->tval &= ~NUM;
 	vp->tval |= STR;
-	vp->tval &= ~DONTFREE;
+	setfree(vp);
 	   dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n", 
 		vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
 
@@ -400,8 +412,8 @@ static char *get_str_val(Cell *vp, char 
 		else
 			snprintf(s, sizeof(s), *fmt, vp->fval);
 		vp->sval = tostring(s);
-		vp->tval &= ~DONTFREE;
 		vp->tval |= STR;
+		setfree(vp);
 	}
 	   dprintf( ("getsval %p: %s = \"%s (%p)\", t=%o\n", vp, NN(vp->nval), vp->sval, vp->sval, vp->tval) );
 	return(vp->sval);



CVS commit: src/external/historical/nawk/dist

2013-10-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 20 21:35:46 UTC 2013

Modified Files:
src/external/historical/nawk/dist: lib.c

Log Message:
remove unused variable


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/historical/nawk/dist/lib.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.7 src/external/historical/nawk/dist/lib.c:1.8
--- src/external/historical/nawk/dist/lib.c:1.7	Sat Dec 29 09:51:41 2012
+++ src/external/historical/nawk/dist/lib.c	Sun Oct 20 17:35:46 2013
@@ -753,10 +753,9 @@ int isclvar(const char *s)	/* is s of fo
 #include 
 int is_number(const char *s)
 {
-	double r;
 	char *ep;
 	errno = 0;
-	r = strtod(s, &ep);
+	(void)strtod(s, &ep);
 	if (ep == s || errno == ERANGE)
 		return 0;
 	if (ep - s >= 3 && strncasecmp(ep - 3, "nan", 3) == 0)



CVS commit: src/external/historical/nawk/dist

2013-10-27 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Oct 27 10:06:01 UTC 2013

Modified Files:
src/external/historical/nawk/dist: run.c

Log Message:
Fix memory leak in gensub()


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.6 src/external/historical/nawk/dist/run.c:1.7
--- src/external/historical/nawk/dist/run.c:1.6	Sat Dec 29 02:44:26 2012
+++ src/external/historical/nawk/dist/run.c	Sun Oct 27 10:06:01 2013
@@ -2074,6 +2074,7 @@ Cell *gensub(Node **a, int nnn)	/* globa
 	x = execute(a[4]);	/* source string */
 	t = getsval(x);
 	res = copycell(x);	/* target string - initially copy of source */
+	res->csub = CTEMP;	/* result values are temporary */
 	if (a[0] == 0)		/* 0 => a[1] is already-compiled regexpr */
 		pfa = (fa *) a[1];	/* regular expression */
 	else {



CVS commit: src/external/historical/nawk/dist

2013-12-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 15 06:41:18 UTC 2013

Modified Files:
src/external/historical/nawk/dist: run.c

Log Message:
PR/48448: David A. Holland: Avoid coredump by checking return code of
localtime(3)


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.7 src/external/historical/nawk/dist/run.c:1.8
--- src/external/historical/nawk/dist/run.c:1.7	Sun Oct 27 06:06:01 2013
+++ src/external/historical/nawk/dist/run.c	Sun Dec 15 01:41:18 2013
@@ -1647,6 +1647,8 @@ Cell *bltin(Node **a, int n)	/* builtin 
 		} else
 			tv = time((time_t *) 0);
 		tm = localtime(&tv);
+		if (tm == NULL)
+			FATAL("bad time %jd", (intmax_t)tv);
 
 		if (isrec(x)) {
 			/* format argument not provided, use default */



CVS commit: src/external/historical/nawk/dist

2011-05-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat May 28 15:13:04 UTC 2011

Modified Files:
src/external/historical/nawk/dist: awkgram.y proto.h tran.c

Log Message:
Handle string concatenation in terms:
'{ print "foo" > "file" ".txt"; }',


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/awkgram.y
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/proto.h
cvs rdiff -u -r1.4 -r1.5 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/awkgram.y
diff -u src/external/historical/nawk/dist/awkgram.y:1.2 src/external/historical/nawk/dist/awkgram.y:1.3
--- src/external/historical/nawk/dist/awkgram.y:1.2	Thu Aug 26 10:55:19 2010
+++ src/external/historical/nawk/dist/awkgram.y	Sat May 28 11:13:04 2011
@@ -75,6 +75,7 @@
 %type		do st
 %type		pst opt_pst lbrace rbrace rparen comma nl opt_nl and bor
 %type		subop print
+%type		string
 
 %right	ASGNOP
 %right	'?'
@@ -352,6 +353,11 @@
 	  SUB | GSUB
 	;
 
+string:
+	  STRING
+	| string STRING		{ $$ = catstr($1, $2); }
+	;
+
 term:
  	  term '/' ASGNOP term		{ $$ = op2(DIVEQ, $1, $4); }
  	| term '+' term			{ $$ = op2(ADD, $1, $3); }
@@ -414,7 +420,7 @@
 	| SPLIT '(' pattern comma varname ')'
 		{ $$ = op4(SPLIT, $3, makearr($5), NIL, (Node*)STRING); }  /* default */
 	| SPRINTF '(' patlist ')'	{ $$ = op1($1, $3); }
-	| STRING	 		{ $$ = celltonode($1, CCON); }
+	| string	 		{ $$ = celltonode($1, CCON); }
 	| subop '(' reg_expr comma pattern ')'
 		{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, rectonode()); }
 	| subop '(' pattern comma pattern ')'

Index: src/external/historical/nawk/dist/proto.h
diff -u src/external/historical/nawk/dist/proto.h:1.3 src/external/historical/nawk/dist/proto.h:1.4
--- src/external/historical/nawk/dist/proto.h:1.3	Sun Nov  7 17:55:26 2010
+++ src/external/historical/nawk/dist/proto.h	Sat May 28 11:13:04 2011
@@ -114,6 +114,7 @@
 extern	char	*tostring(const char *);
 extern	char	*tostringN(const char *, size_t n);
 extern	char	*qstring(const char *, int);
+extern	Cell	*catstr(Cell *, Cell *);
 
 extern	void	recinit(unsigned int);
 extern	void	initgetrec(void);

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.4 src/external/historical/nawk/dist/tran.c:1.5
--- src/external/historical/nawk/dist/tran.c:1.4	Thu Jan 20 16:26:20 2011
+++ src/external/historical/nawk/dist/tran.c	Sat May 28 11:13:04 2011
@@ -428,6 +428,22 @@
 	return(p);
 }
 
+Cell *catstr(Cell *a, Cell *b) /* concatenate a and b */
+{
+	Cell *c;
+	char *p;
+	char *sa = getsval(a);
+	char *sb = getsval(b);
+	size_t l = strlen(sa) + strlen(sb) + 1;
+	p = malloc(l);
+	if (p == NULL)
+		FATAL("out of space concatenating %s and %s", sa, sb);
+	snprintf(p, l, "%s%s", sa, sb);
+	c = setsymtab(p, p, 0.0, CON|STR|DONTFREE, symtab);
+	free(p);
+	return c;
+}
+
 char *tostringN(const char *s, size_t n)	/* make a copy of string s */
 {
 	char *p;



CVS commit: src/external/historical/nawk/dist

2011-04-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr 18 15:23:28 UTC 2011

Modified Files:
src/external/historical/nawk/dist: main.c run.c

Log Message:
PR/44876: Aleksey Cheusov: awk: incorrect return value of function srand()
Make it return the value of the previous random seed as the standard mandates.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/historical/nawk/dist/main.c
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/main.c
diff -u src/external/historical/nawk/dist/main.c:1.4 src/external/historical/nawk/dist/main.c:1.5
--- src/external/historical/nawk/dist/main.c:1.4	Mon Oct 18 11:58:05 2010
+++ src/external/historical/nawk/dist/main.c	Mon Apr 18 11:23:28 2011
@@ -42,6 +42,7 @@
 extern	int	nfields;
 
 int	dbg	= 0;
+unsigned int srand_seed;
 char	*cmdname;	/* gets argv[0] for error messages */
 extern	FILE	*yyin;	/* lex input file */
 char	*lexprog;	/* points to program argument if it exists */
@@ -122,6 +123,10 @@
 #else
 	(void)signal(SIGFPE, fpecatch);
 #endif
+	/* Set and keep track of the random seed */
+	srand_seed = 1;
+	srand(srand_seed);
+
 	yyin = NULL;
 	symtab = makesymtab(NSYMTAB/NSYMTAB);
 	while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {

Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.2 src/external/historical/nawk/dist/run.c:1.3
--- src/external/historical/nawk/dist/run.c:1.2	Thu Aug 26 10:55:20 2010
+++ src/external/historical/nawk/dist/run.c	Mon Apr 18 11:23:28 2011
@@ -74,6 +74,7 @@
 
 jmp_buf env;
 extern	int	pairstack[];
+extern	unsigned int srand_seed;
 
 Node	*winner = NULL;	/* root of parse tree */
 Cell	*tmps;		/* free temporary cells for execution */
@@ -1546,6 +1547,7 @@
 	Cell *x, *y;
 	Awkfloat u;
 	int t, sz;
+	unsigned int tmp;
 	char *buf, *fmt;
 	Node *nextarg;
 	FILE *fp;
@@ -1598,7 +1600,9 @@
 			u = time((time_t *)0);
 		else
 			u = getfval(x);
-		srand((unsigned int) u);
+		srand(tmp = (unsigned int) u);
+		u = srand_seed;
+		srand_seed = tmp;
 		break;
 	case FTOUPPER:
 	case FTOLOWER:



CVS commit: src/external/historical/nawk/dist

2011-09-16 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Sep 16 16:09:47 UTC 2011

Modified Files:
src/external/historical/nawk/dist: main.c proto.h

Log Message:
Use __dead


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/external/historical/nawk/dist/main.c
cvs rdiff -u -r1.4 -r1.5 src/external/historical/nawk/dist/proto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/main.c
diff -u src/external/historical/nawk/dist/main.c:1.5 src/external/historical/nawk/dist/main.c:1.6
--- src/external/historical/nawk/dist/main.c:1.5	Mon Apr 18 15:23:28 2011
+++ src/external/historical/nawk/dist/main.c	Fri Sep 16 16:09:46 2011
@@ -71,7 +71,7 @@
 	return NULL;
 }
 
-static void fpecatch(int n
+__dead static void fpecatch(int n
 #ifdef SA_SIGINFO
 	, siginfo_t *si, void *uc
 #endif

Index: src/external/historical/nawk/dist/proto.h
diff -u src/external/historical/nawk/dist/proto.h:1.4 src/external/historical/nawk/dist/proto.h:1.5
--- src/external/historical/nawk/dist/proto.h:1.4	Sat May 28 15:13:04 2011
+++ src/external/historical/nawk/dist/proto.h	Fri Sep 16 16:09:46 2011
@@ -46,7 +46,7 @@
 extern	int	hexstr(const uschar **);
 extern	int	quoted(const uschar **);
 extern	char	*cclenter(const char *);
-extern	void	overflo(const char *);
+extern	void	overflo(const char *) __dead;
 extern	void	cfoll(fa *, Node *);
 extern	int	first(Node *);
 extern	void	follow(Node *);
@@ -137,7 +137,7 @@
 extern	void	bcheck2(int, int, int);
 extern	void	SYNTAX(const char *, ...)
 __attribute__((__format__(__printf__, 1, 2)));
-extern	void	FATAL(const char *, ...)
+extern	void	FATAL(const char *, ...) __dead
 __attribute__((__format__(__printf__, 1, 2)));
 extern	void	WARNING(const char *, ...)
 __attribute__((__format__(__printf__, 1, 2)));



CVS commit: src/external/historical/nawk/dist

2011-11-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Nov 22 22:30:22 UTC 2011

Modified Files:
src/external/historical/nawk/dist: run.c

Log Message:
- make decimal conversions use the maximum width integers available on the
  architecture.
- make signed and unsigned code consistent.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.3 src/external/historical/nawk/dist/run.c:1.4
--- src/external/historical/nawk/dist/run.c:1.3	Mon Apr 18 11:23:28 2011
+++ src/external/historical/nawk/dist/run.c	Tue Nov 22 17:30:22 2011
@@ -37,6 +37,7 @@ THIS SOFTWARE.
 #include 
 #include 
 #include 
+#include 
 #include "awk.h"
 #include "awkgram.h"
 
@@ -882,12 +883,15 @@ int format(char **pbuf, int *pbufsize, c
 		case 'd': case 'i':
 			flag = 'd';
 			if(*(s-1) == 'l') break;
-			*(t-1) = 'l';
+			*(t-1) = 'j';
 			*t = 'd';
 			*++t = '\0';
 			break;
 		case 'o': case 'x': case 'X': case 'u':
 			flag = *(s-1) == 'l' ? 'd' : 'u';
+			*(t-1) = 'j';
+			*t = *s;
+			*++t = '\0';
 			break;
 		case 's':
 			flag = 's';
@@ -920,8 +924,8 @@ int format(char **pbuf, int *pbufsize, c
 			snprintf(p, BUFSZ(p), "%s", t);
 			break;
 		case 'f':	snprintf(p, BUFSZ(p), fmt, getfval(x)); break;
-		case 'd':	snprintf(p, BUFSZ(p), fmt, (long) getfval(x)); break;
-		case 'u':	snprintf(p, BUFSZ(p), fmt, (int) getfval(x)); break;
+		case 'd':	snprintf(p, BUFSZ(p), fmt, (intmax_t) getfval(x)); break;
+		case 'u':	snprintf(p, BUFSZ(p), fmt, (uintmax_t) getfval(x)); break;
 		case 's':
 			t = getsval(x);
 			n = strlen(t);



CVS commit: src/external/historical/nawk/dist

2011-01-20 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Thu Jan 20 21:23:11 UTC 2011

Modified Files:
src/external/historical/nawk/dist: lib.c

Log Message:
avoid crash if certain operations are done before an input record is
read, ie in a BEGIN rule


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/lib.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.3 src/external/historical/nawk/dist/lib.c:1.4
--- src/external/historical/nawk/dist/lib.c:1.3	Sun Nov  7 22:55:26 2010
+++ src/external/historical/nawk/dist/lib.c	Thu Jan 20 21:23:11 2011
@@ -328,7 +328,9 @@
 	}
 	fr = fields;
 	i = 0;	/* number of fields accumulated here */
-	if (inputFS[0] && inputFS[1]) {	/* it's a regular expression */
+	if (!inputFS) {
+		/* do nothing */
+	} else if (inputFS[0] && inputFS[1]) {	/* it's a regular expression */
 		i = refldbld(r, inputFS);
 	} else if ((sep = *inputFS) == ' ') {	/* default whitespace */
 		for (i = 0; ; ) {



CVS commit: src/external/historical/nawk/dist

2011-01-20 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Thu Jan 20 21:26:20 UTC 2011

Modified Files:
src/external/historical/nawk/dist: tran.c

Log Message:
fix bug introduced in rev. 1.3: need to set the string before
converting it into a numerical value, otherwise we might get junk or crash


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.3 src/external/historical/nawk/dist/tran.c:1.4
--- src/external/historical/nawk/dist/tran.c:1.3	Sun Nov  7 22:55:26 2010
+++ src/external/historical/nawk/dist/tran.c	Thu Jan 20 21:26:20 2011
@@ -353,6 +353,7 @@
 	   dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n", 
 		vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
 
+	vp->sval = t;
 	if (&vp->fval == NF) {
 		donerec = 0;	/* mark $0 invalid */
 		f = getfval(vp);
@@ -360,7 +361,7 @@
 		dprintf( ("setting NF to %g\n", f) );
 	}
 
-	return(vp->sval = t);
+	return(vp->sval);
 }
 
 Awkfloat getfval(Cell *vp)	/* get float val of a Cell */



CVS commit: src/external/historical/nawk/dist

2010-08-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Aug 26 14:53:18 UTC 2010

Update of /cvsroot/src/external/historical/nawk/dist
In directory ivanova.netbsd.org:/tmp/cvs-serv10406

Log Message:
imprort latest nawk

Status:

Vendor Tag: NAWK
Release Tags:   NAWK20100523

N src/external/historical/nawk/dist/awkgram.y
N src/external/historical/nawk/dist/README
N src/external/historical/nawk/dist/FIXES
N src/external/historical/nawk/dist/awk.h
N src/external/historical/nawk/dist/proto.h
N src/external/historical/nawk/dist/maketab.c
N src/external/historical/nawk/dist/lex.c
N src/external/historical/nawk/dist/b.c
N src/external/historical/nawk/dist/main.c
N src/external/historical/nawk/dist/proctab.c
N src/external/historical/nawk/dist/parse.c
N src/external/historical/nawk/dist/lib.c
N src/external/historical/nawk/dist/run.c
N src/external/historical/nawk/dist/tran.c
N src/external/historical/nawk/dist/makefile
N src/external/historical/nawk/dist/awk.1

No conflicts created by this import



CVS commit: src/external/historical/nawk/dist

2010-08-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Aug 27 16:49:48 UTC 2010

Modified Files:
src/external/historical/nawk/dist: proctab.c

Log Message:
fix botched merge.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/proctab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/proctab.c
diff -u src/external/historical/nawk/dist/proctab.c:1.2 src/external/historical/nawk/dist/proctab.c:1.3
--- src/external/historical/nawk/dist/proctab.c:1.2	Thu Aug 26 10:55:20 2010
+++ src/external/historical/nawk/dist/proctab.c	Fri Aug 27 12:49:47 2010
@@ -186,10 +186,10 @@
 	nullproc,	/* STRING */
 	nullproc,	/* REGEXPR */
 	awkgetline,	/* GETLINE */
-	substr,	/* SUBSTR */
-	split,	/* SPLIT */
 	gensub,	/* GENSUB */
 	jump,	/* RETURN */
+	split,	/* SPLIT */
+	substr,	/* SUBSTR */
 	whilestat,	/* WHILE */
 	cat,	/* CAT */
 	boolop,	/* NOT */



CVS commit: src/external/historical/nawk/dist

2010-10-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 17 22:12:23 UTC 2010

Modified Files:
src/external/historical/nawk/dist: main.c

Log Message:
PR/43981: Aleksey Cheusov: awk too small limit on number -f options
remove the limit
should we pullup to 5.x?


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/main.c
diff -u src/external/historical/nawk/dist/main.c:1.2 src/external/historical/nawk/dist/main.c:1.3
--- src/external/historical/nawk/dist/main.c:1.2	Thu Aug 26 10:55:20 2010
+++ src/external/historical/nawk/dist/main.c	Sun Oct 17 18:12:22 2010
@@ -51,9 +51,10 @@
 
 #define	MAX_PFILE	20	/* max number of -f's */
 
-char	*pfile[MAX_PFILE];	/* program filenames from -f's */
-int	npfile = 0;	/* number of filenames */
-int	curpfile = 0;	/* current filename */
+static char	**pfile = NULL;	/* program filenames from -f's */
+static size_t 	maxpfile = 0;	/* max program filenames */
+static size_t	npfile = 0;	/* number of filenames */
+static size_t	curpfile = 0;	/* current filename */
 
 int	safe	= 0;	/* 1 => "safe" mode */
 
@@ -146,8 +147,14 @@
 			argv++;
 			if (argc <= 1)
 FATAL("no program filename");
-			if (npfile >= MAX_PFILE - 1)
-FATAL("too many -f options"); 
+			if (npfile >= maxpfile) {
+maxpfile += 20;
+pfile = realloc(pfile,
+maxpfile * sizeof(*pfile));
+if (pfile == NULL)
+	FATAL("error allocating space for "
+	"-f options"); 
+			}
 			pfile[npfile++] = argv[1];
 			break;
 		case 'F':	/* set field separator */



CVS commit: src/external/historical/nawk/dist

2010-10-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 18 15:58:06 UTC 2010

Modified Files:
src/external/historical/nawk/dist: main.c

Log Message:
remove the unused MAX_PFILE define from Aleksey Cheusov.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/main.c
diff -u src/external/historical/nawk/dist/main.c:1.3 src/external/historical/nawk/dist/main.c:1.4
--- src/external/historical/nawk/dist/main.c:1.3	Sun Oct 17 18:12:22 2010
+++ src/external/historical/nawk/dist/main.c	Mon Oct 18 11:58:05 2010
@@ -49,8 +49,6 @@
 int	compile_time = 2;	/* for error printing: */
 /* 2 = cmdline, 1 = compile, 0 = running */
 
-#define	MAX_PFILE	20	/* max number of -f's */
-
 static char	**pfile = NULL;	/* program filenames from -f's */
 static size_t 	maxpfile = 0;	/* max program filenames */
 static size_t	npfile = 0;	/* number of filenames */



CVS commit: src/external/historical/nawk/dist

2010-11-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov  7 22:55:27 UTC 2010

Modified Files:
src/external/historical/nawk/dist: lib.c proto.h tran.c

Log Message:
PR/44063: Aleksey Cheusov: awk: setting NF doesn't change $i
http://www.opengroup.org/onlinepubs/009695399/utilities/awk.html

...
References to nonexistent fields (that is, fields after $NF),
shall evaluate to the uninitialized value.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/lib.c \
src/external/historical/nawk/dist/proto.h \
src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.2 src/external/historical/nawk/dist/lib.c:1.3
--- src/external/historical/nawk/dist/lib.c:1.2	Thu Aug 26 10:55:20 2010
+++ src/external/historical/nawk/dist/lib.c	Sun Nov  7 17:55:26 2010
@@ -400,6 +400,7 @@
 		}
 	}
 	setfval(nfloc, (Awkfloat) lastfld);
+	donerec = 1; /* restore */
 	if (dbg) {
 		for (j = 0; j <= lastfld; j++) {
 			p = fldtab[j];
@@ -431,6 +432,19 @@
 	setfval(nfloc, (Awkfloat) n);
 }
 
+void setlastfld(int n)	/* set lastfld cleaning fldtab cells if necessary */
+{
+	if (n > nfields)
+		growfldtab(n);
+
+	if (lastfld < n)
+	cleanfld(lastfld+1, n);
+	else
+	cleanfld(n+1, lastfld);
+
+	lastfld = n;
+}
+
 Cell *fieldadr(int n)	/* get nth field */
 {
 	if (n < 0)
Index: src/external/historical/nawk/dist/proto.h
diff -u src/external/historical/nawk/dist/proto.h:1.2 src/external/historical/nawk/dist/proto.h:1.3
--- src/external/historical/nawk/dist/proto.h:1.2	Thu Aug 26 10:55:20 2010
+++ src/external/historical/nawk/dist/proto.h	Sun Nov  7 17:55:26 2010
@@ -127,6 +127,7 @@
 extern	void	fldbld(void);
 extern	void	cleanfld(int, int);
 extern	void	newfld(int);
+extern	void	setlastfld(int);
 extern	int	refldbld(const char *, const char *);
 extern	void	recbld(void);
 extern	Cell	*fieldadr(int);
Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.2 src/external/historical/nawk/dist/tran.c:1.3
--- src/external/historical/nawk/dist/tran.c:1.2	Thu Aug 26 10:55:20 2010
+++ src/external/historical/nawk/dist/tran.c	Sun Nov  7 17:55:26 2010
@@ -298,6 +298,10 @@
 		if (fldno > *NF)
 			newfld(fldno);
 		   dprintf( ("setting field %d to %g\n", fldno, f) );
+	} else if (&vp->fval == NF) {
+		donerec = 0;	/* mark $0 invalid */
+		setlastfld(f);
+		dprintf( ("setting NF to %g\n", f) );
 	} else if (isrec(vp)) {
 		donefld = 0;	/* mark $1... invalid */
 		donerec = 1;
@@ -324,6 +328,7 @@
 {
 	char *t;
 	int fldno;
+	Awkfloat f;
 
 	   dprintf( ("starting setsval %p: %s = \"%s\", t=%o, r,f=%d,%d\n", 
 		vp, NN(vp->nval), s, vp->tval, donerec, donefld) );
@@ -347,6 +352,14 @@
 	vp->tval &= ~DONTFREE;
 	   dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n", 
 		vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
+
+	if (&vp->fval == NF) {
+		donerec = 0;	/* mark $0 invalid */
+		f = getfval(vp);
+		setlastfld(f);
+		dprintf( ("setting NF to %g\n", f) );
+	}
+
 	return(vp->sval = t);
 }