dkdebug.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /*
  20. * The set of diagnostic bits set by dk_setup(), and used by the other
  21. * functions to test offered diagnostics against.
  22. */
  23. unsigned dk_diag_mask = 0;
  24. char
  25. dk_setup(const char* diag_str, const struct dkdesc* diags) {
  26. dk_diag_mask = 0;
  27. int i;
  28. for (; *diag_str != '\0'; diag_str++) {
  29. for (i = 0; diags[i].keyletter != '\0'; i++) {
  30. if (diags[i].keyletter == *diag_str) {
  31. dk_diag_mask |= diags[i].mask;
  32. break;
  33. }
  34. }
  35. if (diags[i].keyletter == '\0') {
  36. return(*diag_str);
  37. }
  38. }
  39. return('\0');
  40. }
  41. void
  42. dkprintf(unsigned diag_req, const char format[], ...) {
  43. va_list ap;
  44. va_start(ap,format);
  45. vdkprintf(diag_req, format, ap);
  46. va_end(ap);
  47. }
  48. void
  49. vdkprintf(unsigned diag_req, const char format[], va_list ap) {
  50. if (diag_req & dk_diag_mask) {
  51. vfprintf(stderr, format, ap);
  52. }
  53. }
  54. int
  55. dk_set(unsigned diag_req) {
  56. return((diag_req & dk_diag_mask) != 0);
  57. }