Re: Preprocessor for Informix 4GL m4/cpp?
Posted in 1994
In <36sd4d$nss@newsbf01.news.aol.com> sfidai@aol.com (SFidai) writes: >Has anyone experimented using m4 with Informix 4GL programs? I know >cpp can not be used as '#' will conflict with cpp commands. Sure you can use cpp -- I couldn't live without it. Add something like this to your Makefile: ====================================================================== CPP = /path/to/your/cpp #e.g., /usr/local/lib/gcc/gcc-cpp # I like to throw in any other defs that might be useful, so mine is # CPP=/usr/local/lib/gcc/gcc-cpp -D`hostname` $(DEFS) .SUFFIXES .4 .4gl .4gi .frm .per .4.4gl: sed -e 's/\\([^\\]\\)#.*/\\1/' -e 's/^#.*//' -e 's/\\\\#/#/g' -e 's/^@/#/' -e 's/~/#/g' $< | $(CPP) > $@ .4gl.4go: fglpc $< .per.frm: form4gl $< ====================================================================== Then you edit xyz.4, and when you do a make, it turns into xyz.4gl, which the other make rule turns into .4go. Also a rule for .per --> .frm. The translation from .4 to .4gl is done by sed & cpp, with sed doing this: (1) Strips out #comment-to-end-of-line, except where prefixed with \\ (as spurious #'s will confuse cpp) (2) Replaces \\# with #, e.g., for use in strings (3) Replaces @ at start of line with #, for use in @define/etc. (4) Replaces ~ with # for those who don't like \\# So, in a .4 file, you would say @include "stuff.h" @define FOO bar @ifdef DOTHIS ... @endif Only remember that if you @include a .h file, inside *that* you must use #define, since that will never be seen by fglpc. You could also just remove # lines that don't start as #define, #include, #if, etc., but I found that to be error prone -- if you happen to start a comment like "#if this is..."... Alternatively, use # for cpp only, and "--" for comments (but I personally don't like that, hence the convolution). Also note that @ is only "magical" as the first character on the line, so (a) not a problem using it in queries, (b) you have to start your @define in column 1, and (c) you don't want to have a query with @ in column 1, like select ... where @foo = bar -- Which I doubt you'd want anyway, but FYI... -- Andrew Burt aburt@du.edu "But if he was dying he wouldn't bother to carve "Aaaaargh", he'd just say it."