On Wednesday 02 May 2007 12:39, Philip Hazel wrote:
> Suppose you define 100 macros. Then for each input line that Exim reads,
> it obeys
>
> for (i = 0; i < 100; i++)
> Search the line for occurrences of macro number i
That looks inefficient, but perhaps necessary due to the partly silly way
macro expansion works. IIUC, if I have
FOO=ZON
GAZONK=fnord
then GAFOOK will be expanded into GAZONK, which will in turn be expanded into
fnord. Does anybody depend on this?
If the RHS of a macro definition B contains a previously defined macro A,
macro A will be expanded before B is defined (like a simply expanded makefile
variable), whereas if A (still the first macro) contains B (the second
macro), then B isn't expanded until A is used further down (like a
recursively expanded makefile variable). Correct? Do we need both? (Well,
both cases are very likely in use around the world.)
The reason that a macro name cannot contain the name of a previously defined
macro as a prefix isn't to prevent infinite loops - the fact that a
replacement text isn't scanned for the same or previous macros again prevents
that. The reason, IIUC, is simply that the second macro would never be used
since the first macro would always match first. On the other hand, expansion
of the first macro could cause the second macro name to appear on the line
and to be expanded, wouldn't it?
Would could use a Patricia trie if the rules were a bit different:
* scan from left to right, replacing the longest possible match
* only rescan the replacement for new macros
* macros have to be prevented from including themselves in the replacement
The trie would need at most 63*sizeof(size_t) bytes of extra space per macro
defined above one (if we want branching in the trie in O(1) time), and take
essentially O(L) time overall (where L is the length of a particular line)
instead of O(L*M) (where M is the number of macros defined).
I don't think there would be any practical differences except in rather
complex configurations. Still, probably something for Exim 5.
--
Magnus Holmgren holmgren@???
(No Cc of list mail needed, thanks)
"Exim is better at being younger, whereas sendmail is better for
Scrabble (50 point bonus for clearing your rack)" -- Dave Evans