home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / awk / awk320.zip / C_COUNT.AWK < prev    next >
Text File  |  1990-02-08  |  1KB  |  44 lines

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