From d7921337d35fc9f5408e3b50992b0125e341efac Mon Sep 17 00:00:00 2001 From: Eric Blake 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@&t@_IF and AS@&t@_CASE): Enhance test. Signed-off-by: Eric Blake --- 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 e0f3f265..2f8cb50a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-10-23 Eric Blake + + 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@&t@_IF and AS@&t@_CASE): Enhance test. + 2008-10-22 Jim Meyering AC_FUNC_GETGROUPS: always define $ac_cv_func_getgroups_works diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index c2c4afd8..09fbee63 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], [:]) ;; -]) +[ [@%:@(] + $1[)] $2 ;;]) m4_define([_AS_CASE_DEFAULT], -[ *[)] $1 ;; -]) +[ [@%:@(] + *[)] $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 49c2b7e9..badc6681 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= -- 2.47.2