diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c index 2fa513c652e..ef00bfd6098 100644 --- a/base/shell/cmd/cmd.c +++ b/base/shell/cmd/cmd.c @@ -180,6 +180,74 @@ CON_STREAM_MODE OutputStreamMode = UTF8Text; // AnsiText; WORD wDefColor = 0; /* Default color */ #endif +/* Dynamic tracing */ +#ifdef FEATURE_DYNAMIC_TRACE + +BOOL g_bDynamicTracing = FALSE; +struct __wine_debug_functions g_debug_functions; + +VOID CmdTrace(INT type, LPCSTR file, INT line, LPCSTR func, LPCSTR format, ...) +{ + va_list va; + int cch; + char szTextA[800]; +#ifdef _UNICODE + wchar_t szTextW[800]; +#endif + + if (!g_bDynamicTracing) + return; + + va_start(va, format); + StringCchPrintfA(szTextA, _countof(szTextA), "%s (%d): ", file, line); + cch = lstrlenA(szTextA); + StringCchVPrintfA(&szTextA[cch], _countof(szTextA) - cch, format, va); + + /* Console output */ +#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 + + /* Debug logging */ + switch (type) + { + case __WINE_DBCL_FIXME: + { + g_debug_functions.dbg_vlog(__WINE_DBCL_FIXME, __wine_dbch___default, + file, func, line, format, va); + break; + } + case __WINE_DBCL_ERR: + { + g_debug_functions.dbg_vlog(__WINE_DBCL_ERR, __wine_dbch___default, + file, func, line, format, va); + break; + } + case __WINE_DBCL_WARN: + { + g_debug_functions.dbg_vlog(__WINE_DBCL_WARN, __wine_dbch___default, + file, func, line, format, va); + break; + } + case __WINE_DBCL_TRACE: + { + g_debug_functions.dbg_vlog(__WINE_DBCL_TRACE, __wine_dbch___default, + file, func, line, format, va); + break; + } + default: + break; + } + + va_end(va); +} + +#endif /* def FEATURE_DYNAMIC_TRACE */ + /* * convert * @@ -2316,6 +2384,10 @@ Initialize(VOID) ExecuteAutoRunFile(HKEY_CURRENT_USER); } +#ifdef FEATURE_DYNAMIC_TRACE + __wine_dbg_set_functions(NULL, &g_debug_functions, sizeof(g_debug_functions)); +#endif + /* Returns the rest of the command line */ return ptr; } 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..78e4e2fb690 100644 --- a/base/shell/cmd/precomp.h +++ b/base/shell/cmd/precomp.h @@ -37,10 +37,36 @@ #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; +extern struct __wine_debug_functions g_debug_functions; + +void CmdTrace(INT type, LPCSTR file, INT line, LPCSTR func, LPCSTR format, ...); + +#undef FIXME +#define FIXME(fmt, ...) \ + CmdTrace(__WINE_DBCL_FIXME, __FILE__, __LINE__, __FUNCTION__, fmt, ## __VA_ARGS__) + +#undef ERR +#define ERR(fmt, ...) \ + CmdTrace(__WINE_DBCL_ERR, __FILE__, __LINE__, __FUNCTION__, fmt, ## __VA_ARGS__) + +#undef WARN +#define WARN(fmt, ...) \ + CmdTrace(__WINE_DBCL_WARN, __FILE__, __LINE__, __FUNCTION__, fmt, ## __VA_ARGS__) + +#undef TRACE +#define TRACE(fmt, ...) \ + CmdTrace(__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..b8f0ea54816 100644 --- a/base/shell/cmd/set.c +++ b/base/shell/cmd/set.c @@ -175,6 +175,13 @@ 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;