qmisc.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <stdarg.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "qminiqt.h"
  5. #ifdef DEBUG
  6. #define MAX_QDEBUG_TYPES 16
  7. static const char *types[MAX_QDEBUG_TYPES];
  8. static int types_no = 0;
  9. void qDebugSetTypes(int no, ...)
  10. {
  11. types_no = no;
  12. va_list ap;
  13. va_start(ap, no);
  14. for (int i = 0; i < no; ++i)
  15. types[i] = va_arg(ap, const char *);
  16. va_end(ap);
  17. }
  18. void qDebug(const char *type, const char *fmt, ...)
  19. {
  20. if (type) {
  21. bool found = FALSE;
  22. for (int i = 0; i < types_no; ++i)
  23. if (!strcmp(type, types[i]))
  24. found = TRUE;
  25. if (!found)
  26. return;
  27. }
  28. va_list ap;
  29. va_start(ap, fmt);
  30. fprintf(stderr, "[%s] ", type);
  31. vfprintf(stderr, fmt, ap);
  32. fputc('\n', stderr);
  33. va_end(ap);
  34. }
  35. #endif // DEBUG
  36. void qWarning(const char *fmt, ...)
  37. {
  38. va_list ap;
  39. va_start(ap, fmt);
  40. vfprintf(stderr, fmt, ap);
  41. fputc('\n', stderr);
  42. va_end(ap);
  43. }
  44. void qFatal(const char *fmt, ...)
  45. {
  46. va_list ap;
  47. va_start(ap, fmt);
  48. vfprintf(stderr, fmt, ap);
  49. fputc('\n', stderr);
  50. va_end(ap);
  51. exit(1);
  52. }