home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / C_LINES.AWK < prev    next >
Text File  |  1997-07-05  |  1KB  |  46 lines

  1. # +++Date last modified: 05-Jul-1997
  2.  
  3. # count lines in a C program, not counting comments, blank lines or 
  4. # form feeds
  5. # does separate count of preprocessor directives
  6. # if a preprocessor directive is commented out, it does not count
  7. #
  8. # By: Dan Kozak
  9.  
  10. {
  11.  if (file == "") {
  12.   file = FILENAME
  13.  }
  14.  if (file != FILENAME) {
  15.   printf("Number of lines in %s is: %d\n",file,nl+ppd)
  16.   printf("Number of preprocessor directives is: %d\n",ppd)
  17.   printf("Number of lines excluding preprocessor directives is: %d\n\n",nl)
  18.   file = FILENAME
  19.   tnl += nl
  20.   tppd += ppd
  21.   nl = 0
  22.   ppd = 0
  23.  }
  24.  
  25.  if ($0 == "") { ; }
  26.  else if ($1 ~ /^\/\*/ && $NF ~ /\*\/$/) { ; }
  27.  else if ($0 ~ /\/\*/ && $0 !~ /\*\//) { in_comment = 1 }
  28.  else if ($0 !~ /\/\*/ && $0 ~ /\*\//) { in_comment = 0 }
  29.  else if (in_comment) { ; }
  30.  else if ($1 ~ /^#/) { ppd++ }
  31.  else { nl++ }
  32. }
  33.  
  34. END { printf("Number of lines in %s is: %d\n",file,nl+ppd)
  35.       printf("Number of preprocessor directives is: %d\n",ppd)
  36.       printf("Number of lines excluding preprocessor directives is: 
  37. %d\n\n",nl)
  38.       file = FILENAME
  39.       tnl += nl
  40.       tppd += ppd
  41.       printf("Total number of lines is: %d\n",tnl+tppd)
  42.       printf("Number of preprocessor directives is: %d\n",tppd)
  43.       printf("Number of lines excluding preprocessor directives is: 
  44. %d\n",tnl)
  45.     }
  46.