Results 1 to 1 of 1
Enjoy an ad free experience by logging in. Not a member yet? Register.
- Join Date
- Jan 2005
Has anyone used the m4 preprocessor ?
There are a couple of awk programmes I want to write and I was thinking it
would be nice to have named constants as you do in C. I mean things like
#define MAX_FIELD_WIDTH 100
to be expanded inside quoted strings and inside regular expressions.So for
example if my programme has somewhere
if ( $0 ~ /MAX_FIELD_WIDTH/ )
On the other hand if I have somewhere
if ( a < MAX_FIELD_WIDTH )
if ( a < 100 )
Defining macros is straightforward but as I've said my problem is how to
prevent them from expanding at the wrong place.So far the only way I can
see to achieve this is to put the critical portions of the code inside m4
quotes ie write
if ( $0 ~ ` /MAX_FIELD_WIDTH/ ' ) print ` "MAX_FIELD_WIDTH" '
would have to think not only in terms of awk but also in terms of m4.While
what I have in mind is to put in the beginning some m4 directives and
from then on just write the programme as any other awk programme
apart from using the macros.
The other solution is to use macro names which I won't use inside regular
expressions or quotes.Once again I find this inelegant.It's an extra thing
to worry about , especially if I have a lot of macros.
So can anyone suggest any other solution ?
Even if you don't have any ideas for my specific problem , if you've
used m4 as a preprocessor for other languages I'd be curious to see what
you did with it.