run.c.diff   [plain text]


--- run.c.orig	2008-11-12 11:42:56.000000000 -0800
+++ run.c	2008-11-12 11:43:08.000000000 -0800
@@ -90,6 +90,8 @@
 
 Node	*curnode = NULL;	/* the node being executed, for debugging */
 
+static Awkfloat prev_srand, tmp_srand;
+
 /* buffer memory management */
 int adjbuf(char **pbuf, int *psiz, int minlen, int quantum, char **pbptr,
 	const char *whatrtn)
@@ -196,6 +198,7 @@
 	if (setjmp(env) != 0)	/* handles exit within END */
 		goto ex1;
 	if (a[2]) {		/* END */
+		donefld = 1;	/* avoid updating NF */
 		x = execute(a[2]);
 		if (isbreak(x) || isnext(x) || iscont(x))
 			FATAL("illegal break, continue, next or nextfile from END");
@@ -902,7 +905,7 @@
 			break;
 		case 'f':	sprintf(p, fmt, getfval(x)); break;
 		case 'd':	sprintf(p, fmt, (long) getfval(x)); break;
-		case 'u':	sprintf(p, fmt, (int) getfval(x)); break;
+		case 'u':	sprintf(p, fmt, (unsigned int) getfval(x)); break;
 		case 's':
 			t = getsval(x);
 			n = strlen(t);
@@ -1520,6 +1523,9 @@
 		else
 			u = getfval(x);
 		srand((unsigned int) u);
+		tmp_srand = u;
+		u = prev_srand;		/* return the previous value	*/
+		prev_srand = tmp_srand;	/* remember for next time	*/
 		break;
 	case FTOUPPER:
 	case FTOLOWER: