Date: Sun, 18 Nov 2001 01:47:39 +0200 From: Sheldon Hearn <sheldonh@starjuice.net> To: Akinori MUSHA <knu@FreeBSD.org> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/share/man/man1 builtin.1 src/bin/sh Makefile builtins.def sh.1 src/bin/test test.1 test.c Message-ID: <99546.1006040859@axl.seasidesoftware.co.za> In-Reply-To: Your message of "Sat, 17 Nov 2001 11:10:11 PST." <200111171910.fAHJABJ92986@freefall.freebsd.org>
index | next in thread | previous in thread | raw e-mail
On Sat, 17 Nov 2001 11:10:11 PST, Akinori MUSHA wrote:
> I don't drop the printf builtin while I'm here because some /etc/rc.*
> scripts seem to use it before mounting /usr where printf(1) resides.
The only place seems to be in rc.network6 (although a simple grep shows
lots of false hits elsewhere in embedded awk(1) scripts).
ipv4_in_hexformat=`printf "%x:%x\n" \
$(($1*256 + $2)) $(($3*256 + $4))`
Using the hexprint function given below, the above fragment would be
rewritten as follows (with extra variables required only for the
purposes of sane indentation):
hexfrag1=`hexprint $(($1*256 + $2))`
hexfrag2=`hexprint $(($3*256 + $4))`
ipv4_in_hexformat="${hexfrag1}:${hexfrag2}"
Of course, this only makes sense with test(1) as a builtin, since you're
replacing a single call to printf(1) with multiple calls to test(1).
Ciao,
Sheldon.
hexdig () {
if [ $1 -lt 10 ]; then
echo $1
else
case $1 in
10) echo a ;;
11) echo b ;;
12) echo c ;;
13) echo d ;;
14) echo e ;;
15) echo f ;;
esac
fi
}
hexprint () {
val=$1
str=''
dig=`hexdig $((${val} & 15))`
str=${dig}${str}
val=$((${val} >> 4))
while [ ${val} -gt 0 ]; do
dig=`hexdig $((${val} & 15))`
str=${dig}${str}
val=$((${val} >> 4))
done
echo ${str}
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?99546.1006040859>
