tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

RFC: ppath(3): property list paths library



I'm working on a library called ppath(3) for making property lists more
convenient to use in the kernel.  With ppath(3), you refer to a property
to read/write/delete in a property list by the path from the list's
outermost container.  Comments welcome.

The latest source is at
<ftp://elmendorf.ojctech.com/users/netbsd-e238041d/ppath.tgz>.

Here is an example of using ppath(3):

/* Read and write from a personnel property list a user's "favorite color" 
const char **s;
int rc;
ppath_t *p;
prop_dictionary_t d;

/* Create the property list. */
d = prop_dictionary_internalize("<dict> "
"       <key>David Young</key>"
"       <dict>"
"               <key>favorite color</key>"
"               <string>green</string>"
"       </dict>"
"</dict>");

assert(d != NULL);

/* Set up the path. */
p = ppath_create();
ppath_push_key(p, "David Young");
ppath_push_key(p, "favorite color");

assert(p != NULL);

/* Get the string at the path. */
switch (ppath_get_string(d, p, &s)) {
case ENOENT:
        errx(EXIT_FAILURE, "favorite color not found");
        break;
case EFTYPE:
        errx(EXIT_FAILURE, "favorite color is not a string");
        break;
case 0:
        printf("old favorite color: %s\n", s);
        break;
default:
        errx(EXIT_FAILURE, "unknown error");
        break;
}

/* Replace with a new value. */
switch (ppath_set_string(d, p, "brown")) {
case ENOENT:
        errx(EXIT_FAILURE, "favorite color not found");
        break;
case EFTYPE:
        errx(EXIT_FAILURE, "favorite color is not a string");
        break;
case 0:
        printf("set a new favorite color\n");
        break;
default:
        errx(EXIT_FAILURE, "unknown error");
        break;
}

Dave

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 278-3933


Home | Main Index | Thread Index | Old Index