home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18895 < prev    next >
Encoding:
Internet Message Format  |  1992-12-26  |  1.2 KB

  1. Path: sparky!uunet!olivea!mintaka.lcs.mit.edu!ai-lab!ai.mit.edu!kenneths
  2. From: kenneths@ai.mit.edu (Kenneth J. Schneider)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Wanted: program to extract comments from C
  5. Message-ID: <1h580nINN11p@life.ai.mit.edu>
  6. Date: 21 Dec 92 20:04:39 GMT
  7. Organization: MIT Artificial Intelligence Laboratory
  8. Lines: 48
  9. NNTP-Posting-Host: granola.ai.mit.edu
  10.  
  11. well, i just hacked this lex file together:
  12.  
  13. %{
  14. int inCComment=0, inCPPComment=0;
  15. %}
  16.  
  17. %%
  18.  
  19. \/\*    {
  20.           if (inCComment == 1)
  21.         printf("/*");
  22.       inCComment=1;
  23.     }
  24. \*\/    { 
  25.           inCComment=0;
  26.       printf("\n");
  27.     }
  28.  
  29. \/\/    {
  30.           inCPPComment=1;
  31.     }
  32. \n      {
  33.           if (inCPPComment==1) {
  34.         inCPPComment=0;
  35.         printf("\n");
  36.       }
  37.     }
  38. .       {
  39.           if (inCComment || inCPPComment)
  40.         ECHO;
  41.     }
  42. %%
  43.  
  44. ---------------------------------------------------------
  45.  
  46. to use it do:
  47.     lex filename /* file containing the above code */
  48.     cc lex.yy.c -ll
  49.     cat yourfile.c | a.out >! mycomments
  50.  
  51.  
  52. not thoroughly tested, but should work :-)
  53.  
  54.  
  55. also note that cpp allows you to strip or not strip comment, so you could just
  56. run the file through cpp with strip on and with strip off, then diff the two files
  57.  
  58. ken
  59.