Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <ip.h>
5 #include <ndb.h>
7 /*
8 * Look for a pair with the given attribute. look first on the same line,
9 * then in the whole entry.
10 */
11 Ndbtuple*
12 ndbfindattr(Ndbtuple *entry, Ndbtuple *line, char *attr)
13 {
14 Ndbtuple *nt;
16 /* first look on same line (closer binding) */
17 for(nt = line; nt;){
18 if(strcmp(attr, nt->attr) == 0)
19 return nt;
20 nt = nt->line;
21 if(nt == line)
22 break;
23 }
25 /* search whole tuple */
26 for(nt = entry; nt; nt = nt->entry)
27 if(strcmp(attr, nt->attr) == 0)
28 return nt;
30 return nil;
31 }
33 Ndbtuple*
34 ndblookval(Ndbtuple *entry, Ndbtuple *line, char *attr, char *to)
35 {
36 Ndbtuple *t;
38 t = ndbfindattr(entry, line, attr);
39 if(t != nil){
40 strncpy(to, t->val, Ndbvlen-1);
41 to[Ndbvlen-1] = 0;
42 }
43 return t;
44 }