2008-10-27 Eric Blake <ebb9@byu.net>
+ Use AS_VAR_ARITH.
+ * lib/autotest/general.m4 (at_func_arith): Delete; replace all
+ clients with AS_VAR_ARITH instead.
+ * lib/autoconf/general.m4 (_AC_COMPUTE_INT_COMPILE): Use new
+ macro.
+ * lib/autoconf/programs.m4 (_AC_FEATURE_CHECK_LENGTH): Likewise.
+ * tests/torture.at (Torturing config.status): Likewise.
+ * tests/tools.at (autom4te --force): Likewise.
+
Add AS_VAR_ARITH.
* lib/m4sugar/m4sh.m4 (_AS_VAR_ARITH_PREPARE, _AS_VAR_ARITH_WORKS)
(AS_VAR_ARITH): New macros.
while :; do
_AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_mid])],
[ac_hi=$ac_mid; break],
- [ac_lo=`expr $ac_mid + 1`
+ [AS_VAR_ARITH([ac_lo], [$ac_mid + 1])
if test $ac_lo -le $ac_mid; then
ac_lo= ac_hi=
break
fi
- ac_mid=`expr 2 '*' $ac_mid + 1`])
+ AS_VAR_ARITH([ac_mid], [2 '*' $ac_mid + 1])])
done],
[AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) < 0])],
[ac_hi=-1 ac_mid=-1
while :; do
_AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= $ac_mid])],
[ac_lo=$ac_mid; break],
- [ac_hi=`expr '(' $ac_mid ')' - 1`
+ [AS_VAR_ARITH([ac_hi], ['(' $ac_mid ')' - 1])
if test $ac_mid -le $ac_hi; then
ac_lo= ac_hi=
break
fi
- ac_mid=`expr 2 '*' $ac_mid`])
+ AS_VAR_ARITH([ac_mid], [2 '*' $ac_mid])])
done],
[ac_lo= ac_hi=])])
# Binary search between lo and hi bounds.
while test "x$ac_lo" != "x$ac_hi"; do
- ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
+ AS_VAR_ARITH([ac_mid], ['(' $ac_hi - $ac_lo ')' / 2 + $ac_lo])
_AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_mid])],
- [ac_hi=$ac_mid], [ac_lo=`expr '(' $ac_mid ')' + 1`])
+ [ac_hi=$ac_mid],
+ [AS_VAR_ARITH([ac_lo], ['(' $ac_mid ')' + 1])])
done
case $ac_lo in @%:@((
?*) AS_VAR_SET([$2], [$ac_lo]); $4 ;;
AS_ECHO(['$4']) >> "conftest.nl"
$3 < "conftest.nl" >"conftest.out" 2>/dev/null || break
diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
- ac_count=`expr $ac_count + 1`
+ AS_VAR_ARITH([ac_count], [$ac_count + 1])
if test $ac_count -gt ${$1_max-0}; then
# Best one so far, save it but keep looking for a better one
$2="$$1"
chmod +x "$at_group_dir/run"
}
-AS_FUNCTION_DESCRIBE([at_func_arith], [ARG...],
-[Arithmetic evaluation, avoids expr if the shell is sane. The
-interpretation of leading zeroes is unspecified.])
-#
-# subshell and eval are needed to keep Solaris sh from bailing out:
-if ( eval 'test $(( 1 + 1 )) = 2' ) 2>/dev/null; then
- [#] With "$[@]", bash does not split positional parameters:
- eval 'at_func_arith ()
- {
- at_func_arith_result=$(( $[*] ))
- }'
-else
- at_func_arith ()
- {
- at_func_arith_result=`expr "$[@]"`
- }
-fi
-
m4_text_box([End of autotest shell functions.])
m4_divert_pop([PREPARE_TESTS])dnl back to DEFAULTS
fi
case $at_value in
0*) # We want to treat leading 0 as decimal, like expr and test, but
- # at_func_arith treats it as octal if it uses $(( )).
+ # AS_VAR_ARITH treats it as octal if it uses $(( )).
# With XSI shells, ${at_value#${at_value%%[1-9]*}} avoids the
# expr fork, but it is not worth the effort to determine if the
# shell supports XSI when the user can just avoid leading 0.
set X $at_fail_list; shift; at_fail_count=$[@%:@]; at_fail_list=$[*]
set X $at_skip_list; shift; at_skip_count=$[@%:@]
-at_func_arith $at_group_count - $at_skip_count
-at_run_count=$at_func_arith_result
-at_func_arith $at_xpass_count + $at_fail_count
-at_unexpected_count=$at_func_arith_result
-at_func_arith $at_xfail_count + $at_fail_count
-at_total_fail_count=$at_func_arith_result
+AS_VAR_ARITH([at_run_count], [$at_group_count - $at_skip_count])
+AS_VAR_ARITH([at_unexpected_count], [$at_xpass_count + $at_fail_count])
+AS_VAR_ARITH([at_total_fail_count], [$at_xfail_count + $at_fail_count])
# Back to the top directory.
cd "$at_dir"
AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
case $at_start_time,$at_stop_time in
[[0-9]*,[0-9]*])
- at_func_arith $at_stop_time - $at_start_time
- at_duration_s=$at_func_arith_result
- at_func_arith $at_duration_s / 60
- at_duration_m=$at_func_arith_result
- at_func_arith $at_duration_m / 60
- at_duration_h=$at_func_arith_result
- at_func_arith $at_duration_s % 60
- at_duration_s=$at_func_arith_result
- at_func_arith $at_duration_m % 60
- at_duration_m=$at_func_arith_result
+ AS_VAR_ARITH([at_duration_s], [$at_stop_time - $at_start_time])
+ AS_VAR_ARITH([at_duration_m], [$at_duration_s / 60])
+ AS_VAR_ARITH([at_duration_h], [$at_duration_m / 60])
+ AS_VAR_ARITH([at_duration_s], [$at_duration_s % 60])
+ AS_VAR_ARITH([at_duration_m], [$at_duration_m % 60])
at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
;;
# This macro does not expand to a single shell command, so be careful
# when using it. Surrounding the body of this macro with {} would
# cause "bash -c '_ASLINENO_WORKS'" to fail (with Bash 2.05, anyway),
-# but that bug is irrelevant to our use of LINENO.
+# but that bug is irrelevant to our use of LINENO. We can't use
+# AS_VAR_ARITH, as this is expanded prior to shell functions.
m4_define([_AS_LINENO_WORKS],
[
as_lineno_1=$LINENO
# even on slow machines.
echo BAD >file
this_year=`TZ=UTC0 date +%Y`
-TZ=UTC0 touch -t `expr $this_year + 1`01010001 file
+AS_VAR_ARITH([next_year], [$this_year + 1])
+TZ=UTC0 touch -t ${next_year}01010001 file
AT_CHECK_AUTOM4TE([--force -o file file.m4])
AT_CHECK([cat file], 0,
i=1
while test $i != 101; do
echo "content of file $i" > file_$i
- i=`expr $i + 1`
+ AS_VAR_ARITH([i], [$i + 1])
done