4.2 awk difference

Guy Harris guy at rlgvax.UUCP
Sat Jun 9 18:07:29 AEST 1984


> DESCRIPTION:
> 	4.2 awk fails to modify $0 when one of $1, $2, ... is modified.  The awk
> distributed with 4.1 handles the case below as documented.

> POSSIBLE SOLUTION:
> 	The action of 'print $0' can be performed by 'for (i=1;i<=NF;i++)
> printf "%s " $i;'.  Thus one still has the full capability of the old awk.
> Since the documentation is slightly unclear about $0 when changed as a
> side-effect it might be better to just delete this feature from awk.  In other
> words simply change the documentation.

If I remember correctly, this was not a feature, but a bug.  It was introduced
when "awk" was changed not to try dereferencing NULL pointers.  Bill Shannon
posted a fix; here's the changes to "awk.def" and "tran.c":

*** /tmp/,RCSt1018196	Sat Jun  9 04:03:41 1984
--- awk.def	Tue May 22 21:07:58 1984
***************
*** 5,10
  #define	xfree(a)	{ if(a!=NULL) { yfree(a); a=NULL;} }
  #define	strfree(a)	{ if(a!=NULL && a!=EMPTY) { yfree(a);} a=EMPTY; }
  #define yfree free
  #ifdef	DEBUG
  #	define	dprintf	if(dbg)printf
  #else

--- 5,11 -----
  #define	xfree(a)	{ if(a!=NULL) { yfree(a); a=NULL;} }
  #define	strfree(a)	{ if(a!=NULL && a!=EMPTY) { yfree(a);} a=EMPTY; }
  #define yfree free
+ #define isnull(x)	((x) == EMPTY || (x) == NULL)
  #ifdef	DEBUG
  #	define	dprintf	if(dbg)printf
  #else

*** /tmp/,RCSt1018201	Sat Jun  9 04:03:54 1984
--- tran.c	Tue May 22 21:11:06 1984
***************
*** 136,142
  		error(FATAL, "can't set $0");
  	vp->tval &= ~STR;	/* mark string invalid */
  	vp->tval |= NUM;	/* mark number ok */
! 	if ((vp->tval & FLD) && vp->nval == 0)
  		donerec = 0;
  	return(vp->fval = f);
  }

--- 136,142 -----
  		error(FATAL, "can't set $0");
  	vp->tval &= ~STR;	/* mark string invalid */
  	vp->tval |= NUM;	/* mark number ok */
! 	if ((vp->tval & FLD) && isnull(vp->nval))
  		donerec = 0;
  	return(vp->fval = f);
  }
***************
*** 151,157
  		error(FATAL, "can't set $0");
  	vp->tval &= ~NUM;
  	vp->tval |= STR;
! 	if ((vp->tval & FLD) && vp->nval == 0)
  		donerec = 0;
  	if (!(vp->tval&FLD))
  		strfree(vp->sval);

--- 151,157 -----
  		error(FATAL, "can't set $0");
  	vp->tval &= ~NUM;
  	vp->tval |= STR;
! 	if ((vp->tval & FLD) && isnull(vp->nval))
  		donerec = 0;
  	if (!(vp->tval&FLD))
  		strfree(vp->sval);

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.bugs.4bsd.ucb-fixes mailing list