From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 18 20:51:09 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 35EAD16A408 for ; Tue, 18 Apr 2006 20:51:09 +0000 (UTC) (envelope-from mistry.7@osu.edu) Received: from mail.united-ware.com (am-productions.biz [69.61.164.22]) by mx1.FreeBSD.org (Postfix) with ESMTP id 77DD643D5E for ; Tue, 18 Apr 2006 20:51:06 +0000 (GMT) (envelope-from mistry.7@osu.edu) Received: from [192.168.1.100] (am-productions.biz [69.61.164.22]) (authenticated bits=0) by mail.united-ware.com (8.13.4/8.13.4) with ESMTP id k3IL7Qtv051167 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 18 Apr 2006 17:07:32 -0400 (EDT) (envelope-from mistry.7@osu.edu) From: Anish Mistry To: freebsd-hackers@freebsd.org Date: Tue, 18 Apr 2006 16:50:55 -0400 User-Agent: KMail/1.9.1 References: <444515C8.3030406@centtech.com> <20060418203333.GA19094@central.0xfce3.net> <44454D96.3030004@centtech.com> In-Reply-To: <44454D96.3030004@centtech.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart11550951.phmSzyb89C"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200604181651.03040.mistry.7@osu.edu> X-Spam-Status: No, score=-5.5 required=5.0 tests=ALL_TRUSTED,BAYES_50, MYFREEBSD2 autolearn=failed version=3.1.0 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on mail.united-ware.com X-Virus-Scanned: ClamAV 0.88.1/1405/Tue Apr 18 14:30:25 2006 on mail.united-ware.com X-Virus-Status: Clean Cc: Gordon Bergling , cokane@cokane.org Subject: Re: [PATCH] Fancy rc startup style RFC X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Apr 2006 20:51:09 -0000 --nextPart11550951.phmSzyb89C Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Tuesday 18 April 2006 16:35, Eric Anderson wrote: > Gordon Bergling wrote: > > * Thus spake Eric Anderson (anderson@centtech.com): > >> Peter Jeremy wrote: > >>> On Tue, 2006-Apr-18 14:02:07 -0400, Coleman Kane wrote: > >>> > >>> A few comments on the shellscript: > >>>> + rcargsize=3D`echo $rc_arg` > >>>> + rcargsize=3D${#rcargsize} > >>> > >>> Try rcargsize=3D$((${#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=3D`echo -n $name` > >>>> + namesize=3D${#namesize} > >>> > >>> or namesize=3D${#name} > >>> > >>>> + padding=3D"" > >>>> + paddingsize=3D$(($columns - 15 - $2 - $namesize)) > >>>> + until [ 0 =3D ${paddingsize} ]; do > >>>> + padding=3D" $padding" > >>>> + paddingsize=3D$(($paddingsize - 1)) > >>>> + done > >>> > >>> This particular block of code appears unnecessary (since > >>> $padding is unused). > >> > >> I must be missing something, because I'm pretty sure it's used.. > >> What did I miss? > >> > >>>> + paddingsize=3D$((60 - $namesize - $rc_argsize)) > >>>> + until [ 0 =3D ${paddingsize} ]; do > >>>> + padding=3D" $padding" > >>>> + paddingsize=3D$(($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=3D" $padding" > >>> paddingsize=3D$(($paddingsize - 8)) > >>> done > >>> until [ 0 -ge ${paddingsize} ]; do > >>> padding=3D" $padding" > >>> paddingsize=3D$(($paddingsize - 1)) > >>> done > >> > >> Thanks for the hints. I was testing the same changes to the > >> namesize/etc as you suggested, and it does work and is more > >> readable and more efficient. > >> > >> I've included your suggestions and put the latest changes here: > >> > >> http://www.googlebit.com/freebsd/patches/rc_fancy.patch-3 > > > > Patch -3 is working good here. :) > > > > best regards, > > > > Gordon > > > > PS: next try... fancy_color_rc=3D"YES" ;) > > If I could figure out how to make sh do colors, I'd do it. :) Is that all? :) #!/bin/sh ############################################################ # Nico Golde Homepage: http://www.ngolde.de # Last change: Mon Feb 16 16:24:41 CET 2004 ############################################################ for attr in 0 1 4 5 7 ; do =20 echo "----------------------------------------------------------------" printf "ESC[%s;Foreground;Background - \n" $attr for fore in 30 31 32 33 34 35 36 37; do for back in 40 41 42 43 44 45 46 47; do printf '\033[%s;%s;%sm %02s;%02s ' $attr $fore $back=20 $fore $back done printf '\n' done printf '\033[0m' done =2D-=20 Anish Mistry --nextPart11550951.phmSzyb89C Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (FreeBSD) iD8DBQBERVE3xqA5ziudZT0RAo2UAJ95Bonq6NpYQ3Qk/KhDsNdJOS49UwCgw5z8 lnTRSCsdkFYNSVg2ySBKfDI= =TrAy -----END PGP SIGNATURE----- --nextPart11550951.phmSzyb89C--