Subject: Re: db(1) show size of key and/or value (with patch)
To: Jeremy C. Reed <firstname.lastname@example.org>
From: Luke Mewburn <lukem@NetBSD.org>
Date: 09/21/2007 16:43:44
Content-Type: text/plain; charset=us-ascii
On Fri, Aug 31, 2007 at 08:35:50AM -0500, Jeremy C. Reed wrote:
| On Fri, 31 Aug 2007, Luke Mewburn wrote:
| > On Thu, Aug 30, 2007 at 06:01:38AM -0500, Jeremy C. Reed wrote:
| > | Any thoughts on this db(1) -s addition:
| > I'm curious; what did you need this for that a post-processor
| > program (hi awk(1) :) couldn't do?
| It just seemed easier in db(1) versus doing more awk scripting to get i=
| > | Is it okay that the size is one larger? For example:
| > |=20
| > | $ db -w hash abc.db key value =20
| > | Added key `key'
| > | $ db -s hash abc.db
| > | key (4) value (6)
| > The size is including the trailing NUL.
| > Does it return the correct length when using -N ?
| So I did printf("%zd", key->size - 1);
Does that work correctly when -N is in use?
You may want to look at the hackery that is the MINUSNUL() macro.
| > | Would you prefer different output format?
| > If we implemented this, I'd remove the surrounding parenthesis
| > to make the number easy to parse.
| $ /usr/src/usr.bin/db/obj/db -S b -T w -s hash /var/db/services.db | he=
| 37 2 gopher\04070/tcp\040nicname\040 22
| \M-~pop3s 6 197 3
| 286 3 afs3-resserver\0407010/udp\040icq\040 28
| \M^?87/tcp 7 43 2
| 38 2 gopher\04070/udp\040nicname\040 22
On consideration, I wonder if it's worth putting the length before the
string, rather than after?
| Thanks for your feedback. (It is nice to receive feedback from the=20
| AUTHOR :) db(1) sure is useful -- is your db(1) included with any other=
| operating systems?
I don't think so. Maybe FreeBSD picked it up?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (NetBSD)
-----END PGP SIGNATURE-----