Re: [PATCH 1/7] syntax-check: fix violations and implement sc_useless_quotes_in_case.

2011-11-25 Thread Gary V. Vaughan
On 21 Nov 2011, at 21:47, Gary V. Vaughan wrote:
 I'll push the whole series in 72 hours or so as usual.

Pushed.

 [[snip]]
 
 Contrary to popular belief, Bourne shell does not resplit case
 expressions after expansion, so if there are no shell unquoted
 shell metacharacters or whitespace, the quotes are useless.
 * cfg.mk (sc_useless_quotes_in_case): New syntax-check rule to
 ensure we don't reintroduce useless quoted case expressions.
 * build-aux/ltmain.m4sh, m4/libtool.m4, tests/bindir.at,
 tests/darwin.at, tests/defs.m4sh, tests/demo-hardcode.test,
 tests/demo-nopic.test, tests/link-2.test, tests/quote.test,
 tests/sysroot.at: Remove spurious quotes.
 
 Signed-off-by: Gary V. Vaughan g...@gnu.org
 ---
 build-aux/ltmain.m4sh|   12 ++--
 cfg.mk   |8 
 m4/libtool.m4|2 +-
 tests/bindir.at  |4 ++--
 tests/darwin.at  |2 +-
 tests/defs.m4sh  |2 +-
 tests/demo-hardcode.test |4 ++--
 tests/demo-nopic.test|6 +++---
 tests/link-2.test|2 +-
 tests/quote.test |8 
 tests/sysroot.at |2 +-
 11 files changed, 30 insertions(+), 22 deletions(-)


Cheers,
-- 
Gary V. Vaughan (gary AT gnu DOT org)



[PATCH 1/7] syntax-check: fix violations and implement sc_useless_quotes_in_case.

2011-11-21 Thread Gary V. Vaughan
More syntax-check inspired goodness to make our shell code more
readable and maintainable.  There's nothing controversial in here,
except perhaps a seemingly large amount of code churn for a
relatively small gain in each case, however the code definitely
*does* need all the help it can get to be maintainable without
severe hair loss, and even a journey of 1000 miles starts with a
single step, so I'll push the whole series in 72 hours or so as
usual.

By the end of this series, we've made some good progress in
unifying the style of new and old shell code alike, and since it's
all hooked into syntax-check, it'll take a concerted effort to
regress the aspects of style I've tackled, since make distcheck
will now fail if new violations are added in future. But, making
some of the older stuff not look like spaghetti is a much much
bigger task than these few patches are able to achieve.

Feedback welcome.

Contrary to popular belief, Bourne shell does not resplit case
expressions after expansion, so if there are no shell unquoted
shell metacharacters or whitespace, the quotes are useless.
* cfg.mk (sc_useless_quotes_in_case): New syntax-check rule to
ensure we don't reintroduce useless quoted case expressions.
* build-aux/ltmain.m4sh, m4/libtool.m4, tests/bindir.at,
tests/darwin.at, tests/defs.m4sh, tests/demo-hardcode.test,
tests/demo-nopic.test, tests/link-2.test, tests/quote.test,
tests/sysroot.at: Remove spurious quotes.

Signed-off-by: Gary V. Vaughan g...@gnu.org
---
 build-aux/ltmain.m4sh|   12 ++--
 cfg.mk   |8 
 m4/libtool.m4|2 +-
 tests/bindir.at  |4 ++--
 tests/darwin.at  |2 +-
 tests/defs.m4sh  |2 +-
 tests/demo-hardcode.test |4 ++--
 tests/demo-nopic.test|6 +++---
 tests/link-2.test|2 +-
 tests/quote.test |8 
 tests/sysroot.at |2 +-
 11 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/build-aux/ltmain.m4sh b/build-aux/ltmain.m4sh
index 5e8fb25..ee93a21 100644
--- a/build-aux/ltmain.m4sh
+++ b/build-aux/ltmain.m4sh
@@ -461,7 +461,7 @@ func_lalib_unsafe_p ()
for lalib_p_l in 1 2 3 4
do
read lalib_p_line
-   case $lalib_p_line in
+   case $lalib_p_line in
\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
esac
done
@@ -568,7 +568,7 @@ func_resolve_sysroot ()
 # store the result into func_replace_sysroot_result.
 func_replace_sysroot ()
 {
-  case $lt_sysroot:$1 in
+  case $lt_sysroot:$1 in
   ?*:$lt_sysroot*)
 func_stripname $lt_sysroot '' $1
 func_replace_sysroot_result==$func_stripname_result
@@ -3625,7 +3625,7 @@ main (int argc, char *argv[])
   if (STREQ (argv[i], dumpscript_opt))
{
 EOF
-   case $host in
+   case $host in
  *mingw* | *cygwin* )
# make stdout use unix line endings
echo   setmode(1,_O_BINARY);
@@ -5796,7 +5796,7 @@ func_mode_link ()
  if test -z $libdir  test $linkmode = prog; then
func_fatal_error only libraries may -dlpreopen a convenience 
library: \`$lib'
  fi
- case $host in
+ case $host in
# special handling for platforms with PE-DLLs.
*cygwin* | *mingw* | *cegcc* )
  # Linker will automatically link against shared library if both
@@ -5896,7 +5896,7 @@ func_mode_link ()
# We need to hardcode the library path
if test -n $shlibpath_var  test -z $avoidtemprpath ; then
  # Make sure the rpath contains only unique directories.
- case $temp_rpath: in
+ case $temp_rpath: in
  *$absdir:*) ;;
  *) func_append temp_rpath $absdir: ;;
  esac
@@ -8765,7 +8765,7 @@ func_mode_uninstall ()
  done
  test -n $old_library  func_append rmfiles  $odir/$old_library
 
- case $opt_mode in
+ case $opt_mode in
  clean)
case  $library_names  in
* $dlname *) ;;
diff --git a/cfg.mk b/cfg.mk
index 6a1748c..4bc32a7 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -60,6 +60,14 @@ sc_trailing_blank-non-rfc3676:
halt='found trailing blank(s)'  \
  $(_sc_search_regexp)
 
+# Avoid useless quotes around case arguments such as:
+#   case $foo in ...
+exclude_file_name_regexp--sc_useless_quotes_in_case = ^cfg.mk$$
+sc_useless_quotes_in_case:
+   @prohibit='case [^  ]*[   ][  ]*in'  \
+   halt='found spurious quotes around case argument'   \
+ $(_sc_search_regexp)
+
 # List syntax-check exempted files.
 exclude_file_name_regexp--sc_bindtextdomain = ^tests/.*demo[0-9]*/.*\.c$$
 exclude_file_name_regexp--sc_error_message_uppercase = \
diff --git a/m4/libtool.m4 b/m4/libtool.m4
index a9e20cf..ec00e81 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -1198,7 +1198,7 @@ 

Re: [PATCH 1/7] syntax-check: fix violations and implement sc_useless_quotes_in_case.

2011-11-21 Thread Eric Blake
On 11/21/2011 07:47 AM, Gary V. Vaughan wrote:
 Contrary to popular belief, Bourne shell does not resplit case
 expressions after expansion, so if there are no shell unquoted
 shell metacharacters or whitespace, the quotes are useless.
 @@ -568,7 +568,7 @@ func_resolve_sysroot ()
  # store the result into func_replace_sysroot_result.
  func_replace_sysroot ()
  {
 -  case $lt_sysroot:$1 in
 +  case $lt_sysroot:$1 in
?*:$lt_sysroot*)

Likewise in the pattern expression; you could further change this to:

case $lt_sysroot:$1 in
  ?*:$lt_sysroot*)

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature