bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gawk --lint-old (was: awk portability notes)


From: Ralf Wildenhues
Subject: gawk --lint-old (was: awk portability notes)
Date: Sun, 03 Dec 2006 10:06:07 +0100

The following patch tests some more issues related to V7 awk,
and adds a testsuite test for --lint-old.
Cheers,
Ralf
ChangeLog:
2006-12-03 Ralf Wildenhues <address@hidden>
        Enable more `--lint-old' warnings.
        * awkgram.y: Warning about multiple BEGIN or END rules,
        `index in array' outside of for loops, multidimensional arrays.
        * field.c (set_FS): Warn about regex FS.
* node.c (parse_escape): Warn about `\b', `\f', `\r'.
test/ChangeLog:
2006-12-03 Ralf Wildenhues <address@hidden>
        * lintold.awk, lintold.in, lintold.ok: New `--lint-old' test.
* Gentests, Makefile.am: Adjust.
Index: awkgram.y
===================================================================
RCS file: /cvsroot/gawk/gawk-stable/awkgram.y,v
retrieving revision 1.3
diff -u -r1.3 awkgram.y
--- awkgram.y   5 Sep 2006 23:10:41 -0000       1.3
+++ awkgram.y   2 Dec 2006 11:39:13 -0000
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-2005 the Free Software Foundation, Inc. + * Copyright (C) 1986, 1988, 1989, 1991-2006 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -245,11 +245,19 @@
          }
        | LEX_BEGIN
          {
+               static int begin_seen = 0;
+               if (++begin_seen == 2 && do_lint_old) {
+                 warning(_("old awk does not support multiple `BEGIN' or `END' 
rules"));
+               }
                begin_or_end_rule = TRUE;
                $$ = append_pattern(&begin_block, (NODE *) NULL);
          }
        | LEX_END
          {
+               static int end_seen = 0;
+               if (++end_seen == 2 && do_lint_old) {
+                 warning(_("old awk does not support multiple `BEGIN' or `END' 
rules"));
+               }
                begin_or_end_rule = parsing_end_rule = TRUE;
                $$ = append_pattern(&end_block, (NODE *) NULL);
          }
@@ -808,7 +816,11 @@
                  $$ = node($1, $2, mk_rexp($3));
                }
        | exp LEX_IN NAME
-               { $$ = node(variable($3, CAN_FREE, Node_var_array), 
Node_in_array, $1); }
+               {
+                 if (do_lint_old)
+ warning(_("old awk does not support the keyword `in' except after `for'"));
+                 $$ = node(variable($3, CAN_FREE, Node_var_array), 
Node_in_array, $1);
+               }
        | exp a_relop exp %prec RELOP
                {
                  if (do_lint && $3->type == Node_regex)
@@ -854,7 +866,13 @@
                            $2);
                }
        | '(' expression_list r_paren LEX_IN NAME
-               { $$ = node(variable($5, CAN_FREE, Node_var_array), 
Node_in_array, $2); }
+               {
+                 if (do_lint_old) {
+ warning(_("old awk does not support the keyword `in' except after `for'"));
+                   warning(_("old awk does not support multidimensional 
arrays"));
+                 }
+                 $$ = node(variable($5, CAN_FREE, Node_var_array), 
Node_in_array, $2);
+               }
        | simp_exp
                { $$ = $1; }
        | common_exp simp_exp %prec CONCAT_OP
Index: field.c
===================================================================
RCS file: /cvsroot/gawk/gawk-stable/field.c,v
retrieving revision 1.2
diff -u -r1.2 field.c
--- field.c     11 Aug 2006 12:49:40 -0000      1.2
+++ field.c     2 Dec 2006 11:39:13 -0000
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-2005 the Free Software Foundation, Inc. + * Copyright (C) 1986, 1988, 1989, 1991-2006 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -1027,6 +1027,8 @@
                        lintwarn(_("null string for `FS' is a gawk extension"));
                }
        } else if (fs->stlen > 1) {
+               if (do_lint_old)
+                       warning(_("old awk does not support regexps as value of 
`FS'"));
                parse_field = re_parse_field;
        } else if (RS_is_null) {
                /* we know that fs->stlen <= 1 */
Index: node.c
===================================================================
RCS file: /cvsroot/gawk/gawk-stable/node.c,v
retrieving revision 1.2
diff -u -r1.2 node.c
--- node.c      11 Aug 2006 12:49:40 -0000      1.2
+++ node.c      2 Dec 2006 11:39:13 -0000
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-2001, 2003-2005 the Free Software Foundation, Inc. + * Copyright (C) 1986, 1988, 1989, 1991-2001, 2003-2006 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -545,6 +545,15 @@
        register int i;
register int count;
+       if (do_lint_old) {
+               switch (c) {
+               case 'b':
+               case 'f':
+               case 'r':
+ warning(_("old awk does not support the escape sequences `\\b', `\\f' and `\\r'"));
+               }
+       }
+
        switch (c) {
        case 'a':
                return BELL;
Index: test/Gentests
===================================================================
RCS file: /cvsroot/gawk/gawk-stable/test/Gentests,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Gentests
--- test/Gentests       11 Aug 2006 12:05:50 -0000      1.1.1.1
+++ test/Gentests       2 Dec 2006 11:39:13 -0000
@@ -29,6 +29,13 @@
        next
}
+/^NEED_LINT_OLD *=/,/[^\\]$/ {
+       gsub(/(^NEED_LINT_OLD *=|\\$)/,"")
+       for (i = 1; i <= NF; i++)
+               lint_old[$i]
+       next
+}
+
/^GENTESTS_UNUSED *=/,/[^\\]$/ {
        gsub(/(^GENTESTS_UNUSED *=|\\$)/,"")
        for (i = 1; i <= NF; i++)
@@ -71,6 +78,10 @@
                s = s " --lint"
                delete lint[x]
        }
+       if (x in lint_old) {
+               s = s " --lint-old"
+               delete lint_old[x]
+       }
        if (x".in" in files) {
                s = s " < $(srcdir)/address@hidden"
                delete files[x".in"]
@@ -85,6 +96,9 @@
        for (x in lint)
                if (!(x in targets))
                        printf "WARNING: --lint target `%s' is missing.\n", x > 
"/dev/stderr"
+       for (x in lint_old)
+               if (!(x in targets))
+ printf "WARNING: --lint-old target `%s' is missing.\n", x > "/dev/stderr"
        for (x in files)
                if (!(x in unused) && \
                    !(gensub(/\.(awk|in)$/,"","",x) in targets))
Index: test/Makefile.am
===================================================================
RCS file: /cvsroot/gawk/gawk-stable/test/Makefile.am,v
retrieving revision 1.3
diff -u -r1.3 Makefile.am
--- test/Makefile.am    5 Sep 2006 23:10:55 -0000       1.3
+++ test/Makefile.am    2 Dec 2006 11:39:13 -0000
@@ -1,7 +1,7 @@
#
# test/Makefile.am --- automake input file for gawk
#
-# Copyright (C) 1988-2005 the Free Software Foundation, Inc.
+# Copyright (C) 1988-2006 the Free Software Foundation, Inc.
#
# This file is part of GAWK, the GNU implementation of the
# AWK Programming Language.
@@ -292,6 +292,9 @@
        leadnl.ok \
        lint.awk \
        lint.ok \
+       lintold.awk \
+       lintold.in \
+       lintold.ok \
        litoct.awk \
        litoct.ok \
        longdbl.awk \
@@ -624,7 +627,7 @@ GAWK_EXT_TESTS = argtest asort asorti backw badargs binmode1 clos1way devfd1 devfd2 \
        fieldwdth fsfwfs fwtest  gensub gensub2 gnuops2 gnuops3 gnureops 
icasefs \
-       icasers igncdym igncfs ignrcase ignrcas2 lint match1 match2 manyfiles \
+ icasers igncdym igncfs ignrcase ignrcas2 lint lintold match1 match2 manyfiles \
        nondec nondec2 posix procinfs printfbad1 regx8bit rebuf reint rsstart1 \
rsstart2 rsstart3 rstest6 shadow sort1 strtonum strftime whiny
@@ -635,6 +638,9 @@
# List of the tests which should be run with --lint option:
NEED_LINT = defref noeffect nofmtch shadow uninit2 uninit3 uninit4 uninitialized
+# List of the tests which should be run with --lint-old option:
+NEED_LINT_OLD = lintold
+
# List of the files that appear in manual tests or are for reserve testing:
GENTESTS_UNUSED = Makefile.in gtlnbufv.awk printfloat.awk switch2.awk
--- /dev/null   2006-05-22 13:44:12.000000000 +0200
+++ test/lintold.awk    2006-12-02 11:31:50.000000000 +0100
@@ -0,0 +1,21 @@
+# lintold.awk --- test --lint-old
+
+BEGIN {
+       a[1] = 1
+       for (i in a)
+         print a[i]
+       delete a[1]
+       if (2 in a)
+         a[2] **= 2;
+       if ((2,3) in a)
+         a[2,3] ^= 2 ** 3 ^ 15;
+}
+BEGIN {
+       FS = "ab"
+       foo = "\b\f\r"
+}
+END {
+}
+END {
+        print "done"
+}
--- /dev/null   2006-05-22 13:44:12.000000000 +0200
+++ test/lintold.in     2006-12-02 11:17:19.000000000 +0100
@@ -0,0 +1 @@
+
--- /dev/null   2006-05-22 13:44:12.000000000 +0200
+++ test/lintold.ok     2006-12-02 11:39:58.000000000 +0100
@@ -0,0 +1,16 @@
+gawk: lintold.awk:7: warning: `delete' is not supported in old awk
+gawk: lintold.awk:8: warning: old awk does not support the keyword `in' except after `for'
+gawk: lintold.awk:9: warning: old awk does not support operator `**='
+gawk: lintold.awk:10: warning: old awk does not support the keyword `in' except after `for' +gawk: lintold.awk:10: warning: old awk does not support multidimensional arrays
+gawk: lintold.awk:11: warning: operator `^=' is not supported in old awk
+gawk: lintold.awk:11: warning: old awk does not support operator `**'
+gawk: lintold.awk:11: warning: operator `^' is not supported in old awk
+gawk: lintold.awk:13: warning: old awk does not support multiple `BEGIN' or `END' rules +gawk: lintold.awk:15: warning: old awk does not support the escape sequences `\b', `\f' and `\r' +gawk: lintold.awk:15: warning: old awk does not support the escape sequences `\b', `\f' and `\r' +gawk: lintold.awk:15: warning: old awk does not support the escape sequences `\b', `\f' and `\r' +gawk: lintold.awk:19: warning: old awk does not support multiple `BEGIN' or `END' rules
+1
+gawk: lintold.awk:14: warning: old awk does not support regexps as value of `FS' +done




reply via email to

[Prev in Thread] Current Thread [Next in Thread]