fmt.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <thread.h>
  4. #include <sunrpc.h>
  5. /*
  6. * print formatters
  7. */
  8. int
  9. sunRpcFmt(Fmt *f)
  10. {
  11. SunRpc *rpc;
  12. rpc = va_arg(f->args, SunRpc*);
  13. sunRpcPrint(f, rpc);
  14. return 0;
  15. }
  16. static SunProg **fmtProg;
  17. static int nfmtProg;
  18. static RWLock fmtLock;
  19. void
  20. sunFmtInstall(SunProg *p)
  21. {
  22. int i;
  23. wlock(&fmtLock);
  24. for(i=0; i<nfmtProg; i++){
  25. if(fmtProg[i] == p){
  26. wunlock(&fmtLock);
  27. return;
  28. }
  29. }
  30. if(nfmtProg%16 == 0)
  31. fmtProg = erealloc(fmtProg, sizeof(fmtProg[0])*(nfmtProg+16));
  32. fmtProg[nfmtProg++] = p;
  33. wunlock(&fmtLock);
  34. }
  35. int
  36. sunCallFmt(Fmt *f)
  37. {
  38. int i;
  39. void (*fmt)(Fmt*, SunCall*);
  40. SunCall *c;
  41. SunProg *p;
  42. c = va_arg(f->args, SunCall*);
  43. rlock(&fmtLock);
  44. for(i=0; i<nfmtProg; i++){
  45. p = fmtProg[i];
  46. if(p->prog == c->rpc.prog && p->vers == c->rpc.vers){
  47. runlock(&fmtLock);
  48. if(c->type < 0 || c->type >= p->nproc || (fmt=p->proc[c->type].fmt) == nil)
  49. return fmtprint(f, "unknown proc %c%d", "TR"[c->type&1], c->type>>1);
  50. (*fmt)(f, c);
  51. return 0;
  52. }
  53. }
  54. runlock(&fmtLock);
  55. fmtprint(f, "<sunrpc %d %d %c%d>", c->rpc.prog, c->rpc.vers, "TR"[c->type&1], c->type>>1);
  56. return 0;
  57. }