Date: Wed, 17 Nov 2010 21:39:45 +0000 From: Alexander Best <arundel@freebsd.org> To: Dan Nelson <dnelson@allantgroup.com> Cc: freebsd-questions@freebsd.org Subject: Re: a question regarding proper printf(3) formating and alignment Message-ID: <20101117213945.GA46006@freebsd.org> In-Reply-To: <20101117195521.GF57869@dan.emsphone.com> References: <20101117155006.GA88394@freebsd.org> <20101117195521.GF57869@dan.emsphone.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed Nov 17 10, Dan Nelson wrote: > In the last episode (Nov 17), Alexander Best said: > > hi there, > > > > i've looked at a lot of utilities in the bsd src tree and most of them > > seem to be doing something like this: > > > > Device 1M-blocks Used Avail Capacity > > /dev/label/swapfs 10239 0 10239 0% > > /dev/label/swap 8191 0 8191 0% > > Total 18431 0 18431 0% > > > > as you can see the header simply gets written with a number of tabs in > > between the keywords, but then the actual output aligns differently. > > > > i'd like to learn of ways formatting the header so that it aligns > > properly, whether the device name is 10 chars long or 1000. is there an > > example for this somewhere in the src tree? > > /bin/ls does this for the user, group, and size columns. Note that this > only works if you batch up your output (or take two passes over your input > data). I seem to remember /usr/bin/find doing this dynamically by expanding > columns as it saw values that were larger than the previous max, but > apparently not (I just tested it). thanks. so looking at the /bin/ls source is probably the first i should do. cheers. alex > > -- > Dan Nelson > dnelson@allantgroup.com -- a13x
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101117213945.GA46006>