Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[zsh-2.6-b18] signames.awk and the backslash treatment bug



I wrote the author of mawk, Michael Brennan, concerning the behavior
of mawk w.r.t. the backslashes introduced into the signames.awk script
in beta18. Appended is his take on the matter.

This is probably more than anyone ever wanted to know, but in case you
are curious...

------- start of forwarded message (RFC 934 encapsulation) -------
Content-Type: text
content-length: 891
From: brennan@xxxxxxx (Michael Brennan)
Subject: Re: [mawk-1.2.2] backslash treatment
Date: Wed, 22 May 1996 12:36:00 -0700 (PDT)
To: mdb@xxxxxxxxxxxx (Mark Borges)

> 
> Is this a bug in mawk?
> 
> Apparently the use of a `\' preceding a character that need not be
> escaped in a print statement is ambiguous. Some awks remove it, others
> (like mawk) leave it verbatim.
> 

The posix answer is "\z" has undefined meaning which implies that it is
not portable to use it.  The posix standard says it is explicitly
undefined.   Note that the same thing is true for ansi C.  See K&R
(ansi version) page 193.

I discuss this issue in the portability section of the mawk man pages
(near the back).

[man page excerpt]

     With mawk, the following are all equivalent,
          x ~ /a\+b/    x ~ "a\+b"     x ~ "a\\+b"
     The strings get scanned twice, once as string  and  once  as
     regular  expression.   On  the string scan, mawk ignores the
     escape on non-escape characters while the AWK book advocates
     \c be recognized as c which necessitates the double escaping
     of meta-characters in strings. Posix explicitly declines  to
     define  the  behavior  which  passively forces programs that
     must run under a variety of awks to use  the  more  portable
     but less readable, double escape.

[end man page excerpt]
 
In mawk, I wanted 

	 x ~ /c\+/
	 x ~ "c\+"

to work the same.  Note with nawk or gawk, you need to

	 x ~ "c\\+"

to escape + once for the string scan and once for the regexp scan.
With mawk
	 x ~ "c\\+"

works correctly too.

- --
Mike
brennan@xxxxxxx

------- end -------




Messages sorted by: Reverse Date, Date, Thread, Author