Macro Expansion: $ and $&
The
value of a macro can be used by putting a $
character in front of the macro’s name. For example,
consider the following definition:
DXtextHere, the macro named X is given
text as its value.
If you later prefix a macro name with a $
character, you can use that value. This is called
expanding a macro:
$X
Here, the expression $X tells
sendmail to use the value stored in
X (the text) rather
than its name (X).
For multicharacter names, the process is the same, but the name is surrounded with curly braces:
D{Xxx}text ← declare {Xxx} ${Xxx}← use {Xxx}
Macro Expansion Is Recursive
When
text contains other macros, those other
macros are also expanded. This process is recursive and continues
until all macros have been expanded. For example, consider the
following:
DAxxx DByyy DC$A.$B DD$C.zzz
Here, the text for the macro
D is $C.zzz. When the
D macro is defined, it is recursively expanded
like this:
$D → becomes → $C.zzz $C.zzz → becomes → $A.$B.zzz $A.$B.zzz → becomes → xxx.$B.zzz xxx.$B.zzz → becomes → xxx.yyy.zzz
Notice that when sendmail recursively expands a macro, it does so one macro at a time, always expanding the leftmost macro first.
In rules, when sendmail expands a macro, it also
tokenizes it. For example, placing the earlier $D
in the following rule’s LHS:
R$+ @ $D $1
causes the LHS to contain seven tokens rather than three:
R$+ @ xxx . yyy . zzz $1
Note that the largest a recursive expansion can grow is defined at compile time with the MACBUFSIZE compile-time ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access