Date: Wed, 19 Apr 2006 05:30:18 +1000 From: Peter Jeremy <peterjeremy@optushome.com.au> To: cokane@cokane.org Cc: freebsd-hackers@freebsd.org Subject: Re: [PATCH] Fancy rc startup style RFC Message-ID: <20060418193018.GB694@turion.vk2pj.dyndns.org> In-Reply-To: <346a80220604181102v3597a1edp3e05fa663b87e15c@mail.gmail.com> References: <444515C8.3030406@centtech.com> <20060418165709.GA17705@central.0xfce3.net> <44452532.40703@centtech.com> <20060418.114933.69380798.imp@bsdimp.com> <346a80220604181102v3597a1edp3e05fa663b87e15c@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 2006-Apr-18 14:02:07 -0400, Coleman Kane wrote: A few comments on the shellscript: >+ rcargsize=`echo $rc_arg` >+ rcargsize=${#rcargsize} Try rcargsize=$((${#rc_arg} + 1)) >- return 1 >+ (echo_fancy "FAILED" `expr 10 + $rcargsize - 1`) && return 1 Try echo_fancy "FAILED" $((10 + $rcargsize - 1)) && return 1 >+echo_fancy () { ... >+ namesize=`echo -n $name` >+ namesize=${#namesize} or namesize=${#name} >+ padding="" >+ paddingsize=$(($columns - 15 - $2 - $namesize)) >+ until [ 0 = ${paddingsize} ]; do >+ padding=" $padding" >+ paddingsize=$(($paddingsize - 1)) >+ done This particular block of code appears unnecessary (since $padding is unused). >+ paddingsize=$((60 - $namesize - $rc_argsize)) >+ until [ 0 = ${paddingsize} ]; do >+ padding=" $padding" >+ paddingsize=$(($paddingsize - 1)) >+ done For safety, the conditions should probably be [ 0 -ge ${paddingsize} ] I don't see any alternative to the until loop. If efficiency turns out to be a real issue then you could try doing the expansion in multiple goes. Eg: until [ 8 -gt ${paddingsize} ]; do padding=" $padding" paddingsize=$(($paddingsize - 8)) done until [ 0 -ge ${paddingsize} ]; do padding=" $padding" paddingsize=$(($paddingsize - 1)) done -- Peter Jeremy
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060418193018.GB694>