diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c index 2fa513c652e..526d11d1bb0 100644 --- a/base/shell/cmd/cmd.c +++ b/base/shell/cmd/cmd.c @@ -180,6 +180,79 @@ CON_STREAM_MODE OutputStreamMode = UTF8Text; // AnsiText; WORD wDefColor = 0; /* Default color */ #endif +/* Dynamic tracing */ +#ifdef FEATURE_DYNAMIC_TRACE + +BOOL g_bDynamicTracing = FALSE; + +VOID cmd_trace(INT type, LPCSTR file, INT line, LPCSTR func, LPCSTR pszFormat, ...) +{ + va_list va; + int cch; + char szTextA[1024]; +#ifdef _UNICODE + wchar_t szTextW[1024]; +#endif + + if (!g_bDynamicTracing) + return; + + va_start(va, pszFormat); + StringCchPrintfA(szTextA, _countof(szTextA), "%s (%d): ", file, line); + cch = lstrlenA(szTextA); + StringCchVPrintfA(&szTextA[cch], _countof(szTextA) - cch, pszFormat, va); + +#ifdef _UNICODE + MultiByteToWideChar(OutputCodePage, 0, szTextA, -1, szTextW, _countof(szTextW)); + szTextW[_countof(szTextW) - 1] = UNICODE_NULL; /* Avoid buffer overrun */ + ConOutPuts(szTextW); +#else + ConOutPuts(szTextA); +#endif + + switch (type) + { + case __WINE_DBCL_FIXME: + { + if (__WINE_GET_DEBUGGING(_FIXME, __wine_dbch___default)) + { + ros_dbg_log(__WINE_DBCL_FIXME, __wine_dbch___default, file, func, line, va); + } + break; + } + case __WINE_DBCL_ERR: + { + if (__WINE_GET_DEBUGGING(_ERR, __wine_dbch___default)) + { + ros_dbg_log(__WINE_DBCL_ERR, __wine_dbch___default, file, func, line, va); + } + break; + } + case __WINE_DBCL_WARN: + { + if (__WINE_GET_DEBUGGING(_WARN, __wine_dbch___default)) + { + ros_dbg_log(__WINE_DBCL_WARN, __wine_dbch___default, file, func, line, va); + } + break; + } + case __WINE_DBCL_TRACE: + { + if (__WINE_GET_DEBUGGING(_TRACE, __wine_dbch___default)) + { + ros_dbg_log(__WINE_DBCL_TRACE, __wine_dbch___default, file, func, line, va); + } + break; + } + default: + break; + } + + va_end(va); +} + +#endif + /* * convert * diff --git a/base/shell/cmd/config.h b/base/shell/cmd/config.h index 3a5b70b221a..09fb65d7e8e 100644 --- a/base/shell/cmd/config.h +++ b/base/shell/cmd/config.h @@ -18,26 +18,24 @@ /* Define to enable the alias command, and aliases.*/ #define FEATURE_ALIASES - /* Define to enable history */ #define FEATURE_HISTORY /*Define to enable history wrap (4nt's style)*/ #define WRAP_HISTORY - /* Define one of these to enable filename completion */ //#define FEATURE_UNIX_FILENAME_COMPLETION #define FEATURE_4NT_FILENAME_COMPLETION - /* Define to enable the directory stack */ #define FEATURE_DIRECTORY_STACK - /* Define to activate redirections and piping */ #define FEATURE_REDIRECTION +/* Define to enable dynamic switching of TRACE output in console */ +#define FEATURE_DYNAMIC_TRACE /* Define one of these to select the used locale. */ /* (date and time formats etc.) used in DATE, TIME, */ diff --git a/base/shell/cmd/precomp.h b/base/shell/cmd/precomp.h index 7c0e76dc3da..b1e65d23ae3 100644 --- a/base/shell/cmd/precomp.h +++ b/base/shell/cmd/precomp.h @@ -37,10 +37,34 @@ #include WINE_DEFAULT_DEBUG_CHANNEL(cmd); + #ifdef UNICODE #define debugstr_aw debugstr_w #else #define debugstr_aw debugstr_a #endif +#ifdef FEATURE_DYNAMIC_TRACE + +extern BOOL g_bDynamicTracing; +void cmd_trace(INT type, LPCSTR file, INT line, LPCSTR func, LPCSTR pszFormat, ...); + +#undef FIXME +#define FIXME(fmt, ...) \ + cmd_trace(__WINE_DBCL_FIXME, __FILE__, __LINE__, __FUNCTION__, fmt, ## __VA_ARGS__) + +#undef ERR +#define ERR(fmt, ...) \ + cmd_trace(__WINE_DBCL_ERR, __FILE__, __LINE__, __FUNCTION__, fmt, ## __VA_ARGS__) + +#undef WARN +#define WARN(fmt, ...) \ + cmd_trace(__WINE_DBCL_WARN, __FILE__, __LINE__, __FUNCTION__, fmt, ## __VA_ARGS__) + +#undef TRACE +#define TRACE(fmt, ...) \ + cmd_trace(__WINE_DBCL_TRACE, __FILE__, __LINE__, __FUNCTION__, fmt, ## __VA_ARGS__) + +#endif /* def FEATURE_DYNAMIC_TRACE */ + #endif /* __CMD_PRECOMP_H */ diff --git a/base/shell/cmd/set.c b/base/shell/cmd/set.c index 1adf091ad84..7d026e31b43 100644 --- a/base/shell/cmd/set.c +++ b/base/shell/cmd/set.c @@ -175,6 +175,15 @@ INT cmd_set(LPTSTR param) } *p++ = _T('\0'); + +#ifdef FEATURE_DYNAMIC_TRACE + /* Check for dynamic TRACE ON/OFF */ + if (!_tcsicmp(param, _T("CMDTRACE"))) + { + g_bDynamicTracing = !_tcsicmp(p, _T("ON")); + } +#endif + if (!SetEnvironmentVariable(param, *p ? p : NULL)) { retval = 1;