debug.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @file debug.h
  3. * #define DEBUG_FILE "debug.h"
  4. */
  5. #ifndef DEBUG_H
  6. #define DEBUG_H
  7. /* Enable debug globally */
  8. #ifndef DEBUG
  9. #define DEBUG
  10. #endif /* DEBUG */
  11. #define DEFAULT_PRINTLEVEL 0
  12. #define MAIN_PRINTLEVEL DEFAULT_PRINTLEVEL
  13. #define MERGE_PRINTLEVEL DEFAULT_PRINTLEVEL
  14. #define DOC_PRINTLEVEL DEFAULT_PRINTLEVEL
  15. #define LEXER_PRINTLEVEL DEFAULT_PRINTLEVEL
  16. #define PARSER_PRINTLEVEL DEFAULT_PRINTLEVEL
  17. #define DOC_ELT_PRINTLEVEL DEFAULT_PRINTLEVEL
  18. #define LISTMERGE_PRINTLEVEL DEFAULT_PRINTLEVEL
  19. #define SMERGER_PRINTLEVEL DEFAULT_PRINTLEVEL
  20. /* DEBUG_ON is used to test if debug is enabled */
  21. #ifdef DEBUG
  22. #define DEBUG_ON 1
  23. #else
  24. #define DEBUG_ON 0
  25. #endif /* DEBUG */
  26. #ifndef DEBUG_OUT
  27. #define DEBUG_OUT stderr
  28. #endif /* DEBUG_OUT */
  29. #ifndef DEBUG_PRINT
  30. #define DEBUG_PRINT 1
  31. #endif /* DEBUG_PRINT */
  32. /* Standard Debug Module */
  33. #ifndef DEBUG_MODULE
  34. #define DEBUG_MODULE DEFAULT
  35. #endif /* DEBUG_MODULE */
  36. #define debug_printf(format, ...) \
  37. debug_msg(DEFAULT, DEFAULT_PRINTLEVEL, format, ##__VA_ARGS__)
  38. #define debug_msg(module, level, format, ...) \
  39. do { if (DEBUG_ON && (level <= module ## _PRINTLEVEL)) { \
  40. fprintf (DEBUG_OUT, #module"-%d:%s:%d:%s " format, \
  41. level, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
  42. }} while (0)
  43. #endif /*DEBUG_H */