home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / qtawkos2.zip / QTAUTL.ZIP / compat.exp < prev    next >
Text File  |  1991-10-08  |  4KB  |  117 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("cal center copies cosh deletec execute fprint fprintf \
  14.             fract insert jdn overlay pd_sym pi remove replace rotate \
  15.             sdate 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 \
  23.             ECHO_INPUT ENVIRON FALSE LONGEST_EXP MAX_CYCLE MLENGTH \
  24.             MSTART NG QTAwk_Path RETAIN_FS TRACE TRANS_FROM TRANS_TO \
  25.             TRUE vargc vargv");
  26.  
  27.     # AWK new keywords
  28.     keys = asplit("do delete function return");
  29.  
  30.     # QTAwk new keywords
  31.     keysp = asplit("case cycle default deletea endfile FINAL INITIAL local"
  32.            "NOMATCH switch");
  33.  
  34.     # new/changed operators
  35.     s_ops  = /,/;    # new sequence (comma) operator
  36.     sc_ops = /∩=?/;    # new string concatenation operator
  37.     mo_ops = /~~?=?/;    # changed match and unary ones complement operators
  38.     bs_ops = /(<<|>>)=?/;   # new binary shift operators
  39.     bw_ops = /[&@|]=?/; # new bit-wise operators
  40.  
  41.     # expecting ';' to end statements now - cannot count on newline to do so
  42.     # allow for formatting style with opening/closing brace ending line
  43.     proper_ending = /[{};]{_w}*$/;
  44.  
  45.     # regular expression for blank and comment only lines
  46.     blank_line = /^{_w}*(#.*)?$/;
  47. }
  48.  
  49. blank_line { next; }    # skip blank and comment lines
  50.  
  51. # copy input line
  52.     {
  53.     iline = line = $0;
  54. }
  55.  
  56. # remove strings
  57. /"/ {
  58.     gsub(/"([!"]|\\")*"/,"",line);
  59. }
  60.  
  61. # remove reg. exprs.
  62. /\// {
  63.     gsub(/\/([!\/]|\\\/)+\//,"",line);
  64. }
  65.  
  66. # and comments
  67. /#/ {
  68.     sub(/#.*/,"",line);
  69. }
  70.  
  71. # copy input line back to pick up improper operators and endings in following
  72. # patterns
  73.     {
  74.     $0 = line;
  75. }
  76.  
  77. !proper_ending { warn("New Line No Longer Ends Statements"); }
  78.  
  79. s_ops  { warn("',' Is Now the Sequence Operator"); }
  80.  
  81. sc_ops { warn("'∩' Is Now the String Concatenation Operator"); }
  82.  
  83. mo_ops { warn("'~' and '~~' Are Changed Operators"); }
  84.  
  85. bs_ops { warn("'<<' and '>>' Are Now The Shift Operators"); }
  86.  
  87. bw_ops { warn("'&', '@' and '|' Are Now The Bit-Wise Operators"); }
  88.  
  89.    {
  90.     n = split(line,x,/[!A-Za-z0-9_]+/);  #into words
  91.     for ( i = 1 ; i <= n ; i++ ) {
  92.        if ( x[i] in fcns  ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Function");
  93.      else if ( x[i] in fcnsp ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Function (QTAwk)");
  94.      else if ( x[i] in vars  ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Variable");
  95.      else if ( x[i] in varsp ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Variable (QTAwk)");
  96.      else if ( x[i] in keys  ) warn("'" ∩ x[i] ∩ "' Is Now A Keyword");
  97.      else if ( x[i] in keysp ) warn("'" ∩ x[i] ∩ "' Is Now A Keyword (QTAwk)");
  98.     }
  99. }
  100.  
  101. # function to split string passed into words
  102. # words used to index array returned by function
  103. # illustrate that a user function may return an array
  104. #
  105. function asplit(str) {
  106.     local i, temp, arr;
  107.  
  108.     split(str,temp);
  109.     for ( i in temp ) arr[temp[i]]++;
  110.     return arr;
  111. }
  112.  
  113. function warn(s) {
  114.     sub(/^{_w}+/,"",iline);     # remove leading white space
  115.     printf("file %s: line %d: %s\n\t%s\n",FILENAME,FNR,s,iline);
  116. }
  117.