CVS commit: src/dist/nawk

2009-06-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jun 20 23:23:12 UTC 2009

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

Log Message:
PR/30294: John Darrow: nawk doesn't handle RS as a RE but as a single character


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/dist/nawk/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/dist/nawk/lib.c
diff -u src/dist/nawk/lib.c:1.16 src/dist/nawk/lib.c:1.17
--- src/dist/nawk/lib.c:1.16	Thu Mar 12 09:04:01 2009
+++ src/dist/nawk/lib.c	Sat Jun 20 19:23:12 2009
@@ -210,22 +210,62 @@
 			;
 		if (c != EOF)
 			ungetc(c, inf);
-	}
-	for (rr = buf; ; ) {
-		for (; (c=getc(inf)) != sep && c != EOF; ) {
-			if (rr-buf+1 > bufsize)
-if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 1"))
-	FATAL("input record `%.30s...' too long", buf);
+	} else if ((*RS)[1]) {
+		fa *pfa = makedfa(*RS, 1);
+		int tempstat = pfa->initstat;
+		char *brr = buf;
+		char *rrr = NULL;
+		int x;
+		for (rr = buf; ; ) {
+			while ((c = getc(inf)) != EOF) {
+if (rr-buf+3 > bufsize)
+	if (!adjbuf(&buf, &bufsize, 3+rr-buf,
+	recsize, &rr, "readrec 2"))
+		FATAL("input record `%.30s...'"
+		" too long", buf);
+*rr++ = c;
+*rr = '\0';
+if (!(x = nematch(pfa, brr))) {
+	pfa->initstat = tempstat;
+	if (rrr) {
+		rr = rrr;
+		ungetc(c, inf);
+		break;
+	}
+} else {
+	pfa->initstat = 2;
+	brr = rrr = rr = patbeg;
+}
+			}
+			if (rrr || c == EOF)
+break;
+			if ((c = getc(inf)) == '\n' || c == EOF)
+/* 2 in a row */
+break;
+			*rr++ = '\n';
+			*rr++ = c;
+		}
+	} else {
+		for (rr = buf; ; ) {
+			for (; (c=getc(inf)) != sep && c != EOF; ) {
+if (rr-buf+1 > bufsize)
+	if (!adjbuf(&buf, &bufsize, 1+rr-buf,
+	recsize, &rr, "readrec 1"))
+		FATAL("input record `%.30s...'"
+		" too long", buf);
+*rr++ = c;
+			}
+			if (**RS == sep || c == EOF)
+break;
+			if ((c = getc(inf)) == '\n' || c == EOF)
+/* 2 in a row */
+break;
+			if (!adjbuf(&buf, &bufsize, 2+rr-buf, recsize, &rr,
+			"readrec 2"))
+FATAL("input record `%.30s...' too long", buf);
+			*rr++ = '\n';
 			*rr++ = c;
 		}
-		if (**RS == sep || c == EOF)
-			break;
-		if ((c = getc(inf)) == '\n' || c == EOF) /* 2 in a row */
-			break;
-		if (!adjbuf(&buf, &bufsize, 2+rr-buf, recsize, &rr, "readrec 2"))
-			FATAL("input record `%.30s...' too long", buf);
-		*rr++ = '\n';
-		*rr++ = c;
 	}
 	if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3"))
 		FATAL("input record `%.30s...' too long", buf);



CVS commit: src/dist/nawk

2009-06-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 21 20:08:44 UTC 2009

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

Log Message:
PR/40689: Nicolas Joly: awk(1) trashes memory with RE and ^ anchor
Another place to special-case HAT.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/dist/nawk/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/dist/nawk/b.c
diff -u src/dist/nawk/b.c:1.17 src/dist/nawk/b.c:1.18
--- src/dist/nawk/b.c:1.17	Tue Nov 25 13:40:26 2008
+++ src/dist/nawk/b.c	Sun Jun 21 16:08:44 2009
@@ -946,7 +946,8 @@
 		overflo("out of space in cgoto");
 
 	f->posns[f->curstat] = p;
-	f->gototab[s][c] = f->curstat;
+	if (c != HAT)
+		f->gototab[s][c] = f->curstat;
 	for (i = 0; i <= setcnt; i++)
 		p[i] = tmpset[i];
 	if (setvec[f->accept])



CVS commit: src/dist/nawk

2009-11-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov 15 21:56:06 UTC 2009

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

Log Message:
PR/42320: Alexander Nasonov: According to:
http://www.opengroup.org/onlinepubs/7990989775/xcu/awk.html
the LC_NUMERIC decimal point recognized is always period. Make it so.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/dist/nawk/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/dist/nawk/main.c
diff -u src/dist/nawk/main.c:1.9 src/dist/nawk/main.c:1.10
--- src/dist/nawk/main.c:1.9	Sun Mar  1 18:30:52 2009
+++ src/dist/nawk/main.c	Sun Nov 15 16:56:06 2009
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "awk.h"
 #include "awkgram.h"
 
@@ -102,6 +101,7 @@
 int main(int argc, char *argv[])
 {
 	const char *fs = NULL;
+	struct lconv *lconv;
 
 	setlocale(LC_CTYPE, "");
 	setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
@@ -114,6 +114,9 @@
 	}
 
 	(void) setlocale(LC_ALL, "");
+	lconv = localeconv();
+	lconv->decimal_point = ".";
+
 
 #ifdef SA_SIGINFO
 	{



CVS commit: src/dist/nawk

2009-06-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 14 21:05:40 UTC 2009

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

Log Message:
purge/flush 0,1,2 since we did not open them, we should not be closing them.
s/EOF/-1/ as the documentation for fclose/pclose states.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/dist/nawk/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/dist/nawk/run.c
diff -u src/dist/nawk/run.c:1.25 src/dist/nawk/run.c:1.26
--- src/dist/nawk/run.c:1.25	Sun Oct 19 15:33:47 2008
+++ src/dist/nawk/run.c	Sun Jun 14 17:05:40 2009
@@ -1616,7 +1616,7 @@
 			flush_all();	/* fflush() or fflush("") -> all */
 			u = 0;
 		} else if ((fp = openfile(FFLUSH, getsval(x))) == NULL)
-			u = EOF;
+			u = -1;
 		else
 			u = fflush(fp);
 		break;
@@ -1821,7 +1821,7 @@
 stat = pclose(files[i].fp);
 			else
 stat = fclose(files[i].fp);
-			if (stat == EOF)
+			if (stat == -1)
 WARNING( "i/o error occurred closing %s", files[i].fname );
 			if (i > 2)	/* don't do /dev/std... */
 xfree(files[i].fname);
@@ -1844,11 +1844,15 @@
 		if (files[i].fp) {
 			if (ferror(files[i].fp))
 WARNING( "i/o error occurred on %s", files[i].fname );
-			if (files[i].mode == '|' || files[i].mode == LE)
+			if (i == 0)
+stat = fpurge(files[i].fp);
+			else if (i < 2)
+stat = fflush(files[i].fp);
+			else if (files[i].mode == '|' || files[i].mode == LE)
 stat = pclose(files[i].fp);
 			else
 stat = fclose(files[i].fp);
-			if (stat == EOF)
+			if (stat == -1)
 WARNING( "i/o error occurred while closing %s", files[i].fname );
 		}
 	}



CVS commit: src/dist/nawk

2009-06-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jun 15 20:09:36 UTC 2009

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

Log Message:
<= 2, from jukka salmi


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/dist/nawk/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/dist/nawk/run.c
diff -u src/dist/nawk/run.c:1.26 src/dist/nawk/run.c:1.27
--- src/dist/nawk/run.c:1.26	Sun Jun 14 17:05:40 2009
+++ src/dist/nawk/run.c	Mon Jun 15 16:09:36 2009
@@ -1846,7 +1846,7 @@
 WARNING( "i/o error occurred on %s", files[i].fname );
 			if (i == 0)
 stat = fpurge(files[i].fp);
-			else if (i < 2)
+			else if (i <= 2)
 stat = fflush(files[i].fp);
 			else if (files[i].mode == '|' || files[i].mode == LE)
 stat = pclose(files[i].fp);



CVS commit: src/dist/nawk

2009-06-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jun 16 13:56:10 UTC 2009

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

Log Message:
fix EOF/-1 portability.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/dist/nawk/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/dist/nawk/run.c
diff -u src/dist/nawk/run.c:1.27 src/dist/nawk/run.c:1.28
--- src/dist/nawk/run.c:1.27	Mon Jun 15 16:09:36 2009
+++ src/dist/nawk/run.c	Tue Jun 16 09:56:09 2009
@@ -1818,11 +1818,14 @@
 			if (ferror(files[i].fp))
 WARNING( "i/o error occurred on %s", files[i].fname );
 			if (files[i].mode == '|' || files[i].mode == LE)
-stat = pclose(files[i].fp);
+stat = pclose(files[i].fp) == -1;
 			else
-stat = fclose(files[i].fp);
-			if (stat == -1)
-WARNING( "i/o error occurred closing %s", files[i].fname );
+stat = fclose(files[i].fp) == EOF;
+			if (stat) {
+stat = -1;
+WARNING( "i/o error occurred closing %s",
+files[i].fname );
+			}
 			if (i > 2)	/* don't do /dev/std... */
 xfree(files[i].fname);
 			files[i].fname = NULL;	/* watch out for ref thru this */
@@ -1845,14 +1848,14 @@
 			if (ferror(files[i].fp))
 WARNING( "i/o error occurred on %s", files[i].fname );
 			if (i == 0)
-stat = fpurge(files[i].fp);
+stat = fpurge(files[i].fp) == EOF;
 			else if (i <= 2)
-stat = fflush(files[i].fp);
+stat = fflush(files[i].fp) == EOF;
 			else if (files[i].mode == '|' || files[i].mode == LE)
-stat = pclose(files[i].fp);
+stat = pclose(files[i].fp) == -1;
 			else
-stat = fclose(files[i].fp);
-			if (stat == -1)
+stat = fclose(files[i].fp) == EOF;
+			if (stat)
 WARNING( "i/o error occurred while closing %s", files[i].fname );
 		}
 	}



CVS commit: src/dist/nawk

2009-11-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov 21 17:57:09 UTC 2009

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

Log Message:
Better fix for PR/42320 by Takehiko NOZAKI.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/dist/nawk/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/dist/nawk/main.c
diff -u src/dist/nawk/main.c:1.10 src/dist/nawk/main.c:1.11
--- src/dist/nawk/main.c:1.10	Sun Nov 15 16:56:06 2009
+++ src/dist/nawk/main.c	Sat Nov 21 12:57:09 2009
@@ -101,9 +101,8 @@
 int main(int argc, char *argv[])
 {
 	const char *fs = NULL;
-	struct lconv *lconv;
 
-	setlocale(LC_CTYPE, "");
+	setlocale(LC_ALL, "");
 	setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
 	cmdname = argv[0];
 	if (argc == 1) {
@@ -113,11 +112,6 @@
 		exit(1);
 	}
 
-	(void) setlocale(LC_ALL, "");
-	lconv = localeconv();
-	lconv->decimal_point = ".";
-
-
 #ifdef SA_SIGINFO
 	{
 		struct sigaction sa;