[comp.unix.questions] question about m4 - macro preprocessor

carl@gemed (Carl Crawford) (11/20/90)

i am using the macro preprocessor m4 with files that are
subsequently passed to troff. m4 replaces lines that 
contain m4 commands with blank lines. the blank lines
disrupt the text that is passed to troff. does anyone know 
how to run m4 so that the blank lines can be eliminated?


Carl R. Crawford, Ph.D.	   Voice: 414-521-6572
GE Medical Systems	   Fax: 414-521-6575
P.O. Box 414, W-875	   Uucp: {sun!sunbird,uunet!crdgw1}!gemed!carl
Milwaukee, WI 53201	   Internet: carl@gemed.ge.com

rickert@mp.cs.niu.edu (Neil Rickert) (11/25/90)

In article <3201@mrsvr.UUCP> carl@gemed.ge.com (Carl Crawford) writes:
>i am using the macro preprocessor m4 with files that are
>subsequently passed to troff. m4 replaces lines that 
>contain m4 commands with blank lines. the blank lines
>disrupt the text that is passed to troff. does anyone know 
>how to run m4 so that the blank lines can be eliminated?
>
 m4 appears to 'replace lines that contain m4 commands with blank lines',
but actually this is a misinterpretation of what m4 is doing.

 m4 acts on the commands and substitutions, but leaves everything else
untouched.  Consequently it leaves untouched the '\n' at the end of the
line containing the command.

 Solution:  Liberal use of the command 'dnl' (delete to new line).

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115.                                  +1-815-753-6940

eric@snark.thyrsus.com (Eric S. Raymond) (11/26/90)

In <3201@mrsvr.UUCP> Carl Crawford wrote:
> i am using the macro preprocessor m4 with files that are
> subsequently passed to troff. m4 replaces lines that 
> contain m4 commands with blank lines. the blank lines
> disrupt the text that is passed to troff. does anyone know 
> how to run m4 so that the blank lines can be eliminated?

No sweat. Just append the special token `dnl' to the lines containing your
macro calls. This mutually annihilates the newline immediately following. So,
instead of

================
mytext
mymacro(baz, qux)
more_mytext
================

write

================
mytext
mymacro(baz, qux)dnl
more_mytext
================

Happy hacking!
-- 
      Eric S. Raymond = eric@snark.thyrsus.com  (mad mastermind of TMN-Netnews)

ckp@grebyn.com (Checkpoint Technologies) (11/27/90)

In article <3201@mrsvr.UUCP> carl@gemed.ge.com (Carl Crawford) writes:
>i am using the macro preprocessor m4 with files that are
>subsequently passed to troff. m4 replaces lines that 
>contain m4 commands with blank lines. the blank lines
>disrupt the text that is passed to troff. does anyone know 
>how to run m4 so that the blank lines can be eliminated?

Put the macro "dnl" at the end of your m4 macro lines.  This asks m4 to
read and discard input characters up to and including the trailing
newline from the input file.  Therefore the trailing newline, and
consequently the undesirable blank lines, will be omitted from the
output file.
-- 
First comes the logo: C H E C K P O I N T  T E C H N O L O G I E S      / /  
                                                                    \\ / /    
Then, the disclaimer:  All expressed opinions are, indeed, opinions. \  / o
Now for the witty part:    I'm pink, therefore, I'm spam!             \/

gwyn@smoke.brl.mil (Doug Gwyn) (11/27/90)

In article <3201@mrsvr.UUCP> carl@gemed.ge.com (Carl Crawford) writes:
>i am using the macro preprocessor m4 with files that are
>subsequently passed to troff. m4 replaces lines that 
>contain m4 commands with blank lines. the blank lines
>disrupt the text that is passed to troff. does anyone know 
>how to run m4 so that the blank lines can be eliminated?

Yes, end the m4 commands with a dnl command.

mvadh@cbnews.att.com (andrew.d.hay) (11/27/90)

In article <3201@mrsvr.UUCP>, carl@gemed (Carl Crawford) writes:
> i am using the macro preprocessor m4 with files that are
> subsequently passed to troff. m4 replaces lines that 
> contain m4 commands with blank lines. the blank lines
> disrupt the text that is passed to troff. does anyone know 
> how to run m4 so that the blank lines can be eliminated?

it's easy -- add "dnl" to the end of each m4 macro definition.
this deletes the newline that otherwise automatically follows
the definition.

-- 
Andrew Hay		+------------------------------------------------------+
Ragged Individualist	| 	You just have _N_O idea!  It's the difference    |
AT&T-BL Ward Hill MA	|	between _S_H_O_O_T_I_N_G a bullet and _T_H_R_O_W_I_N_G it!     |
a.d.hay@att.com		+------------------------------------------------------+