home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!mintaka.lcs.mit.edu!ai-lab!ai.mit.edu!kenneths
- From: kenneths@ai.mit.edu (Kenneth J. Schneider)
- Newsgroups: comp.lang.c
- Subject: Re: Wanted: program to extract comments from C
- Message-ID: <1h580nINN11p@life.ai.mit.edu>
- Date: 21 Dec 92 20:04:39 GMT
- Organization: MIT Artificial Intelligence Laboratory
- Lines: 48
- NNTP-Posting-Host: granola.ai.mit.edu
-
- well, i just hacked this lex file together:
-
- %{
- int inCComment=0, inCPPComment=0;
- %}
-
- %%
-
- \/\* {
- if (inCComment == 1)
- printf("/*");
- inCComment=1;
- }
- \*\/ {
- inCComment=0;
- printf("\n");
- }
-
- \/\/ {
- inCPPComment=1;
- }
- \n {
- if (inCPPComment==1) {
- inCPPComment=0;
- printf("\n");
- }
- }
- . {
- if (inCComment || inCPPComment)
- ECHO;
- }
- %%
-
- ---------------------------------------------------------
-
- to use it do:
- lex filename /* file containing the above code */
- cc lex.yy.c -ll
- cat yourfile.c | a.out >! mycomments
-
-
- not thoroughly tested, but should work :-)
-
-
- also note that cpp allows you to strip or not strip comment, so you could just
- run the file through cpp with strip on and with strip off, then diff the two files
-
- ken
-