[PATCH] Use printf(1) builtin for hexprint function in etc/network.subr

Warner Losh imp at bsdimp.com
Mon May 9 17:21:35 UTC 2011


Missed that it is now a shell built-in.  N/m about my comments.

Warner

On May 8, 2011, at 6:37 AM, Jilles Tjoelker wrote:

> Now that printf(1) is a shell builtin, there is no need to emulate it
> anymore.
> 
> It may be faster to use printf directly but the function is useful for
> compatibility.
> 
> Index: etc/network.subr
> ===================================================================
> --- etc/network.subr	(revision 220966)
> +++ etc/network.subr	(working copy)
> @@ -1333,38 +1333,14 @@
> #	Echo decimal number $arg (single digit) in hexadecimal format.
> hexdigit()
> {
> -	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
> +	printf '%x\n' "$1"
> }
> 
> # hexprint arg
> #	Echo decimal number $arg (multiple digits) in hexadecimal format.
> hexprint()
> {
> -	local val str dig
> -	val=$1
> -	str=''
> -	dig=`hexdigit $((${val} & 15))`
> -	str=${dig}${str}
> -	val=$((${val} >> 4))
> -
> -	while [ ${val} -gt 0 ]; do
> -		dig=`hexdigit $((${val} & 15))`
> -		str=${dig}${str}
> -		val=$((${val} >> 4))
> -	done
> -
> -	echo ${str}
> +	printf '%x\n' "$1"
> }
> 
> is_wired_interface()
> 
> -- 
> Jilles Tjoelker
> _______________________________________________
> freebsd-rc at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-rc
> To unsubscribe, send any mail to "freebsd-rc-unsubscribe at freebsd.org"
> 
> 



More information about the freebsd-rc mailing list