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

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