sexp_assoc

This commit is contained in:
Tony Garnock-Jones 2011-01-01 10:15:01 -05:00
parent 53609faa82
commit ce5de71e11
2 changed files with 17 additions and 0 deletions

15
sexp.c
View File

@ -130,3 +130,18 @@ cmsg_bytes_t sexp_data(sexp_t *x) {
die("Unknown sexp kind %d in data accessor\n", x->kind);
}
}
sexp_t *sexp_assoc(sexp_t *list, cmsg_bytes_t key) {
while (list != NULL) {
sexp_t *candidate = sexp_head(list);
if (sexp_stringp(candidate)) {
cmsg_bytes_t candidate_data = sexp_data(candidate);
if ((candidate_data.len == key.len)
&& (!memcmp(candidate_data.bytes, key.bytes, key.len))) {
return candidate;
}
}
list = sexp_tail(list);
}
return NULL;
}

2
sexp.h
View File

@ -98,4 +98,6 @@ extern cmsg_bytes_t sexp_data(sexp_t *x);
__val; \
})
extern sexp_t *sexp_assoc(sexp_t *list, cmsg_bytes_t key);
#endif