Re: m4 recursive macro help
From: Erik Max Francis (max_at_alcyone.com)
Date: 09/10/03
- Previous message: Jason Sinnamon: "m4 recursive macro help"
- In reply to: Jason Sinnamon: "m4 recursive macro help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 10 Sep 2003 14:41:42 -0700
Jason Sinnamon wrote:
> I need to search a list of values such that I can do something like
> this:
>
> define(`match', `index(:word1:word2:, :$1:)')
>
> define(`rmatch', ?????)
>
> rmatch(word1, word2, word3,
>
> line1
> line2
>
> )
>
> The lines should be printed if one of the words matches a word in the
> colon-separated list. The macro for matching a single word from the
> list
> works, I am just really stuck on the recursive match macro.
So do the following (pseudocode):
1. if there is only one argument in the list (the lines to print), then
exit
2. search for the first word in the table
3. if it is present, print the last argument in the list and exit
4. if it is not present, call recursively with the first argument
removed
The only tricky part here is printing the last argument to a macro,
since there is no builtin way to do this in m4 (that I'm aware of), and
if there are more than 9 arguments to the list it can get ugly. So,
write a support macro which recurses through its argument list to find
the last argument:
1. if the number of arguments is 1, print it and exit
2. if it is not 1, then call recursively with the first argument removed
-- Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I want to know God's thought; the rest are details. \__/ Albert Einstein
- Previous message: Jason Sinnamon: "m4 recursive macro help"
- In reply to: Jason Sinnamon: "m4 recursive macro help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|