bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: config files substitution with awk


From: Pascal Bourguignon
Subject: Re: config files substitution with awk
Date: Tue, 05 Dec 2006 07:30:15 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux)

Ralf Wildenhues <address@hidden> writes:

> * Karl Berry wrote on Tue, Dec 05, 2006 at 12:14:28AM CET:
>> 
>> But for purposes of explaining to rms, can someone tell me (as briefly
>> as possible :) why it is desirable to switch to awk instead of sticking
>> with sed?
>> 
>> (I can imagine some reasons, but best to ask, I figure.)
>
> The primary reason for introducing it to Autoconf was, that it allows a
> faster substitution of variables.  Roughly speaking, a sed script like
>    s/@var1@/text1/g
>    s/@var2@/text2/g
>    ...
>
> used on an input file of the form
>   address@hidden@
>   address@hidden@
>   ...
>
> has an overhead scaling quadratically in the number of variables.

This is not necessarily the case.  It depends on the sed implementation.
There's nothing preventing sed to build collapsed DFAs.

And I don't see how awk can do any better, if it doesn't collapse the
DFAs itself.


Note that it must be done carefully, since we could have:

s/@var1@/@var2@/g
s/@var2@/text2/g

and @var1@ in the input would sustitute to text2.

So we must still have as many DFAs as s commands, but with some luck,
we can skip directly to the right action. (For this reason, I'd
suggest to use a more specific tool rather than sed which is too
general for this job).

Given the regexps r1, r2, ... rn in the n 's' commands, we can build
the first DFA as:

  r1|r2|r3|....|rn

with n different exit states, corresponding to each regexp, and
activating the substitution of the nth text, followed by the skipping
to the nth DFA.

The second DFA would be:  r2|r3|...|rn

Then nth DFA would be:    rn



Of course we really need only the first r1|r2|r3|...|rn DFA, that's
why it would be better to have a specific tool, and processing would
be O(length(file)).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This universe shipped by weight, not volume.  Some expansion may have
occurred during shipment.




reply via email to

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