Subject: Re: bin/29659: awk handling of END non-portable
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Havard Eidnes <he@netbsd.org>
List: netbsd-bugs
Date: 03/13/2005 12:05:03
The following reply was made to PR bin/29659; it has been noted by GNATS.

From: Havard Eidnes <he@netbsd.org>
To: gnats-admin@netbsd.org
Cc: netbsd-bugs@netbsd.org
Subject: Re: bin/29659: awk handling of END non-portable
Date: Fri, 11 Mar 2005 17:11:12 +0100 (CET)

 Here is a candidate patch, not much tested up and above that it
 does work with the given test case.
 
 - Havard
 
 Index: lib.c
 ===================================================================
 RCS file: /cvsroot/src/dist/nawk/lib.c,v
 retrieving revision 1.5
 diff -u -r1.5 lib.c
 --- lib.c	26 Oct 2003 11:34:23 -0000	1.5
 +++ lib.c	11 Mar 2005 16:09:24 -0000
 @@ -106,7 +106,8 @@
  	int c;
  	static int firsttime = 1;
  	uschar *buf = *pbuf;
 -	int bufsize = *pbufsize;
 +	uschar save;
 +	int bufsize = *pbufsize, savebufsize = *pbufsize;
  
  	if (firsttime) {
  		firsttime = 0;
 @@ -118,6 +119,7 @@
  		donefld = 0;
  		donerec = 1;
  	}
 +	save = buf[0];
  	buf[0] = 0;
  	while (argno < *ARGC || infile == stdin) {
  		   dprintf( ("argno=%d, file=|%s|\n", argno, file) );
 @@ -164,8 +166,9 @@
  		infile = NULL;
  		argno++;
  	}
 +	buf[0] = save;
  	*pbuf = buf;
 -	*pbufsize = bufsize;
 +	*pbufsize = savebufsize;
  	return 0;	/* true end of file */
  }