home *** CD-ROM | disk | FTP | other *** search
- # compat - check if AWK program uses new built-in functions
- #
- # adapted from AWK, page 80
- #
- # includes new/changed operators of QTAwk
- # includes new keywords, built-in functions and built-in variables of QTAwk
- #
- BEGIN {
- # AWK new functions
- fcns = asplit("close system atan2 sin cos rand srand match sub gsub");
-
- # QTAwk new functions
- fcnsp = asplit("center copies cosh deletec execute fprint fprintf fract"
- "insert overlay pd_sym pi remove replace rotate sdate"
- "sinh srange srev stime strlwr strupr translate trim"
- "ud_sym");
-
- # AWK new built-in variables
- vars = asplit("ARGC ARGV FNR RSTART RLENGTH");
-
- # QTAwk new built-in variables
- varsp = asplit("_arg_chk ARGI CLENGTH CSTART CYCLE_COUNT DEGREES FALSE"
- "LONGEST_EXP MLENGTH MSTART NG RETAIN_FS TRACE MAX_CYCLE"
- "TRANS_FROM TRANS_TO TRUE vargc vargv");
-
- # AWK new keywords
- keys = asplit("do delete function return");
-
- # QTAwk new keywords
- keysp = asplit("case cycle default deletea endfile FINAL INITIAL local"
- "NOMATCH switch");
-
- # new/changed operators
- s_ops = /,/; # new sequence (comma) operator
- sc_ops = /∩=?/; # new string concatenation operator
- mo_ops = /~~?=?/; # changed match and unary ones complement operators
- bs_ops = /(<<|>>)=?/; # new binary shift operators
- bw_ops = /[&@|]=?/; # new bit-wise operators
-
- # expecting ';' to end statements now - cannot count on newline to do so
- # allow for formatting style with opening/closing brace ending line
- proper_ending = /[{};]{_w}*$/;
-
- # regular expression for blank and comment only lines
- blank_line = /^{_w}*(#.*)?$/;
- }
-
- blank_line { next; } # skip blank and comment lines
-
- # copy input line
- {
- iline = line = $0;
- }
-
- # remove strings
- /"/ {
- gsub(/"([!"]|\\")*"/,"",line);
- }
-
- # remove reg. exprs.
- /\// {
- gsub(/\/([!\/]|\\\/)+\//,"",line);
- }
-
- # and comments
- /#/ {
- sub(/#.*/,"",line);
- }
-
- # copy input line back to pick up improper operators and endings in following
- # patterns
- {
- $0 = line;
- }
-
- !proper_ending { warn("New Line No Longer Ends Statements"); }
-
- s_ops { warn("',' Is Now the Sequence Operator"); }
-
- sc_ops { warn("'∩' Is Now the String Concatenation Operator"); }
-
- mo_ops { warn("'~' and '~~' Are Changed Operators"); }
-
- bs_ops { warn("'<<' and '>>' Are Now The Shift Operators"); }
-
- bw_ops { warn("'&', '@' and '|' Are Now The Bit-Wise Operators"); }
-
- {
- n = split(line,x,/[!A-Za-z0-9_]+/); #into words
- for ( i = 1 ; i <= n ; i++ ) {
- if ( x[i] in fcns ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Function");
- else if ( x[i] in fcnsp ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Function (QTAwk)");
- else if ( x[i] in vars ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Variable");
- else if ( x[i] in varsp ) warn("'" ∩ x[i] ∩ "' Is Now A Built-In Variable (QTAwk)");
- else if ( x[i] in keys ) warn("'" ∩ x[i] ∩ "' Is Now A Keyword");
- else if ( x[i] in keysp ) warn("'" ∩ x[i] ∩ "' Is Now A Keyword (QTAwk)");
- }
- }
-
- # function to split string passed into words
- # words used to index array returned by function
- # illustrate that a user function may return an array
- #
- function asplit(str) {
- local i, temp, arr;
-
- split(str,temp);
- for ( i in temp ) arr[temp[i]]++;
- return arr;
- }
-
- function warn(s) {
- sub(/^{_w}+/,"",iline); # remove leading white space
- printf("file %s: line %d: %s\n\t%s\n",FILENAME,FNR,s,iline);
- }
-