dkdebug.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. * PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <stdio.h>
  17. #include <stdarg.h>
  18. #include "dkdebug.h"
  19. unsigned dk_diag_mask;
  20. int
  21. dk_setup(const char* diag_str, const struct dkdesc* diags) {
  22. dk_diag_mask = 0;
  23. int i;
  24. for (; *diag_str != '\0'; diag_str++)
  25. for (i = 0; diags[i].keyletter != '\0'; i++) {
  26. if (diags[i].keyletter == *diag_str) {
  27. dk_diag_mask |= diags[i].mask;
  28. break;
  29. }
  30. if (diags[i].keyletter == '\0') {
  31. return(0);
  32. }
  33. }
  34. return(1);
  35. }
  36. void
  37. dkprintf(unsigned diag_req, const char format[], ...) {
  38. va_list ap;
  39. va_start(ap,format);
  40. vdkprintf(diag_req, format, ap);
  41. va_end(ap);
  42. }
  43. void
  44. vdkprintf(unsigned diag_req, const char format[], va_list ap) {
  45. if (diag_req & dk_diag_mask) {
  46. vfprintf(stderr, format, ap);
  47. }
  48. }
  49. int
  50. dk_set(unsigned diag_req) {
  51. return(diag_req & dk_diag_mask);
  52. }