Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorOliver Schneider <oliver@assarbad.net>2014-01-26 23:39:18 +0400
committerOliver Schneider <oliver@assarbad.net>2014-01-26 23:39:18 +0400
commit5c08cdf538e5d28d552309cc1aec99a37def2067 (patch)
treef121f16563d15f05666bae9b095d4de6c3bc7e02 /common
parent9a26435a1cf6e9d6c6aa6df5a8b3f682ab8f4e97 (diff)
Adding new implementation file tracer.cpp
Changing the license of the tracer (.h) to MIT Adjustments to premake4.lua to accommodate these changes (and previous ones) Creating console window for VTRACE in debug builds now Updated main project file (because of premake4.lua)
Diffstat (limited to 'common')
-rw-r--r--common/tracer.cpp105
-rw-r--r--common/tracer.h93
2 files changed, 143 insertions, 55 deletions
diff --git a/common/tracer.cpp b/common/tracer.cpp
new file mode 100644
index 0000000..6acdf98
--- /dev/null
+++ b/common/tracer.cpp
@@ -0,0 +1,105 @@
+// tracer.h - Implementation of tracer class for debugging purposes
+//
+// NOTE: this file is under MIT license as opposed to the project as a whole.
+//
+// WinDirStat - Directory Statistics
+// Copyright (C) 2010 Oliver Schneider (assarbad.net)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+// Author(s): - assarbad -> http://windirstat.info/contact/oliver/
+//
+
+#ifndef __TRACER_CPP_VER__
+#define __TRACER_CPP_VER__ 2014012617
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+#pragma once
+#endif // Check for "#pragma once" support
+#include "tracer.h"
+#include <cstdarg>
+#include <fcntl.h>
+#include <io.h>
+
+#if VTRACE_TO_CONSOLE
+CWDSTracerConsole::CWDSTracerConsole()
+{
+ ::AllocConsole();
+ // Standard output
+ int hCrt = _open_osfhandle((intptr_t)::GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
+ FILE *hf = _fdopen(hCrt, "w");
+ *stdout = *hf;
+ setvbuf(stdout, NULL, _IONBF, 0);
+ // Standard error
+ hCrt = _open_osfhandle((intptr_t)::GetStdHandle(STD_ERROR_HANDLE), _O_TEXT);
+ hf = _fdopen(hCrt, "w");
+ *stderr = *hf;
+ setvbuf(stderr, NULL, _IONBF, 0);
+}
+
+CWDSTracerConsole::~CWDSTracerConsole()
+{
+ ::FreeConsole();
+}
+#endif // VTRACE_TO_CONSOLE
+
+CWDSTracer::CWDSTracer(LPCSTR srcfile, LPCSTR fctname, unsigned int srcline)
+ : m_srcfile(srcfile)
+ , m_srcfunc(fctname)
+ , m_srcline(srcline)
+ // we can rely on the format with back slashes, no need to check forward slashes here
+ , m_srcbasename((srcfile) ? strrchr(srcfile, '\\') : NULL)
+{
+ // Skip over the backslash
+ m_srcbasename = (m_srcbasename) ? m_srcbasename + 1 : srcfile;
+}
+
+void CWDSTracer::operator()(LPCSTR format, ...) // ANSI
+{
+ CStringA str;
+ va_list args;
+ va_start(args, format);
+ str.FormatV(format, args);
+ va_end(args);
+ CStringA strDbg;
+ strDbg.Format("[%hs:%u:%hs] %hs\n", m_srcbasename, m_srcline, m_srcfunc, str.GetBuffer());
+# if !VTRACE_TO_CONSOLE || (VTRACE_TO_CONSOLE && !VTRACE_NO_OUTPUTDEBUGSTRING)
+ OutputDebugStringA(strDbg.GetBuffer());
+# endif
+# if VTRACE_TO_CONSOLE
+ printf(strDbg.GetBuffer());
+# endif // VTRACE_TO_CONSOLE
+}
+
+void CWDSTracer::operator()(LPCWSTR format, ...) // Unicode
+{
+ CStringW str;
+ va_list args;
+ va_start(args, format);
+ str.FormatV(format, args);
+ va_end(args);
+ CStringW strDbg;
+ strDbg.Format(L"[%hs:%u:%hs] %ws\n", m_srcbasename, m_srcline, m_srcfunc, str.GetBuffer());
+# if !VTRACE_TO_CONSOLE || (VTRACE_TO_CONSOLE && !VTRACE_NO_OUTPUTDEBUGSTRING)
+ OutputDebugStringW(strDbg.GetBuffer());
+# endif
+# ifdef VTRACE_TO_CONSOLE
+ wprintf(strDbg.GetBuffer());
+# endif // VTRACE_TO_CONSOLE
+}
+#endif // __TRACER_CPP_VER__
diff --git a/common/tracer.h b/common/tracer.h
index 7797567..3ee72dc 100644
--- a/common/tracer.h
+++ b/common/tracer.h
@@ -1,82 +1,65 @@
// tracer.h - Implementation of tracer class for debugging purposes
//
+// NOTE: this file is under MIT license as opposed to the project as a whole.
+//
// WinDirStat - Directory Statistics
// Copyright (C) 2010 Oliver Schneider (assarbad.net)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
//
// Author(s): - assarbad -> http://windirstat.info/contact/oliver/
//
-#ifndef __TRACER_CPP_VER__
-#define __TRACER_CPP_VER__ 2010073115
+#ifndef __TRACER_H_VER__
+#define __TRACER_H_VER__ 2014012617
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif // Check for "#pragma once" support
#ifdef _DEBUG
-#include <afxwin.h> // MFC core and standard components
-#include <cstdarg>
+#if VTRACE_TO_CONSOLE
+class CWDSTracerConsole
+{
+public:
+ CWDSTracerConsole();
+ ~CWDSTracerConsole();
+};
+#endif // VTRACE_TO_CONSOLE
class CWDSTracer
{
public:
- CWDSTracer(LPCSTR srcfile, unsigned int srcline)
- : m_srcfile(srcfile)
- , m_srcline(srcline)
- // we can rely on the format with back slashes, no need to check forward slashes here
- , m_srcbasename((srcfile) ? strrchr(srcfile, '\\') : NULL)
- {
- // Skip over the backslash
- m_srcbasename = (m_srcbasename) ? m_srcbasename + 1 : srcfile;
- }
-
- void operator()(LPCSTR format, ...) // ANSI
- {
- CStringA str;
- va_list args;
- va_start(args, format);
- str.FormatV(format, args);
- va_end(args);
- CStringA strDbg;
- strDbg.Format("[%hs:%u] %hs\n", m_srcbasename, m_srcline, str.GetBuffer());
- OutputDebugStringA(strDbg.GetBuffer());
- }
-
- void operator()(LPCWSTR format, ...) // Unicode
- {
- CStringW str;
- va_list args;
- va_start(args, format);
- str.FormatV(format, args);
- va_end(args);
- CStringW strDbg;
- strDbg.Format(L"[%hs:%u] %ws\n", m_srcbasename, m_srcline, str.GetBuffer());
- OutputDebugStringW(strDbg.GetBuffer());
- }
-
+ CWDSTracer(LPCSTR srcfile, LPCSTR fctname, unsigned int srcline);
+ void operator()(LPCSTR format, ...);
+ void operator()(LPCWSTR format, ...);
private:
const CStringA m_srcfile;
+ const CStringA m_srcfunc;
unsigned int m_srcline;
LPCSTR m_srcbasename;
+ CWDSTracer& operator=(const CWDSTracer&); // hide it
};
// Use as VTRACE(format, ...) ... *must* be on one long line ;)
-# define VTRACE CWDSTracer(__##FILE##__, __##LINE##__)
-#else // note _DEBUG
+# define VTRACE CWDSTracer(__##FILE##__, __##FUNCTION##__, __##LINE##__)
+#else // not _DEBUG, ... please note that this trick works _because_ of the VC++ preprocessor
# define VTRACE /##/
#endif // _DEBUG
-#endif // __TRACER_CPP_VER__ \ No newline at end of file
+#endif // __TRACER_H_VER__ \ No newline at end of file