autoconf-patches
[Top][All Lists]
Advanced

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

Re: config files substitution with awk


From: Ralf Wildenhues
Subject: Re: config files substitution with awk
Date: Tue, 21 Nov 2006 10:13:05 +0100
User-agent: Mutt/1.5.13 (2006-11-01)

Hello Paolo,

* Paolo Bonzini wrote on Tue, Nov 21, 2006 at 09:49:56AM CET:
> 
> >+/@[a-zA-Z_][a-zA-Z_0-9]*@/ {
> >+  nfields = split($ 0, field, "@")
> >+  for (i = 1; i <= nfields; i++) {
> > +    key = field[i]
> 
> The space after $ is useless.

It helps to keep m4 from expanding $0, without needing to think about
level of m4 quotation currently in place.  AFAIK it's portable.

> Furthermore, this is wrong in cases like 
> address@hidden@address@hidden@.

No, it isn't.  It's merely suboptimal in that a sub may be invoked which
does not match anything.  It is possible to iterate only from 2 to less
than nfields though, as another optimization.

Note that the sub replaces the key including the surrounding @, and that
all @ that come in from the replacement are followed by |#_!!_#| so they
are not mistakenly used for substitution again.

I am still pondering abandoning sub completely though, and using substr
and length to do the replacement manually, due to the \& escaping
issues.

Also I wonder how to get around this limitation (autoconf.texi):
|      Traditional Awk `split' supports only two arguments.

Is seems not portable to set FS before each split and reset it
afterwards, to not fall into the 99 field limit when scanning the next
record, unless split allows three arguments:

$ perl -e 'print "address@hidden@" . "x"x199 . "\n"' |
  awk 'BEGIN{FS="@"} {print $ 2; FS="x"; split($ 0, f); print f[2]; FS="@"}'
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
awk: Line address@hidden cannot have more than 199 fields.
 The input line number is 1.
 The source line number is 1.

$ perl -e 'print "address@hidden@" . "x"x199 . "\n"' |
  awk 'BEGIN{FS="@"} {print $ 2; split($ 0, f, "x"); print f[2]}'
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@
$ config.guess
hppa2.0-hp-hpux10.20

Cheers,
Ralf




reply via email to

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