From owner-cvs-all Sat Nov 17 15:46:30 2001 Delivered-To: cvs-all@freebsd.org Received: from axl.seasidesoftware.co.za (axl.seasidesoftware.co.za [196.31.7.201]) by hub.freebsd.org (Postfix) with ESMTP id 1B29837B416; Sat, 17 Nov 2001 15:46:23 -0800 (PST) Received: from sheldonh (helo=axl.seasidesoftware.co.za) by axl.seasidesoftware.co.za with local-esmtp (Exim 3.33 #1) id 165FBT-000Ptb-00; Sun, 18 Nov 2001 01:47:39 +0200 From: Sheldon Hearn To: Akinori MUSHA 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 In-reply-to: Your message of "Sat, 17 Nov 2001 11:10:11 PST." <200111171910.fAHJABJ92986@freefall.freebsd.org> Date: Sun, 18 Nov 2001 01:47:39 +0200 Message-ID: <99546.1006040859@axl.seasidesoftware.co.za> Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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