home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / qtawk / compat.exp < prev    next >
Text File  |  1990-05-02  |  4KB  |  116 lines

  1. # compat - check if AWK program uses new built-in functions
  2. #
  3. #  adapted from AWK, page 80
  4. #
  5. #  includes new/changed operators of QTAwk
  6. #  includes new keywords, built-in functions and built-in variables of QTAwk
  7. #
  8. BEGIN  {
  9.     # AWK new functions
  10.     fcns = asplit("close system atan2 sin cos rand srand match sub gsub");
  11.  
  12.     # QTAwk new functions
  13.     fcnsp = asplit("center copies cosh deletec execute fprint fprintf fract"
  14.            "insert overlay pd_sym pi remove replace rotate sdate"
  15.            "sinh srange srev stime strlwr strupr translate trim"
  16.            "ud_sym");
  17.  
  18.     # AWK new built-in variables
  19.     vars = asplit("ARGC ARGV FNR RSTART RLENGTH");
  20.  
  21.     # QTAwk new built-in variables
  22.     varsp = asplit("_arg_chk ARGI CLENGTH CSTART CYCLE_COUNT DEGREES FALSE"
  23.            "LONGEST_EXP MLENGTH MSTART NG RETAIN_FS TRACE MAX_CYCLE"
  24.            "TRANS_FROM TRANS_TO TRUE vargc vargv");
  25.  
  26.     # AWK new keywords
  27.     keys = asplit("do delete function return");
  28.  
  29.     # QTAwk new keywords
  30.     keysp = asplit("case cycle default deletea endfile FINAL INITIAL local"
  31.            "NOMATCH switch");
  32.  
  33.     # new/changed operators
  34.     s_ops  = /,/;    # new sequence (comma) operator
  35.     sc_ops = /∩=?/;    # new string concatenation operator
  36.     mo_ops = /~~?=?/;    # changed match and unary ones complement operators
  37.     bs_ops = /(<<|>>)=?/;   # new binary shift operators
  38.     bw_ops = /[&@|]=?/; # new bit-wise operators
  39.  
  40.     # expecting ';' to end statements now - cannot count on newline to do so
  41.     # allow for formatting style with opening/closing brace ending line
  42.     proper_ending = /[{};]{_w}*$/;
  43.  
  44.     # regular expression for blank and comment only lines
  45.     blank_line = /^{_w}*(#.*)?$/;
  46. }
  47.  
  48. blank_line { next; }    # skip blank and comment lines
  49.  
  50. # copy input line
  51.     {
  52.     iline = line = $0;
  53. }
  54.  
  55. # remove strings
  56. /"/ {
  57.     gsub(/"([!"]|\\")*"/,"",line);
  58. }
  59.  
  60. # remove reg. exprs.
  61. /\// {
  62.     gsub(/\/([!\/]|\\\/)+\//,"",line);
  63. }
  64.  
  65. # and comments
  66. /#/ {
  67.     sub(/#.*/,"",line);
  68. }
  69.  
  70. # copy input line back to pick up improper operators and endings in following
  71. # patterns
  72.     {
  73.     $0 = line;
  74. }
  75.  
  76. !proper_ending { warn("New Line No Longer Ends Statements"); }
  77.  
  78. s_ops  { warn("',' Is Now the Sequence Operator"); }
  79.  
  80. sc_ops { warn("'∩' Is Now the String Concatenation Operator"); }
  81.  
  82. mo_ops { warn("'~' and '~~' Are Changed Operators"); }
  83.  
  84. bs_ops { warn("'<<' and '>>' Are Now The Shift Operators"); }
  85.  
  86. bw_ops { warn("'&', '@' and '|' Are Now The Bit-Wise Operators"); }
  87.  
  88.    {
  89.     n = split(line,x,/[!A-Za-z0-9_]+/);  #into words
  90.     for ( i = 1 ; i <= n ; i++ ) {
  91.        if ( x[i] in fcns  ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Function");
  92.      else if ( x[i] in fcnsp ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Function (QTAwk)");
  93.      else if ( x[i] in vars  ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Variable");
  94.      else if ( x[i] in varsp ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Variable (QTAwk)");
  95.      else if ( x[i] in keys  ) warn("'" ∩ x[i] ∩ "' Is Now A Keyword");
  96.      else if ( x[i] in keysp ) warn("'" ∩ x[i] ∩ "' Is Now A Keyword (QTAwk)");
  97.     }
  98. }
  99.  
  100. # function to split string passed into words
  101. # words used to index array returned by function
  102. # illustrate that a user function may return an array
  103. #
  104. function asplit(str) {
  105.     local i, temp, arr;
  106.  
  107.     split(str,temp);
  108.     for ( i in temp ) arr[temp[i]]++;
  109.     return arr;
  110. }
  111.  
  112. function warn(s) {
  113.     sub(/^{_w}+/,"",iline);     # remove leading white space
  114.     printf("file %s: line %d: %s\n\t%s\n",FILENAME,FNR,s,iline);
  115. }
  116.