From owner-freebsd-arch@FreeBSD.ORG Fri Jul 26 07:33:25 2013 Return-Path: Delivered-To: arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 4461ABBB for ; Fri, 26 Jul 2013 07:33:25 +0000 (UTC) (envelope-from pawel@dawidek.net) Received: from mail.dawidek.net (garage.dawidek.net [91.121.88.72]) by mx1.freebsd.org (Postfix) with ESMTP id 084D929C3 for ; Fri, 26 Jul 2013 07:33:24 +0000 (UTC) Received: from localhost (58.wheelsystems.com [83.12.187.58]) by mail.dawidek.net (Postfix) with ESMTPSA id 37E6D33F; Fri, 26 Jul 2013 09:28:26 +0200 (CEST) Date: Fri, 26 Jul 2013 09:34:08 +0200 From: Pawel Jakub Dawidek To: Jordan Hubbard Subject: Re: General purpose library for name/value pairs. Message-ID: <20130726073408.GA1383@garage.freebsd.pl> References: <20130704215329.GG1402@garage.freebsd.pl> <4818.1373008073@critter.freebsd.dk> <20130705195255.GB25842@garage.freebsd.pl> <60317.1373055040@critter.freebsd.dk> <20130708150308.GE1383@garage.freebsd.pl> <717D098F-D07E-45B0-B9F0-8D8BCEF06923@mail.turbofuzz.com> <20130708213351.GB1405@garage.freebsd.pl> <20130725202832.GD1400@garage.freebsd.pl> <818200C6-2AF2-465D-873B-CA610A9C763A@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="liOOAslEiF7prFVr" Content-Disposition: inline In-Reply-To: <818200C6-2AF2-465D-873B-CA610A9C763A@gmail.com> X-OS: FreeBSD 10.0-CURRENT amd64 User-Agent: Mutt/1.5.21 (2010-09-15) Cc: arch@FreeBSD.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Jul 2013 07:33:25 -0000 --liOOAslEiF7prFVr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jul 26, 2013 at 12:26:15AM -0700, Jordan Hubbard wrote: >=20 > On Jul 25, 2013, at 1:28 PM, Pawel Jakub Dawidek wrote: >=20 > > Returning to this thread after a short break. I removed all > > {,u}int{8,16.32.64} types and implemented only 'number' type which is > > uint64_t. Looks much nicer now. >=20 > Indeed! >=20 > > Not sure if you looked at the API, but with nvlist you can lookup > > element by name: > >=20 > > const char *nvlist_get_string(const nvlist_t *nvl, const char *name); >=20 > Sorry, I must have misunderstood that function since I thought it would j= ust get you a named string - you can also do something like this? >=20 > { { "name", "Pawel Jakub Dawidek" }, { "age", 37 }, { "favorite-float-nu= m", 1.E027 }, { "likes", { "cats", "ZFS", "fashion models" } }, { "company"= , "wheel systems" } } >=20 > And then look up "name" and get a string, "age" and get a number, "favori= te-float-num" for a float, "likes" for an array of strings, etc? Exactly. The code would look like this: static const char * const *likes =3D { "cats", "ZFS", "fashion models" }; nvlist_t *nvl; nvl =3D nvlist_create(0); nvlist_add_string(nvl, "name", "Pawel Jakub Dawidek"); nvlist_add_number(nvl, "age", 37); /* XXX: Not my age, yet:) */ /* No floats. */ nvlist_add_array_string(nvl, "likes", likes, 3); nvlist_add_string(nvl, "company", "Wheel Systems"); if (nvlist_error(nvl) !=3D 0) errx(1, "Unable to create nvlist."); Then: printf("Name: %s\nAge: %d\nCompany %s\n", nvlist_get_string(nvl, "name"), (int)nvlist_get_number(nvl, "age"), nvlist_get_string(nvl, "company")); --=20 Pawel Jakub Dawidek http://www.wheelsystems.com FreeBSD committer http://www.FreeBSD.org Am I Evil? Yes, I Am! http://mobter.com --liOOAslEiF7prFVr Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iEYEARECAAYFAlHyJnAACgkQForvXbEpPzTIMgCg5DbrGXJTWqIyjaZrJWrnGOvT VkEAoK+HWaWyl8E2OXHyxVwop8ciSXvq =j0XC -----END PGP SIGNATURE----- --liOOAslEiF7prFVr--