ndblookval.c 655 B

12345678910111213141516171819202122232425262728293031323334
  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. ndblookval(Ndbtuple *entry, Ndbtuple *line, char *attr, char *to)
  12. {
  13. Ndbtuple *nt;
  14. /* first look on same line (closer binding) */
  15. for(nt = line;;){
  16. if(strcmp(attr, nt->attr) == 0){
  17. strncpy(to, nt->val, Ndbvlen);
  18. return nt;
  19. }
  20. nt = nt->line;
  21. if(nt == line)
  22. break;
  23. }
  24. /* search whole tuple */
  25. for(nt = entry; nt; nt = nt->entry)
  26. if(strcmp(attr, nt->attr) == 0){
  27. strncpy(to, nt->val, Ndbvlen);
  28. return nt;
  29. }
  30. return 0;
  31. }