public string ReplaceParms(MacroEntry me, string[] actual_parms)
{
Match m;
int istart = 0;
string subst = me.Subst;
while ((m = iden.Match(subst, istart)).Success)
{
int idx = Array.IndexOf(me.Parms, m.Value);
int len = m.Length;
if (idx != -1)
{
string actual = actual_parms[idx];
// A _single_ # before a token means the 'stringizing' operator
if (m.Index > 0 && subst[m.Index - 1] == '#')
{
// whereas ## means 'token-pasting'! #s will be removed later!
if (!(m.Index > 1 && subst[m.Index - 2] == '#'))
actual = '\"' + actual + '\"';
}
subst = iden.Replace(subst, actual, 1, istart);
len = actual.Length;
}
istart = m.Index + len;
}
subst = subst.Replace("#", "");
return subst;
}