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: Paolo Bonzini
Subject: Re: config files substitution with awk
Date: Tue, 21 Nov 2006 09:49:56 +0100
User-agent: Thunderbird 1.5.0.8 (Macintosh/20061025)


+/@[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. Furthermore, this is wrong in cases like address@hidden@address@hidden@.

Rather, you need

  nfields = split($0, field, "@")
  for (i = 3; i <= nfields; ) {
    key = field[i-1]
    if (key ~ /[^a-zA-Z_0-9]/)
      i++;
    else
      i += 2;
    if (key in S)
      sub("@" key "@", S[key])
    else if (key in F) {
      while ((getline aline < F[key]) > 0)
         print(aline)
      close(F[key])
      next
    }

A smaller script to show the idea is this:

awk '{
  nfields = split ($0, field, "@");
  for (i = 3; i <= nfields; ) {
    key = field[i-1];
    if (key ~ /[^a-zA-Z_0-9]/) i++; else { print ">> " key;i+=2; }
  }
}'

with testcases such as

address@hidden@address@hidden
>> bar
address@hidden@@address@hidden
>> bar
>> cde
address@hidden@@address@hidden@
>> bar
>> cde
address@hidden @address@hidden
>> cde
address@hidden @address@hidden@
>> cde
address@hidden @cde@@ghi@
>> cde
>> ghi

Paolo




reply via email to

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