Subject: Re: db(1) show size of key and/or value (with patch)
To: Jeremy C. Reed <reed@reedmedia.net>
From: Luke Mewburn <lukem@NetBSD.org>
List: tech-userlevel
Date: 09/21/2007 16:43:44
--xQR6quUbZ63TTuTU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Aug 31, 2007 at 08:35:50AM -0500, Jeremy C. Reed wrote:
  | On Fri, 31 Aug 2007, Luke Mewburn wrote:
  |=20
  | > On Thu, Aug 30, 2007 at 06:01:38AM -0500, Jeremy C. Reed wrote:
  | >   | Any thoughts on this db(1) -s addition:
  | >=20
  | > I'm curious; what did you need this for that a post-processor
  | > program (hi awk(1) :) couldn't do?
  |=20
  | It just seemed easier in db(1) versus doing more awk scripting to get i=
t=20
  | right.

Fair enough.


  | >   | 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)
  | >=20
  | > The size is including the trailing NUL.
  | > Does it return the correct length when using -N ?
  |=20
  | No.
  |=20
  | 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.



  |=20
  | >   | Would you prefer different output format?
  | >=20
  | > If we implemented this, I'd remove the surrounding parenthesis
  | > to make the number easy to parse.
  |=20
  | Okay:
  |=20
  | $ /usr/src/usr.bin/db/obj/db -S b -T w -s hash /var/db/services.db | he=
ad -5
  | 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?


  |=20
  |=20
  | 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=
=20
  | operating systems?

I don't think so.  Maybe FreeBSD picked it up?


cheers,
Luke.

--xQR6quUbZ63TTuTU
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (NetBSD)

iD8DBQFG82ggpBhtmn8zJHIRAn2yAKCFCM4/1NT3GVyebzvJw4vreTNiyQCgq4Gf
raUQUNe6XDWThkuaHecl9fw=
=mL2g
-----END PGP SIGNATURE-----

--xQR6quUbZ63TTuTU--