not the way ... (was Re: Want a way to strip comments from a)
Randal L. Schwartz @ Stonehenge
merlyn at intelob.intel.com
Fri Mar 17 08:37:19 AEST 1989
In article <9900010 at bradley>, brian at bradley writes:
| > Does anyone have a sed or awk script which we
| > can use to preprocess the C source and get rid of all the comments before
| > sending it to the compiler?
|
| The following works in vi: :%s/\/\*.*\*\///g
|
| I don't know if it will work in sed, but it should...
Nope. Just try it on the line:
foo; bar; /* comment1 */ bletch; /* comment2 */
'bletch;' disappears with the comments.
The regexp that matches comments looks like (in egrep/lex notation):
[/][*]([*]*[^*/])*[*]+[/]
(I use [X] here instead of \X because I hate backslashes...).
Sed and vi are not powerful enough to eat things like this in one
regexp.
Didn't we just go through this about nine months ago? :-)
(And didn't I give the wrong answer at least twice? :-) :-)
--
Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095
on contract to BiiN (for now :-), Hillsboro, Oregon, USA.
ARPA: <@intel-iwarp.arpa:merlyn at intelob> (fastest!)
MX-Internet: <merlyn at intelob.intel.com> UUCP: ...[!uunet]!tektronix!biin!merlyn
Standard disclaimer: I *am* my employer!
Cute quote: "Welcome to Oregon... home of the California Raisins!"
More information about the Comp.lang.c
mailing list