[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AS_CASE [was: AS_IF whitespace cleanup]
From: |
Eric Blake |
Subject: |
AS_CASE [was: AS_IF whitespace cleanup] |
Date: |
Thu, 23 Oct 2008 06:12:47 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 10/21/2008 12:24 PM:
>
> Eric Blake (4):
> Allow AS_CASE in shell lists.
And here's a followup patch for AS_CASE, which makes it more robust in the
face of underquoting (as long as it's easy, we might as well be nice to
users in spite of their bugs).
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkkAaj8ACgkQ84KuGfSFAYDqSgCeN9mT4cZQPBmUI+5IVU4u9C4j
syIAn3wf6xHGoQjy+LRm70Xq1qZzaBUu
=/cPX
-----END PGP SIGNATURE-----
>From edd82b60cbf48f12067c36d0f92244704e7eeaf8 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 22 Oct 2008 14:24:02 -0600
Subject: [PATCH] Formatting tweak: balance () with m4sh case statements.
* lib/m4sugar/m4sh.m4 (_AS_DETECT_BETTER_SHELL)
(_AS_SHELL_SANITIZE, _AS_ECHO_N_PREPARE, _AS_ECHO_PREPARE)
(AS_SET_CATFILE, _AS_TEST_PREPARE): Add strategic shell comments.
(_AS_CASE, _AS_CASE_DEFAULT, AS_CASE): Rearrange newlines, to
allow output of strategic shell comments.
(AS_VERSION_COMPARE): Use AS_CASE.
* tests/m4sh.at (AS@&address@hidden and AS@&address@hidden): Enhance test.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 11 +++++++++++
lib/m4sugar/m4sh.m4 | 49 +++++++++++++++++++++++++------------------------
tests/m4sh.at | 5 ++++-
3 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bdc3244..df85fbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-10-23 Eric Blake <address@hidden>
+
+ Formatting tweak: balance () with m4sh case statements.
+ * lib/m4sugar/m4sh.m4 (_AS_DETECT_BETTER_SHELL)
+ (_AS_SHELL_SANITIZE, _AS_ECHO_N_PREPARE, _AS_ECHO_PREPARE)
+ (AS_SET_CATFILE, _AS_TEST_PREPARE): Add strategic shell comments.
+ (_AS_CASE, _AS_CASE_DEFAULT, AS_CASE): Rearrange newlines, to
+ allow output of strategic shell comments.
+ (AS_VERSION_COMPARE): Use AS_CASE.
+ * tests/m4sh.at (AS@&address@hidden and AS@&address@hidden): Enhance
test.
+
2008-10-22 Paolo Bonzini <address@hidden>
and Eric Blake <address@hidden>
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index c2c4afd..09fbee6 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -209,7 +209,7 @@ dnl Remove any tests from suggested that are also required
[],
[as_candidate_shells=
_AS_PATH_WALK([/bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH],
- [case $as_dir in
+ [case $as_dir in @%:@(
/*)
for as_base in sh bash ksh sh5; do
as_candidate_shells="$as_candidate_shells $as_dir/$as_base"
@@ -423,7 +423,7 @@ _AS_PATH_SEPARATOR_PREPARE
IFS=" "" $as_nl"
# Find who we are. Look in the path if we contain no directory separator.
-case $[0] in
+case $[0] in @%:@((
*[[\\/]]* ) as_myself=$[0] ;;
*) _AS_PATH_WALK([],
[test -r "$as_dir/$[0]" && as_myself=$as_dir/$[0] && break])
@@ -486,20 +486,22 @@ _AS_UNSET_PREPARE
# AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT])
# ----------------------------------------------------
# Expand into
-# | case WORD in
-# | PATTERN1) IF-MATCHED1 ;;
-# | ...
-# | *) DEFAULT ;;
+# | case WORD in #(
+# | PATTERN1) IF-MATCHED1 ;; #(
+# | ...
+# | *) DEFAULT ;;
# | esac
+# The shell comments are intentional, to work around people who don't
+# realize the impacts of using insufficient m4 quoting.
m4_define([_AS_CASE],
-[ $1[)] m4_default([$2], [:]) ;;
-])
+[ address@hidden:@(]
+ $1[)] $2 ;;])
m4_define([_AS_CASE_DEFAULT],
-[ *[)] $1 ;;
-])
+[ address@hidden:@(]
+ *[)] $1 ;;])
+
m4_defun([AS_CASE],
-[case $1 in
-m4_map_args_pair([_$0], [_$0_DEFAULT], m4_shift($@))dnl
+[case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT], m4_shift($@))
esac])# AS_CASE
@@ -664,7 +666,7 @@ _AS_ECHO([$as_me:${as_lineno-$LINENO}: $1],
[AS_MESSAGE_LOG_FD])])
# failed there is also a newline to match.
m4_defun([_AS_ECHO_N_PREPARE],
[ECHO_C= ECHO_N= ECHO_T=
-case `echo -n x` in
+case `echo -n x` in @%:@((((
-n*)
case `echo 'x\c'` in
*c*) ECHO_T=' ';; # ECHO_T is single tab character.
@@ -881,7 +883,7 @@ else
as_echo_body='eval expr "X$][1" : "X\\(.*\\)"'
as_echo_n_body='eval
arg=$][1;
- case $arg in
+ case $arg in @%:@(
*"$as_nl"*)
expr "X$arg" : "X\\(.*\\)$as_nl";
arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
@@ -1154,10 +1156,10 @@ IFS=$as_save_IFS
# Set VAR to DIR-NAME/FILE-NAME.
# Optimize the common case where $2 or $3 is '.'.
m4_define([AS_SET_CATFILE],
-[case $2 in
+[case $2 in @%:@((
.) $1=$3;;
*)
- case $3 in
+ case $3 in @%:@(((
.) $1=$2;;
[[\\/]]* | ?:[[\\/]]* ) $1=$3;;
*) $1=$2/$3;;
@@ -1192,10 +1194,10 @@ else
if test -d "$[]1"; then
test -d "$[]1/.";
else
- case $[]1 in
+ case $[]1 in @%:@(
-*)set "./$[]1";;
esac;
- case `ls -ld'$as_ls_L_option' "$[]1" 2>/dev/null` in
+ case `ls -ld'$as_ls_L_option' "$[]1" 2>/dev/null` in @%:@((
???[[sx]]*):;;*)false;;esac;fi
'\'' sh
'
@@ -1512,12 +1514,11 @@ as_arg_v2=$2
dnl This usage is portable even to ancient awk,
dnl so don't worry about finding a "nice" awk version.
awk "$as_awk_strverscmp" v1="$as_arg_v1" v2="$as_arg_v2" /dev/null
-case $? in
-1) $3;;
-0) $4;;
-2) $5;;
-esac[]dnl
-])# _AS_VERSION_COMPARE
+AS_CASE([$?],
+ [1], [$3],
+ [0], [$4],
+ [2], [$5])[]dnl
+])# AS_VERSION_COMPARE
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 49c2b7e..badc668 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -799,7 +799,7 @@ AS_CASE([foo],
[foo], [echo ten],
[*], [echo wrong])
-# check for nesting, lists, and side effects
+# check for nesting, lists, and side effects, and quoting robustness
empty=
AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
rm -f file
@@ -807,6 +807,8 @@ AS_IF([touch file; false]) && echo thirteen
test -f file && echo fourteen
rm -f file
AS_CASE([`touch file; false`]) && test -f file && echo fifteen
+dnl The next line is badly underquoted; don't intentionally copy this style.
+AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
# check that require works correctly
m4_for([n], 1, 9, [],
@@ -858,6 +860,7 @@ twelve
thirteen
fourteen
fifteen
+sixteen
foo1=1 bar1=1
foo2=2 bar2=
foo3=3 bar3=
--
1.6.0.2