-#define DEBUG(n, a) if (_nc_tracing & (1 << (n - 1))) _tracef a
-extern unsigned _nc_tracing;
-extern void _nc_tracef(char *, ...) GCC_PRINTFLIKE(1,2);
-extern const char *_nc_visbuf(const char *);
+/*
+ * Some traces are designed to be used via tic's verbose option (and similar in
+ * infocmp and toe) rather than the 'trace()' function. So we use the bits
+ * above the normal trace() parameter as a debug-level.
+ */
+
+#define MAX_DEBUG_LEVEL 15
+#define DEBUG_LEVEL(n) ((n) << TRACE_SHIFT)
+
+#define set_trace_level(n) \
+ _nc_tracing &= DEBUG_LEVEL(MAX_DEBUG_LEVEL), \
+ _nc_tracing |= DEBUG_LEVEL(n)
+
+#ifdef TRACE
+#define DEBUG(n, a) if (_nc_tracing >= DEBUG_LEVEL(n)) _tracef a
+#else
+#define DEBUG(n, a) /*nothing*/
+#endif
+
+extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
+extern NCURSES_EXPORT(void) _nc_tracef (char *, ...) GCC_PRINTFLIKE(1,2);
+extern NCURSES_EXPORT(const char *) _nc_visbuf (const char *);
+extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);