m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

awk portability (was: use execute module in m4)


From: Eric Blake
Subject: awk portability (was: use execute module in m4)
Date: Thu, 12 Mar 2009 22:03:48 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Gary V. Vaughan <gary <at> gnu.org> writes:

Hi Gary,

> After that very long preamble (so that you can check my bootstrap
> sanity!), you'll
> be pleased to hear that AIX now passes all tests in all releases I
> have access to.

Yeah!  I'll be pushing that patch series soon, once I finish porting it to the 
master branch.  I'll probably roll another snapshot for one final round of 
sanity checks, although I think we're pretty solid right now.

> 
> I am, however, encountering this error now on HPUX and Tru64:
> 
> make[2]: Entering directory `/opt/build/m4-1.4.12.34-060b5/checks'
> rm -f ./*[0-9][0-9][0-9].*
> cd . && AWK=nawk ./get-them ../doc/m4.texinfo
> awk: There is a regular expression error.
>         \{ \} imbalence
>  The source line number is 99.
>  The error context is
>                   gsub("@{", "{", >>>  $0) <<< ;

Oops.  POSIX says the use of unbalanced { in ERE is unspecified.  GNU awk 
treats it as a literal, but other awk rightfully complain.  Too bad gawk 
doesn't have a --posix option, like sed, to make it easier to detect these non-
portable ERE.

> 
> ...which is easy enough to work around by installing gnu awk, and using
> './configure AWK=gawk' for m4, although that wasn't necessary on the last
> rounds of testing, and I don't believe I have ever had gawk in my path at
> configure time (except on linux where it is installed by default) :-?

I'm not sure how you did bootstrap in the past on HPUX, but the branch has 
never really been scrubbed to be portable to POSIX awk.  According to POSIX 
(and as tested on both gawk and Solaris nawk), the portable way to write an ERE 
matching a single { is any of: "\\{", /\{/, "[{]", or /[{]/.  The master branch 
(where the file checks/get-them was renamed tests/generate.awk) uses a mix of 
the foregoing styles, dating prior to 2001, as well as some later non-portable 
uses reintroduced by me.  On the other hand, POSIX states that } in isolation 
is not a special character, and therefore that \} produces undefined behavior.  
So although I don't have access to HPUX awk, I'm hoping this fixes your 
portability issue.  Solaris /usr/bin/awk is too ancient (it doesn't even 
support gsub), but hopefully configure filters that one out (since 
config.status also needs a relatively posix-y awk).


From: Eric Blake <address@hidden>
Date: Thu, 12 Mar 2009 15:36:39 -0600
Subject: [PATCH] Fix awk script portability.

* checks/get-them: In gsub, properly escape { and }.
Reported by Gary V. Vaughan.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog       |    6 ++++++
 checks/get-them |   13 +++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 01b69db..4f6563c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-03-12  Eric Blake  <address@hidden>
+
+       Fix awk script portability.
+       * checks/get-them: In gsub, properly escape {.
+       Reported by Gary V. Vaughan.
+
 2009-03-05  Eric Blake  <address@hidden>

        Allow configuration choice in syscmd shell.
diff --git a/checks/get-them b/checks/get-them
index 6e571f0..8caf9f6 100755
--- a/checks/get-them
+++ b/checks/get-them
@@ -1,8 +1,8 @@
 #!/bin/sh
 # -*- AWK -*-
 # Extract all examples from the manual source.
-# Copyright (C) 1992, 2005, 2006, 2007, 2008 Free Software Foundation,
-# Inc.
+# Copyright (C) 1992, 2005, 2006, 2007, 2008, 2009 Free Software
+# Foundation, Inc.
 #
 # This file is part of GNU M4.
 #
@@ -19,7 +19,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

-# This script is for use with GNU awk.
+# This script was designed under GNU awk, but hopefully portable to
+# other implementations.

 FILE=${1-/dev/null}
 : ${AWK=awk}
@@ -122,10 +123,10 @@ BEGIN {
   else
     prefix = "";
   gsub("@@", "@", $0);
-  gsub("@{", "{", $0);
+  gsub("@[{]", "{", $0);
   gsub("@}", "}", $0);
-  gsub("@w{ }", " ", $0);
-  gsub("@tabchar{}", "\t", $0);
+  gsub("@w[{] }", " ", $0);
+  gsub("@tabchar[{]}", "\t", $0);
   printf("%s%s\n", prefix, $0) >> file;
 }

-- 
1.6.1.2








reply via email to

[Prev in Thread] Current Thread [Next in Thread]