home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / cmplngmg / cl_jun89.arc / AWK210.ARC / COMPAT.AWK < prev    next >
Text File  |  1988-03-01  |  1KB  |  38 lines

  1. # compat - check if awk program uses new built-in names
  2.  
  3. BEGIN { asplit("close system atan2 sin cos rand srand " \
  4.                "match sub gsub", fcns)
  5.         asplit("ARGC ARGV FNR RSTART RLENGTH SUBSEP", vars)
  6.         asplit("do delete function return", keys)
  7.       }
  8.  
  9.       { line = $0 }
  10.  
  11. /"/   { gsub(/"([^"]|\\")*"/, "", line) }     # remove strings,
  12. /\//  { gsub(/\/([^\/]|\\\/)+\//, "", line) } # reg exprs,
  13. /#/   { sub(/#.*/, "", line) }                # and comments
  14.  
  15.       { n = split(line, x, "[^A-Za-z0-9_]+")  # into words
  16.         for (i = 1; i <= n; i++) {
  17.             if (x[i] in fcns)
  18.                 warn(x[i] " is now a built-in function")
  19.             if (x[i] in vars)
  20.                 warn(x[i] " is now a built-in variable")
  21.             if (x[i] in keys)
  22.                 warn(x[i] " is now a keyword")
  23.         }
  24.       }
  25.  
  26. function asplit(str, arr) {  # make an assoc array from str
  27.     n = split(str, temp)
  28.     for (i = 1; i <= n; i++)
  29.         arr[temp[i]]++
  30.     return n
  31. }
  32.  
  33. function warn(s) {
  34.     sub(/^[ \t]*/, "")
  35.     printf("file %s, line %d: %s\n\t%s\n", FILENAME, FNR, s, $0)
  36. }
  37.  
  38.