[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
how 2 manage arrays & stack conflicts in m4?
From: |
OpenMacNews |
Subject: |
how 2 manage arrays & stack conflicts in m4? |
Date: |
Sat, 06 Aug 2005 18:17:42 -0700 |
hi all,
well, i'm slogging thru arrays (1D 1st, the multi-D ...) & stacks in m4.
my 1st, working example script:
==================================
changequote([,])dnl
dnl # Define Array
define([MY_HOST_ARRAY], [defn(format([[array[%d]]], [$1]))])dnl
define([SET_HOST_ARRAY], [define(format([[array[%d]]], [$1]), [$2])])dnl
define([MY_IP_ARRAY], [defn(format([[array[%d]]], [$1]))])dnl
define([SET_IP_ARRAY], [define(format([[array[%d]]], [$1]), [$2])])dnl
dnl # Define Loop
define([forHostLoop],
[pushdef([$1], [$2])_forHostLoop([$1], [$2], [$3], [$4])popdef([$1])])
define([_forHostLoop],
[$4[]ifelse($1, [$3], ,
[define([$1], incr($1))_forHostLoop([$1], [$2], [$3],
[$4])])])
dnl # Identify/Define the lookup NameServer
define([MY_DNS_NAME], [ns.domain.com])dnl
dnl # Identify/Define the Physical Hosts
SET_HOST_ARRAY(1, [machine1.domain.com])dnl
SET_HOST_ARRAY(2, [machine2.domain.com])dnl
dnl # Define IP address lookup
define([MY_IP_ADDR],
[esyscmd(dig @MY_DNS_NAME MY_HOST_ARRAY(1) | grep MY_HOST_ARRAY(1) | grep -v
DiG | grep -v ";"MY_HOST_ARRAY(1) | grep -v NS | awk '{printf("%s", $ 5)
}')])dnl
dnl # Define IP address lookup
define([MY_IP_ADDR2],
[esyscmd(dig @MY_DNS_NAME MY_HOST_ARRAY(2) | grep MY_HOST_ARRAY(2) | grep -v
DiG | grep -v ";"MY_HOST_ARRAY(2) | grep -v NS | awk '{printf("%s", $ 5)
}')])dnl
dnl # Define IP_ARRAY Elements
SET_IP_ARRAY(1, MY_IP_ADDR)dnl
SET_IP_ARRAY(2, MY_IP_ADDR2)dnl
dnl # Write Apache "LISTENs" for these IPs
forHostLoop([i], 1, 2, [Listen MY_IP_ARRAY(i):80 ]
)dnl
dnl # Write Apache "LISTENs" for these HOSTS
forHostLoop([i], 1, 2, [Listen MY_HOST_ARRAY(i):80 ]
)dnl
==================================
i'd expected SHOULD provide two sets of outputs:
Listen 10.0.0.6:80
Listen 10.0.0.7:80
Listen machine1.domain.com:80
Listen machine2.domain.com:80
however, what it DOES, rather, output is:
Listen 10.0.0.6:80
Listen 10.0.0.7:80
Listen 10.0.0.6:80
Listen 10.0.0.7:80
the 1st part IS CORRECT; the 2nd is not -- which i assume is due to the
forHostLoop define push/pop-ing the *same* stack.
am i correct in this? if so, to circumvent, should i change either of the
ARRAY defs, or, rather, add a second/different Loop definition?
cheers,
richard
- how 2 manage arrays & stack conflicts in m4?,
OpenMacNews <=