ndblookval.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <ip.h>
  13. #include <ndb.h>
  14. /*
  15. * Look for a pair with the given attribute. look first on the same line,
  16. * then in the whole entry.
  17. */
  18. Ndbtuple*
  19. ndbfindattr(Ndbtuple *entry, Ndbtuple *line, char *attr)
  20. {
  21. Ndbtuple *nt;
  22. /* first look on same line (closer binding) */
  23. for(nt = line; nt;){
  24. if(strcmp(attr, nt->attr) == 0)
  25. return nt;
  26. nt = nt->line;
  27. if(nt == line)
  28. break;
  29. }
  30. /* search whole tuple */
  31. for(nt = entry; nt; nt = nt->entry)
  32. if(strcmp(attr, nt->attr) == 0)
  33. return nt;
  34. return nil;
  35. }
  36. Ndbtuple*
  37. ndblookval(Ndbtuple *entry, Ndbtuple *line, char *attr, char *to)
  38. {
  39. Ndbtuple *t;
  40. t = ndbfindattr(entry, line, attr);
  41. if(t != nil){
  42. strncpy(to, t->val, Ndbvlen-1);
  43. to[Ndbvlen-1] = 0;
  44. }
  45. return t;
  46. }