make shell math operations style more succulent

Convert the style:
	var=$((${var} + 1))
to:
	: $(( var += 1 ))

The latter is easier to read imo.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
This commit is contained in:
Mike Frysinger 2011-11-10 21:46:08 -05:00
parent 0510c473d4
commit ef1ff1b4f2
32 changed files with 98 additions and 98 deletions

View File

@ -49,7 +49,7 @@ start()
retval=1
break
fi
x=$(($x + 1))
: $(( x += 1 ))
done
eend $retval

View File

@ -85,7 +85,7 @@ start()
if [ -e /etc/adjtime ] && yesno $clock_adjfile; then
_hwclock --adjust $utc_cmd
retval=$(($retval + $?))
: $(( retval += $? ))
fi
# If setting UTC, don't bother to run hwclock when first booting
@ -99,7 +99,7 @@ start()
else
_hwclock --systz $utc_cmd $clock_args
fi
retval=$(($retval + $?))
: $(( retval += $? ))
fi
eend $retval "Failed to set the system clock"

View File

@ -47,7 +47,7 @@ start()
n=1
while [ $n -le $ttyn ]; do
kbd_mode $kmode -C $ttydev$n
n=$(($n + 1))
: $(( n += 1 ))
done
eend 0

View File

@ -21,7 +21,7 @@ restore()
mixer -f "$mixer" \
$(cat "/var/db/${mixer#/dev/}-state") >/dev/null
veend $?
: $((retval += $?))
: $(( retval += $? ))
fi
done
}
@ -40,7 +40,7 @@ stop()
vebegin "$mixer"
mixer -f "$mixer" -s >/var/db/"${mixer#/dev/}"-state
veend $?
: $((retval += $?))
: $(( retval += $? ))
done
eoutdent
eend $retval

View File

@ -57,7 +57,7 @@ start()
[ -z "$args" ] && eval args=\$module_${aa}_args
[ -z "$args" ] && eval args=\$module_${xx}_args
eval modprobe -q "$mpargs" "$x" "$args"
eend $? "Failed to load $x" && cnt=$(($cnt + 1))
eend $? "Failed to load $x" && : $(( cnt += 1 ))
done
einfo "Autoloaded $cnt module(s)"
}

View File

@ -54,7 +54,7 @@ start()
local ttyv=
for ttyv in /dev/ttyv*; do
vidcontrol < "$ttyv" -m on
: $((retval+= $?))
: $(( retval += $? ))
done
fi

View File

@ -115,7 +115,7 @@ _wait_for_carrier()
eend 0
return 0
fi
timeout=$((${timeout} - 1))
: $(( timeout -= 1 ))
[ "${efunc}" = "einfon" ] && printf "."
done
@ -144,9 +144,9 @@ _netmask2cidr()
local i= len=
local IFS=.
for i in $1; do
while [ ${i} != "0" ]; do
len=$((${len} + ${i} % 2))
i=$((${i} >> 1))
while [ i -ne 0 ]; do
: $(( len += i % 2 ))
: $(( i >>= 1 ))
done
done
@ -277,7 +277,7 @@ _gen_module_list()
echo "module_${i}_program_start='${PROGRAM_START}'" >> "${MODULESLIST}"
echo "module_${i}_program_stop='${PROGRAM_STOP}'" >> "${MODULESLIST}"
echo "module_${i}_provide='${PROVIDE}'" >> "${MODULESLIST}"
i=$((${i} + 1))
: $(( i += 1 ))
done
echo "module_${i}=" >> "${MODULESLIST}"
)
@ -304,7 +304,7 @@ _load_modules()
local i=-1 x= mod= f= provides=
while true; do
i=$((${i} + 1))
: $(( i += 1 ))
eval mod=\$module_${i}
[ -z "${mod}" ] && break
[ -e "${MODULESDIR}/${mod}.sh" ] || continue
@ -438,7 +438,7 @@ _load_config()
# so modules can influence it
for cmd; do
eval config_${config_index}="'${cmd}'"
config_index=$((${config_index} + 1))
: $(( config_index += 1 ))
done
# Terminate the list
eval config_${config_index}=
@ -446,7 +446,7 @@ _load_config()
config_index=0
for cmd in ${fallback}; do
eval fallback_${config_index}="'${cmd}'"
config_index=$((${config_index} + 1))
: $(( config_index += 1 ))
done
# Terminate the list
eval fallback_${config_index}=
@ -541,7 +541,7 @@ start()
if [ -n "${our_metric}" ]; then
metric=${our_metric}
elif [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then
metric=$((${metric} + $(_ifindex)))
: $(( metric += $(_ifindex) ))
fi
while true; do
@ -581,11 +581,11 @@ start()
eindent
eval config_${config_index}=\$config
unset fallback_${config_index}
config_index=$((${config_index} - 1))
: $(( config_index -= 1 ))
fi
fi
eoutdent
config_index=$((${config_index} + 1))
: $(( config_index += 1 ))
done
if ! ${oneworked}; then

View File

@ -287,7 +287,7 @@ start()
tentative || break
[ $r = 5 ] && vebegin "Waiting for tentative addresses"
sleep 1
r=$(($r - 1))
: $(( r -= 1 ))
done
if [ $r != 5 ]; then
[ $r != 0 ]

View File

@ -21,7 +21,7 @@ _setleds()
while [ $i -le $ttyn ]; do
setleds -D "$1"num < $dev$i || retval=1
i=$(($i + 1))
: $(( i += 1 ))
done
return $retval

View File

@ -33,7 +33,7 @@ start()
# Good to go!
"$svc" start && started="$started $svc"
: $((retval += $?))
: $(( retval += $? ))
done
service_set_value started "$started"
eend $retval "Some local rc services failed to start"
@ -46,7 +46,7 @@ stop()
local svc= retval=0
for svc in $(rcorder $(service_get_value started) 2>/dev/null | sort -r); do
"$svc" stop
: $((retval += $?))
: $(( retval += $? ))
done
eend $retval "Some local rc services failed to stop"
return 0

View File

@ -31,7 +31,7 @@ start()
n=1
while [ ${n} -le "$ttyn" ]; do
printf "\033%s" "$termencoding" >$ttydev$n
n=$(($n + 1))
: $(( n += 1 ))
done
# Save the encoding for use immediately at boot

View File

@ -16,7 +16,7 @@ save_seed()
local psz=1
if [ -e /proc/sys/kernel/random/poolsize ]; then
psz=$(($(cat /proc/sys/kernel/random/poolsize) / 4096))
: $(( psz = $(cat /proc/sys/kernel/random/poolsize) / 4096 ))
fi
( # sub shell to prevent umask pollution

View File

@ -449,7 +449,7 @@ eat()
veinfo "Eating `basename ${food}`"
${command} --eat ${food}
retval=$?
: $((${result} += ${retval}))
: $(( result += retval ))
[ ${retval} = 0 ] && ate="${ate} `basename ${food}`"
done

View File

@ -26,20 +26,20 @@ apipa_start()
eindent
while [ ${i} -lt 64516 ]; do
i1=$((($(_random) % 255) + 1))
i2=$((($(_random) % 255) + 1))
: $(( i1 = (_random % 255) + 1 ))
: $(( i2 = (_random % 255) + 1 ))
addr="169.254.${i1}.${i2}"
vebegin "${addr}/16"
if ! arping_address "${addr}"; then
eval config_${config_index}="\"${addr}/16 broadcast 169.254.255.255\""
config_index=$((${config_index} - 1))
: $(( config_index -= 1 ))
veend 0
eoutdent
return 0
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
eerror "No free address found!"

View File

@ -34,7 +34,7 @@ arping_address()
while [ ${w} -gt 0 -a -z "${foundmac}" ]; do
foundmac="$(arping2 ${opts} -r -c 1 -i "${IFACE}" "${ip}" 2>/dev/null | \
sed -e 'y/abcdef/ABCDEF/')"
w=$((${w} - 1))
: $(( w -= 1 ))
done
else
[ -z "$(_get_inet_address)" ] && opts="${opts} -D"

View File

@ -148,7 +148,7 @@ clip_post_start()
local nleftretries=10 emsg= ecode=
while [ ${nleftretries} -gt 0 ]; do
nleftretries=$((${nleftretries} - 1))
: $(( nleftretries -= 1 ))
emsg="$(atmarp -s "${peerip}" "${ifvpivci}" "$@" 2>&1)"
ecode=$? && break
sleep 2

View File

@ -38,7 +38,7 @@ _ifindex()
echo "${x#/dev/net}"
return 0
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
;;
default)
@ -47,7 +47,7 @@ _ifindex()
echo "${i}"
return 0
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
;;
esac

View File

@ -26,7 +26,7 @@ _ifindex()
{
local line= i=-2
while read line; do
i=$((${i} + 1))
: $(( i += 1 ))
[ ${i} -lt 1 ] && continue
case "${line}" in
"${IFACE}:"*) echo "${i}"; return 0;;
@ -34,7 +34,7 @@ _ifindex()
done < /proc/net/dev
# Return the next available index
i=$((${i} + 1))
: $(( i += 1 ))
echo "${i}"
return 1
}
@ -96,7 +96,7 @@ _get_inet_addresses()
_exists || break
local addr="$(_get_inet_address)"
[ -n "${addr}" ] && addrs="${addrs}${addrs:+ }${addr}"
i=$((${i} + 1))
: $(( i += 1 ))
done
echo "${addrs}"
}
@ -106,26 +106,26 @@ _cidr2netmask()
local cidr="$1" netmask="" done=0 i=0 sum=0 cur=128
local octets= frac=
local octets=$((${cidr} / 8))
local frac=$((${cidr} % 8))
local octets=$(( cidr / 8 ))
local frac=$(( cidr % 8 ))
while [ ${octets} -gt 0 ]; do
netmask="${netmask}.255"
octets=$((${octets} - 1))
done=$((${done} + 1))
: $(( octets -= 1 ))
: $(( done += 1 ))
done
if [ ${done} -lt 4 ]; then
while [ ${i} -lt ${frac} ]; do
sum=$((${sum} + ${cur}))
cur=$((${cur} / 2))
i=$((${i} + 1))
: $(( sum += cur ))
: $(( cur /= 2 ))
: $(( i += 1 ))
done
netmask="${netmask}.${sum}"
done=$((${done} + 1))
: $(( done += 1 ))
while [ ${done} -lt 4 ]; do
netmask="${netmask}.0"
done=$((${done} + 1))
: $(( done += 1 ))
done
fi
@ -150,7 +150,7 @@ _add_address()
# Get the last alias made for the interface and add 1 to it
i=$(ifconfig | sed '1!G;h;$!d' | grep -m 1 -o "^${iface}:[0-9]*" \
| sed -n -e 's/'"${iface}"'://p')
i=$((${i:-0} + 1))
: $(( i = ${i:-0} + 1 ))
iface="${iface}:${i}"
fi

View File

@ -72,7 +72,7 @@ ifplugd_pre_start()
fi
sleep 1
[ ${timeout} -eq 0 ] && continue
i=$((${i} + 1))
: $(( i += 1 ))
[ ${i} -ge ${timeout} ] && break
done

View File

@ -51,7 +51,7 @@ ip6to4_start()
case "${ip}" in
172.${i}.*) break;;
esac
i=$((${i} + 1))
: $(( i += 1 ))
done
[ ${i} -lt 32 ] && continue
;;
@ -90,7 +90,7 @@ ip6to4_start()
# Now apply our config
eval config_${config_index}=\'"${new}"\'
config_index=$((${config_index} - 1))
: $(( config_index -= 1 ))
# Add a route for us, ensuring we don't delete anything else
local routes="$(_get_array "routes_${IFVAR}")

View File

@ -36,7 +36,7 @@ _ifindex()
{
local line= i=-2
while read line; do
i=$((${i} + 1))
: $(( i += 1 ))
[ ${i} -lt 1 ] && continue
case "${line}" in
"${IFACE}:"*) echo "${i}"; return 0;;
@ -44,7 +44,7 @@ _ifindex()
done < /proc/net/dev
# Return the next available index
i=$((${i} + 1))
: $(( i += 1 ))
echo "${i}"
return 1
}
@ -290,7 +290,7 @@ iproute2_post_start()
while [ $n -ge 0 ]; do
_iproute2_ipv6_tentative || break
sleep 1
n=$(($n - 1))
: $(( n -= 1 ))
done
[ $n -ge 0 ]
eend $?

View File

@ -218,7 +218,7 @@ iwconfig_associate()
sleep 1
[ ${timeout} -eq 0 ] && continue
i=$((${i} + 1))
: $(( i += 1 ))
[ ${i} -ge ${timeout} ] && { eend 1; return 1; }
done
@ -252,13 +252,13 @@ iwconfig_scan()
scan="$(LC_ALL=C ifconfig -v "${IFACE}" list scan 2>/dev/null | sed -e "1 d" -e "s/$/'/g" -e "s/^/'/g")"
while [ ${i} -lt 3 -a -z "${scan}" ] ; do
scan="${scan}${scan:+ }$(LC_ALL=C ifconfig -v "${IFACE}" scan 2>/dev/null | sed -e "1 d" -e "s/$/'/g" -e "s/^/'/g")"
i=$((${i} + 1))
: $(( i += 1 ))
done
APS=-1
eval set -- ${scan}
for line in "$@" ; do
APS=$((${APS} + 1))
: $(( APS += 1 ))
set -- ${line}
while true ; do
case "$1" in
@ -276,7 +276,7 @@ iwconfig_scan()
# Add 1000 for managed nodes as we prefer them to adhoc
set -- $*
case "$1" in
*E*) eval QUAL_${APS}=$((${quality} + 1000)) ;;
*E*) eval QUAL_${APS}=$(( quality + 1000 )) ;;
*) eval QUAL_${APS}=\$quality ;;
esac
done
@ -290,7 +290,7 @@ iwconfig_scan()
# Sort based on quality
local i=0 k=1 a= b= x= t=
while [ ${i} -lt ${APS} ] ; do
k=$((${i} + 1))
: $(( k = i + 1 ))
while [ ${k} -le ${APS} ] ; do
eval a=\$QUALITY_${i}
[ -z "${a}" ] && break
@ -302,15 +302,15 @@ iwconfig_scan()
eval ${x}_${k}=\$t
done
fi
k=$((${k} + 1))
: $(( k += 1 ))
done
i=$((${i} + 1))
: $(( i += 1 ))
done
# Strip any duplicates
local i=0 k=1 a= b=
while [ ${i} -lt ${APS} ] ; do
k=$((${i} + 1))
: $(( k = i + 1 ))
while [ ${k} -le ${APS} ] ; do
eval a=\$MAC_${i}
eval b=\$MAC_${k}
@ -327,9 +327,9 @@ iwconfig_scan()
unset MAC_${k} SSID_${k} CHAN_${k} QUALITY_${k} CAPS_${k}
fi
fi
k=$((${k} + 1))
: $(( k += 1 ))
done
i=$((${i} + 1))
: $(( i += 1 ))
done
local i=0 e= m= s=
@ -337,7 +337,7 @@ iwconfig_scan()
while [ ${i} -le ${APS} ] ; do
eval x=\$MAC_${i}
if [ -z "${x}" ] ; then
i=$((${i} + 1))
: $(( i += 1 ))
continue
fi
@ -374,7 +374,7 @@ iwconfig_scan()
unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} CAPS_${i}
fi
done
i=$((${i} + 1))
: $(( i += 1 ))
done
eoutdent
return 0
@ -396,7 +396,7 @@ iwconfig_force_preferred()
found_AP=true
break
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
if ! ${found_AP} ; then
SSID=${ssid}
@ -428,7 +428,7 @@ iwconfig_connect_preferred()
iwconfig_associate "${mac}" \
"${chan}" "${caps}" && return 0
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
done
@ -442,7 +442,7 @@ iwconfig_connect_not_preferred()
while [ ${i} -le ${APS} ] ; do
eval e=\$SSID_${i}
if [ -z "${e}" ] ; then
i=$((${i} + 1))
: $(( i += 1 ))
continue
fi
@ -465,7 +465,7 @@ iwconfig_connect_not_preferred()
iwconfig_associate "${mac}" \
"${chan}" "${caps}" && return 0
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
return 1

View File

@ -39,7 +39,7 @@ _get_ssid()
return 0
fi
sleep 1
i=$((${i} - 1))
: $(( i -= 1 ))
done
return 1
@ -229,7 +229,7 @@ iwconfig_wait_for_association()
sleep 1
[ ${timeout} -eq 0 ] && continue
i=$((${i} + 1))
: $(( i += 1 ))
[ ${i} -ge ${timeout} ] && return 1
done
return 1
@ -347,7 +347,7 @@ iwconfig_scan()
;;
esac
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
if [ -z "${scan}" ]; then
@ -377,7 +377,7 @@ iwconfig_scan()
for line; do
case "${line}" in
*Address:*)
APS=$((${APS} + 1))
: $(( APS += 1 ))
eval MAC_${APS}="\""$(echo "${line#*: }" | tr '[:lower:]' '[:upper:]')"\""
eval QUALITY_${APS}=0
;;
@ -427,7 +427,7 @@ iwconfig_scan()
# Sort based on quality
local i=0 k=1 a= b= x= t=
while [ ${i} -lt ${APS} ]; do
k=$((${i} + 1))
: $(( k = i + 1 ))
while [ ${k} -le ${APS} ]; do
eval a=\$QUALITY_${i}
[ -z "${a}" ] && break
@ -439,15 +439,15 @@ iwconfig_scan()
eval ${x}_${k}=\$t
done
fi
k=$((${k} + 1))
: $(( k += 1 ))
done
i=$((${i} + 1))
: $(( i += 1 ))
done
# Strip any duplicates
local i=0 k=1 a= b=
while [ ${i} -lt ${APS} ]; do
k=$((${i} + 1))
: $(( k = i + 1 ))
while [ ${k} -le ${APS} ]; do
eval a=\$MAC_${i}
eval b=\$MAC_${k}
@ -459,9 +459,9 @@ iwconfig_scan()
[ -n "${a}" -a -n "${b}" ] && [ "${a}" -lt "${b}" ] && u=${i}
unset MAC_${u} SSID_${u} MODE_${u} CHAN_${u} QUALITY_${u} ENC_${u}
fi
k=$((${k} + 1))
: $(( k += 1 ))
done
i=$((${i} + 1))
: $(( i += 1 ))
done
local i=0 e= m= s=
@ -469,7 +469,7 @@ iwconfig_scan()
while [ ${i} -le ${APS} ]; do
eval x=\$MAC_${i}
if [ -z "${x}" ]; then
i=$((${i} + 1))
: $(( i += 1 ))
continue
fi
@ -506,7 +506,7 @@ iwconfig_scan()
unset SSID_${i} MAC_${i} ${MODE}_${i} CHAN_${i} QUALITY_${i} ENC_${i}
fi
done
i=$((${i} + 1))
: $(( i += 1 ))
done
eoutdent
}
@ -526,7 +526,7 @@ iwconfig_force_preferred()
found_AP=true
break
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
if ! ${found_AP}; then
SSID=${ssid}
@ -559,7 +559,7 @@ iwconfig_connect_preferred()
iwconfig_associate "${mode}" "${mac}" "${enc}" "${freq}" \
"${chan}" && return 0
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
done
@ -593,7 +593,7 @@ iwconfig_connect_not_preferred()
"${chan}" && return 0
fi
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
return 1

View File

@ -74,7 +74,7 @@ netplugd_pre_start()
fi
sleep 1
[ ${timeout} -eq 0 ] && continue
i=$((${i} + 1))
: $(( i += 1 ))
[ ${i} -ge ${timeout} ] && break
done

View File

@ -96,7 +96,7 @@ pppd_pre_start()
if ! ${hasdefaultmetric}; then
local m=
eval m=\$metric_${IFVAR}
[ -z "${m}" ] && m=$((${metric} + $(_ifindex)))
[ -z "${m}" ] && : $(( m = metric + $(_ifindex) ))
opts="${opts} defaultmetric ${m}"
fi
if [ -n "${mtu}" ]; then

View File

@ -30,7 +30,7 @@ tuntap_pre_start()
local timeout=10
while [ ! -e /dev/net/tun -a ${timeout} -gt 0 ]; do
sleep 1
timeout=$((${timeout} - 1))
: $(( timeout -= 1 ))
done
if [ ! -e /dev/net/tun ]; then
eerror "TUN/TAP support present but /dev/net/tun is not"

View File

@ -34,7 +34,7 @@ _get_ssid()
return 0
fi
sleep 1
timeout=$((timeout - 1))
: $(( timeout -= 1 ))
done
return 1

View File

@ -8,14 +8,14 @@ RC_GOT_FUNCTIONS="yes"
eindent()
{
EINFO_INDENT=$((${EINFO_INDENT:-0} + 2))
: $(( EINFO_INDENT = ${EINFO_INDENT:-0} + 2 ))
[ "$EINFO_INDENT" -gt 40 ] && EINFO_INDENT=40
export EINFO_INDENT
}
eoutdent()
{
EINFO_INDENT=$((${EINFO_INDENT:-0} - 2))
: $(( EINFO_INDENT = ${EINFO_INDENT:-0} - 2 ))
[ "$EINFO_INDENT" -lt 0 ] && EINFO_INDENT=0
return 0
}

View File

@ -59,7 +59,7 @@ do_unmount()
eend 1
else
local sig="TERM"
retry=$(($retry - 1))
: $(( retry -= 1 ))
[ $retry = 1 ] && sig="KILL"
fuser $f_kill$sig -k $f_opts \
"$mnt" >/dev/null 2>&1

View File

@ -9,17 +9,17 @@ tret=0
ebegin "Testing yesno()"
for f in yes YES Yes true TRUE True 1 ; do
if ! yesno $f; then
tret=$(($tret + 1))
: $(( tret += 1 ))
echo "!$f!"
fi
done
for f in no NO No false FALSE False 0 ; do
if yesno $f; then
tret=$(($tret + 1))
: $(( tret += 1 ))
echo "!$f!"
fi
done
eend $tret
ret=$(($ret + $tret))
: $(( ret += $tret ))
exit $ret

View File

@ -15,7 +15,7 @@ checkit() {
echo "$@" | tr ' ' '\n' > ${base}.out
diff -u ${base}.list ${base}.out
eend $?
ret=$(($ret + $?))
: $(( ret += $? ))
}
ret=0
@ -65,7 +65,7 @@ readelf -Wr $(grep -l '#include[[:space:]]"librc\.h"' ${librc_srcdir}/*.c | sed
syms=$(diff -u librc.funcs.hidden.list librc.funcs.hidden.out | sed -n '/^+[^+]/s:^+::p')
[ -z "${syms}" ]
eend $? "Missing hidden defs:"$'\n'"${syms}"
ret=$(($ret + $?))
: $(( ret += $? ))
ebegin "Checking trailing whitespace in code"
# XXX: Should we check man pages too ?
@ -118,7 +118,7 @@ for u in units/*; do
ebegin "$(basename "${u}")"
./"${u}"
eend $?
ret=$(($ret + $?))
: $(( ret += $? ))
done
exit ${ret}

View File

@ -34,7 +34,7 @@ while true; do
elif [ "${opt}" != "${opt#dhcp-option DNS *}" ]; then
NS="${NS}nameserver ${opt#dhcp-option DNS *}\n"
fi
i=$((${i} + 1))
: $(( i += 1 ))
done
if [ -n "${NS}" ]; then