Path: utzoo!attcan!utgpu!watmath!att!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!uwm.edu!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.wizards Subject: Re: Need help using /usr/lib/cpp for generic text Message-ID: <3323@solo10.cs.vu.nl> Date: 21 Sep 89 21:46:16 GMT References: <838@pacific.mps.ohio-state.edu> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 70 verber@pacific.mps.ohio-state.edu (Mark A. Verber) writes: \... \(1) Bloody "# line-number file-name" lines \ \I had thought that the -P switch suppressed such output, but that doesn't \seem to be the case (SunOS 4.x /usr/lib/cpp). I don't want these lines. Huh? `-P' works for me on SunOS 4.0.1! \(2) Leaving in the text \ \When I run text like: I get the output like: I would like: \ \ #define foo before before \ before test \ #ifdef foo test after \ test \ #endif after \ after You could use the following script instead of cpp: ----------8<----------8<----------8<----------8<----------8<---------- #!/bin/sh tab=" " for i in define undef ifdef ifndef if elif else endif do SED1=" $SED1 /^[ $tab]*#[ $tab]*$i/{ s//\\\\&/ p s/.// b } " # due to a bug in some sed versions, the `p' mustn't # be appended to the previous substitute command SED2=" $SED2 /^\\\\[ $tab]*#[ $tab]*$i/{ N d } " done sed "$SED1" ${1+"$@"} | /lib/cpp -P | sed "$SED2" ----------8<----------8<----------8<----------8<----------8<---------- The idea is to remember that a line must be removed: #define foo bar becomes \#define foo bar #define foo bar cpp will leave the first line intact and change the second to an empty line. The second invocation of sed will delete both lines. One limitation: you shouldn't use `/*' and `*/' to comment out text; instead use: #if 0 ... #endif 0 -- creat(2) shouldn't have been create(2): |Maarten Litmaath @ VU Amsterdam: it shouldn't have existed at all. |maart@cs.vu.nl, mcvax!botter!maart