]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
maint: script to fix prohibit_test_const_follows_var syntax-check.
authorGary V. Vaughan <gary@gnu.org>
Fri, 21 Sep 2012 14:02:39 +0000 (21:02 +0700)
committerGary V. Vaughan <gary@gnu.org>
Fri, 21 Sep 2012 16:03:43 +0000 (23:03 +0700)
Manually fixing these with 962aa91 caused several regressions, so
write a program to redo it.
* build-aux/fix_prohibit_test_const_follows_var: New (throwaway) awk
script to programatically find and correct violations flagged by the
prohibit_test_const_follows_var syntax-check.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
build-aux/fix_prohibit_test_const_follows_var [new file with mode: 0755]

diff --git a/build-aux/fix_prohibit_test_const_follows_var b/build-aux/fix_prohibit_test_const_follows_var
new file mode 100755 (executable)
index 0000000..9d7ad05
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/env gawk -f
+
+BEGIN  {
+         tail = "(\\)|]|&&|\\|\\||;|\\\\?$)";
+
+         #       (    \1     )         (        \2         )
+         lhsx = "(\\<test\\s+)\"[.xX],?([^$\"]*\\${?\\w[^\"]*)\"\\s+";
+
+         #                  (           \4          )(     \5     )
+         rhsx = "\\s+[.xX],?([^-$][^)$;[:space:]\\]]*)(\\s*" tail ")";
+
+         #       (    \1     )  (        \2         )
+         lhs  = "(\\<test\\s+)\"([^$\"]*\\${?\\w[^\"]*)\"\\s+";
+
+         #           (           \4          )(     \5     )
+         rhs  = "\\s+([^-$][^)$;[:space:]\\]]*)(\\s*" tail ")";
+       }
+
+       {
+         line = $0;
+
+
+         ## CANONICALIZE ##
+
+         # x"$foo" -> "x$foo"
+         line = gensub ("\\<([.xX])\"([^$\"]*\\${?\\w[^\"]*)\"",
+                        "\"\\1\\2\"", "g", line)
+
+
+
+         ## SIMPLIFY ##
+
+         # test "$foo" = '' -> test -z "$foo"
+         line = gensub ("\\<test\\s+\"(\\${?\\w[^\"]*)\"\\s+=\\s+''(\\s*" tail ")",
+                        "test -z \"\\1\"\\2", "g", line);
+
+         # test '' = "$foo" -> test -z "$foo"
+         line = gensub ("\\<test\\s+''\\s+=\\s+\"(\\${?\\w[^\"]*)\"\\",
+                        "test -z \"\\1\"", "g", line);
+
+         # test "$foo" = "" -> test -z "$foo"
+         line = gensub ("\\<test\\s+\"(\\${?\\w[^\"]*)\"\\s+=\\s+\"\"(\\s*" tail ")",
+                        "test -z \"\\1\"\\2", "g", line);
+
+         # test "" = "$foo" -> test -z "$foo"
+         line = gensub ("\\<test\\s+\"\"\\s+=\\s+\"(\\${?\\w[^\"]*)\"",
+                        "test -z \"\\1\"", "g", line);
+
+         # test "x$foo" = "x" -> test -z "$foo"
+         line = gensub ("\\<test\\s+\"[.xX](\\${?\\w[^\"]*)\"\\s+=\\s+\"[.xX]\"(\\s*" tail ")",
+                        "test -z \"\\1\"\\2", "g", line);
+
+         # test "x$foo" = x -> test -z "$foo"
+         line = gensub ("\\<test\\s+\"[.xX](\\${?\\w[^\"]*)\"\\s+=\\s+[.xX](\\s*" tail ")",
+                        "test -z \"\\1\"\\2", "g", line);
+
+         # test "x" = "x$foo" -> test -z "$foo"
+         line = gensub ("\\<test\\s+\"[.xX]\"\\s+=\\s+\"[.xX](\\${?\\w[^\"]*)\"",
+                        "test -z \"\\1\"", "g", line);
+
+         # test x = "x$foo" -> test -z "$foo"
+         line = gensub ("\\<test\\s+[.xX]\\s+=\\s+\"[.xX](\\${?\\w[^\"]*)\"",
+                        "test -z \"\\1\"", "g", line);
+
+         # test "$foo" != '' -> test -n "$foo"
+         line = gensub ("\\<test\\s+\"(\\${?\\w[^\"]*)\"\\s+!=\\s+''(\\s*" tail ")",
+                        "test -n \"\\1\"\\2", "g", line);
+
+         # test '' != "$foo" -> test -n "$foo"
+         line = gensub ("\\<test\\s+''\\s+!=\\s+\"(\\${?\\w[^\"]*)\"\\",
+                        "test -n \"\\1\"", "g", line);
+
+         # test "$foo" != "" -> test -n "$foo"
+         line = gensub ("\\<test\\s+\"(\\${?\\w[^\"]*)\"\\s+!=\\s+\"\"(\\s*" tail ")",
+                        "test -n \"\\1\"\\2", "g", line);
+
+         # test "" != "$foo" -> test -n "$foo"
+         line = gensub ("\\<test\\s+\"\"\\s+!=\\s+\"(\\${?\\w[^\"]*)\"",
+                        "test -n \"\\1\"", "g", line);
+
+         # test "x$foo" != "x" -> test -n "$foo"
+         line = gensub ("\\<test\\s+\"[.xX](\\${?\\w[^\"]*)\"\\s+!=\\s+\"[.xX]\"(\\s*" tail ")",
+                        "test -n \"\\1\"\\2", "g", line);
+
+         # test "x$foo" != x -> test -n "$foo"
+         line = gensub ("\\<test\\s+\"[.xX](\\${?\\w[^\"]*)\"\\s+!=\\s+[.xX](\\s*" tail ")",
+                        "test -n \"\\1\"\\2", "g", line);
+
+         # test "x" != "x$foo" -> test -n "$foo"
+         line = gensub ("\\<test\\s+\"[.xX]\"\\s+!=\\s+\"[.xX](\\${?\\w[^\"]*)\"",
+                        "test -n \"\\1\"", "g", line);
+
+         # test x != "x$foo" -> test -n "$foo"
+         line = gensub ("\\<test\\s+[.xX]\\s+!=\\s+\"[.xX](\\${?\\w[^\"]*)\"",
+                        "test -n \"\\1\"", "g", line);
+
+
+
+         ## ELIMINATE SPURIOUS CHARACTERS ##
+
+         # swap equivalencies with a lhs string
+         line = gensub (lhsx "(!?=|-eq|-ne)" rhsx, "\\1\\4 \\3 \"\\2\"\\5", "g", line);
+         line = gensub (lhs "(!?=|-eq|-ne)" rhs,   "\\1\\4 \\3 \"\\2\"\\5", "g", line);
+
+         # reverse -lt and -lte operand order
+         line = gensub (lhsx "-l(te?)" rhsx,   "\\1\\4 -g\\3 \"\\2\"\\5", "g", line);
+         line = gensub (lhs "-l(te?)" rhs,     "\\1\\4 -g\\3 \"\\2\"\\5", "g", line);
+
+         # reverse -gt and -gte operand order
+         line = gensub (lhsx "-g(te?)" rhsx,   "\\1\\4 -l\\3 \"\\2\"\\5", "g", line);
+         line = gensub (lhs "-g(te?)" rhs,     "\\1\\4 -l\\3 \"\\2\"\\5", "g", line);
+
+
+         # eliminate remaining spurious quotes
+         line = gensub ("\\<test \"([[:alnum:]._,+:-]+)\"", "test \\1", "g", line);
+
+
+
+         ## EDGE CASES ##
+
+         line = gensub ("\\<test [.xX]([^-$][[:alnum:]._,+:-]*)\\s+(!?=|-eq|-ne|-[lg]te?)\\s+\"[.xX]",
+                        "test \\1 \\2 \"", "g", line)
+
+
+         print line;
+       }