ndblookval.c 791 B

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