Paul Eggert wrote: > > - or the bash maintainers to make 'expr' and 'sed' shell built-ins, > > like 'test' and 'printf' are? > > I think it unlikely that either would happen; neither sounds all that > practical.
Why not? 'expr' and 'sed' could ship its code in the form of shared libraries that bash could dlopen(). > It's that expr is so buggy on many > platforms. Sometimes we have to use expr, but it's better to avoid it > when possible. OK. > How about something like this instead? Perhaps it's not quite as > pretty, but it's equally easy to understand (at least for me). > > case $gl_cv_func_printf_sizes_c99 in *yes) > case $gl_cv_func_printf_directive_a in *yes) > case $gl_cv_func_printf_directive_n in *yes) > case $gl_cv_func_printf_positions in *yes) > case $gl_cv_func_snprintf_truncation_c99 in *yes) > case $gl_cv_func_snprintf_retval_c99 in *yes) > case $gl_cv_func_snprintf_directive_n in *yes) > # snprintf exists and is already POSIX compliant. > gl_cv_func_snprintf_posix=yes;; > esac;; > esac;; > esac;; > esac;; > esac;; > esac;; > esac I agree, this is easy to understand as well. I've committed this: 2007-03-08 Bruno Haible <[EMAIL PROTECTED]> * m4/snprintf-posix.m4 (gl_FUNC_SNPRINTF_POSIX): Use 'case' statements instead of 'expr' invocations. * m4/sprintf-posix.m4 (gl_FUNC_SPRINTF_POSIX): Likewise. * m4/vasnprintf-posix.m4 (gl_FUNC_VASNPRINTF_POSIX): Likewise. * m4/vasprintf-posix.m4 (gl_FUNC_VASPRINTF_POSIX): Likewise. * m4/vsnprintf-posix.m4 (gl_FUNC_VSNPRINTF_POSIX): Likewise. * m4/vsprintf-posix.m4 (gl_FUNC_VSPRINTF_POSIX): Likewise. Suggested by Paul Eggert. *** m4/snprintf-posix.m4 7 Mar 2007 01:59:05 -0000 1.1 --- m4/snprintf-posix.m4 9 Mar 2007 01:19:48 -0000 *************** *** 17,32 **** gl_SNPRINTF_TRUNCATION_C99 gl_SNPRINTF_RETVAL_C99 gl_SNPRINTF_DIRECTIVE_N ! if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_snprintf_truncation_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_snprintf_retval_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_snprintf_directive_n" : ".*yes" > /dev/null; then ! # snprintf exists and is already POSIX compliant. ! gl_cv_func_snprintf_posix=yes ! fi fi if test $gl_cv_func_snprintf_posix = no; then if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then --- 17,53 ---- gl_SNPRINTF_TRUNCATION_C99 gl_SNPRINTF_RETVAL_C99 gl_SNPRINTF_DIRECTIVE_N ! case "$gl_cv_func_printf_sizes_c99" in ! *yes) ! case "$gl_cv_func_printf_directive_a" in ! *yes) ! case "$gl_cv_func_printf_directive_n" in ! *yes) ! case "$gl_cv_func_printf_positions" in ! *yes) ! case "$gl_cv_func_snprintf_truncation_c99" in ! *yes) ! case "$gl_cv_func_snprintf_retval_c99" in ! *yes) ! case "$gl_cv_func_snprintf_directive_n" in ! *yes) ! # snprintf exists and is already POSIX ! # compliant. ! gl_cv_func_snprintf_posix=yes ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac fi if test $gl_cv_func_snprintf_posix = no; then if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then *** m4/sprintf-posix.m4 7 Mar 2007 03:47:50 -0000 1.1 --- m4/sprintf-posix.m4 9 Mar 2007 01:19:48 -0000 *************** *** 11,22 **** AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) ! if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null; then ! : # sprintf exists and is already POSIX compliant. ! else if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, [Define if the vasnprintf implementation needs special code for --- 11,36 ---- AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) ! gl_cv_func_sprintf_posix=no ! case "$gl_cv_func_printf_sizes_c99" in ! *yes) ! case "$gl_cv_func_printf_directive_a" in ! *yes) ! case "$gl_cv_func_printf_directive_n" in ! *yes) ! case "$gl_cv_func_printf_positions" in ! *yes) ! # sprintf exists and is already POSIX compliant. ! gl_cv_func_sprintf_posix=yes ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! if test $gl_cv_func_sprintf_posix = no; then if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, [Define if the vasnprintf implementation needs special code for *** m4/vasnprintf-posix.m4 7 Mar 2007 01:34:55 -0000 1.4 --- m4/vasnprintf-posix.m4 9 Mar 2007 01:19:48 -0000 *************** *** 11,24 **** AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) AC_CHECK_FUNCS_ONCE([vasnprintf]) ! if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null \ ! && test $ac_cv_func_vasnprintf = yes; then ! : # vasnprintf exists and is already POSIX compliant. ! else if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, [Define if the vasnprintf implementation needs special code for --- 11,39 ---- AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + gl_cv_func_vasnprintf_posix=no AC_CHECK_FUNCS_ONCE([vasnprintf]) ! case "$gl_cv_func_printf_sizes_c99" in ! *yes) ! case "$gl_cv_func_printf_directive_a" in ! *yes) ! case "$gl_cv_func_printf_directive_n" in ! *yes) ! case "$gl_cv_func_printf_positions" in ! *yes) ! if test $ac_cv_func_vasnprintf = yes; then ! # vasnprintf exists and is already POSIX compliant. ! gl_cv_func_vasnprintf_posix=yes ! fi ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! if test $gl_cv_func_vasnprintf_posix = no; then if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, [Define if the vasnprintf implementation needs special code for *** m4/vasprintf-posix.m4 7 Mar 2007 01:34:55 -0000 1.2 --- m4/vasprintf-posix.m4 9 Mar 2007 01:19:48 -0000 *************** *** 11,24 **** AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) AC_CHECK_FUNCS([vasprintf]) ! if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null \ ! && test $ac_cv_func_vasprintf = yes; then ! : # vasprintf exists and is already POSIX compliant. ! else if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, [Define if the vasnprintf implementation needs special code for --- 11,39 ---- AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + gl_cv_func_vasprintf_posix=no AC_CHECK_FUNCS([vasprintf]) ! case "$gl_cv_func_printf_sizes_c99" in ! *yes) ! case "$gl_cv_func_printf_directive_a" in ! *yes) ! case "$gl_cv_func_printf_directive_n" in ! *yes) ! case "$gl_cv_func_printf_positions" in ! *yes) ! if test $ac_cv_func_vasprintf = yes; then ! # vasprintf exists and is already POSIX compliant. ! gl_cv_func_vasprintf_posix=yes ! fi ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! if test $gl_cv_func_vasprintf_posix = no; then if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, [Define if the vasnprintf implementation needs special code for *** m4/vsnprintf-posix.m4 7 Mar 2007 01:51:44 -0000 1.1 --- m4/vsnprintf-posix.m4 9 Mar 2007 01:19:48 -0000 *************** *** 18,33 **** gl_SNPRINTF_TRUNCATION_C99 gl_SNPRINTF_RETVAL_C99 gl_SNPRINTF_DIRECTIVE_N ! if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_snprintf_truncation_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_snprintf_retval_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_snprintf_directive_n" : ".*yes" > /dev/null; then ! # vsnprintf exists and is already POSIX compliant. ! gl_cv_func_vsnprintf_posix=yes ! fi fi if test $gl_cv_func_vsnprintf_posix = no; then if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then --- 18,54 ---- gl_SNPRINTF_TRUNCATION_C99 gl_SNPRINTF_RETVAL_C99 gl_SNPRINTF_DIRECTIVE_N ! case "$gl_cv_func_printf_sizes_c99" in ! *yes) ! case "$gl_cv_func_printf_directive_a" in ! *yes) ! case "$gl_cv_func_printf_directive_n" in ! *yes) ! case "$gl_cv_func_printf_positions" in ! *yes) ! case "$gl_cv_func_snprintf_truncation_c99" in ! *yes) ! case "$gl_cv_func_snprintf_retval_c99" in ! *yes) ! case "$gl_cv_func_snprintf_directive_n" in ! *yes) ! # vsnprintf exists and is already POSIX ! # compliant. ! gl_cv_func_vsnprintf_posix=yes ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac fi if test $gl_cv_func_vsnprintf_posix = no; then if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then *** m4/vsprintf-posix.m4 7 Mar 2007 03:27:10 -0000 1.1 --- m4/vsprintf-posix.m4 9 Mar 2007 01:19:48 -0000 *************** *** 11,22 **** AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) ! if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \ ! && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null; then ! : # vsprintf exists and is already POSIX compliant. ! else if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, [Define if the vasnprintf implementation needs special code for --- 11,36 ---- AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) ! gl_cv_func_vsprintf_posix=no ! case "$gl_cv_func_printf_sizes_c99" in ! *yes) ! case "$gl_cv_func_printf_directive_a" in ! *yes) ! case "$gl_cv_func_printf_directive_n" in ! *yes) ! case "$gl_cv_func_printf_positions" in ! *yes) ! # vsprintf exists and is already POSIX compliant. ! gl_cv_func_vsprintf_posix=yes ! ;; ! esac ! ;; ! esac ! ;; ! esac ! ;; ! esac ! if test $gl_cv_func_vsprintf_posix = no; then if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, [Define if the vasnprintf implementation needs special code for