Skip to content

Commit

Permalink
Merge branch 'jl/LH-8v4/introduce-debug-guards' into next
Browse files Browse the repository at this point in the history
* jl/LH-8v4/introduce-debug-guards:
  common.h: split generic tchar defines from common functions
  testNppDebug.cpp: add tests for guard debug statements
  npp_debug.h: add guard_debugf_cat() controlled by guard state
  gitignore: do not ignore PowerEditor/MISC/Debug
  Debug output: improve output performance and design
  Debug guards: add documentation
  Debug guards: add a way to enable / disable per category
  Debug function guards: implement the guard.

* Merge note: When merging a few manual changes are needed to ensure
  that common generic and DEFAULT_NO_CASE are properly handled.

Conflicts:
	PowerEditor/src/MISC/Common/Common.h
	PowerEditor/src/precompiled_headers.h
	PowerEditor/visual.net/notepadPlus.9.vcproj

[#8]

Signed-off-by: Thell Fowler <git@tbfowler.name>
  • Loading branch information
Thell Fowler committed Jan 18, 2010
2 parents f9678e9 + ed2008d commit a75302c
Show file tree
Hide file tree
Showing 10 changed files with 895 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Thumbs.db
*.suo
*.tlb
*.tlh
*.tmp_*
*.bak
*.cache
*.ilk
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!PowerEditor/src/MISC/Debug/
PowerEditor/src/MISC/Debug/FuncGuards.h
46 changes: 0 additions & 46 deletions PowerEditor/src/MISC/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,6 @@
#define NPP_CP_DOS_437 437
#define NPP_CP_BIG5 950

#ifdef UNICODE
#define NppMainEntry wWinMain
#define generic_strtol wcstol
#define generic_strncpy(dest, src, size_d) wcsncpy_s(dest, size_d, src, _TRUNCATE)
#define generic_stricmp _wcsicmp
#define generic_strncmp wcsncmp
#define generic_strnicmp _wcsnicmp
#define generic_strncat wcsncat
#define generic_strchr wcschr
#define generic_atoi _wtoi
#define generic_itoa _itow_s
#define generic_atof _wtof
#define generic_strtok wcstok_s
#define generic_strftime wcsftime
#define generic_fprintf fwprintf
#define generic_sscanf swscanf_s
#define generic_fopen(pFile, filename, mode) if(_wfopen_s(&pFile, filename, mode) != 0){pFile = NULL;}
#define generic_fgets fgetws
#define generic_stat _wstat
#define generic_sprintf swprintf
#define COPYDATA_FILENAMES COPYDATA_FILENAMESW
#else
#define NppMainEntry WinMain
#define generic_strtol strtol
#define generic_strncpy(dest, src, size_d) strncpy_s(dest, size_d, src, _TRUNCATE)
#define generic_stricmp _stricmp
#define generic_strncmp strncmp
#define generic_strnicmp _strnicmp
#define generic_strncat strncat
#define generic_strchr strchr
#define generic_atoi atoi
#define generic_itoa _itoa_s
#define generic_atof atof
#define generic_strtok strtok_s
#define generic_strftime strftime
#define generic_fprintf fprintf
#define generic_sscanf sscanf_s
#define generic_fopen(pFile, filename, mode) if(fopen_s(&pFile, filename, mode) != 0){pFile = NULL;}
#define generic_fgets fgets
#define generic_stat _stat
#define generic_sprintf sprintf
#define COPYDATA_FILENAMES COPYDATA_FILENAMESA
#endif

typedef std::basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR> > generic_string;

void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr = NULL);

void systemMessage(const TCHAR *title);
Expand Down
70 changes: 70 additions & 0 deletions PowerEditor/src/MISC/Common/CommonGenerics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//this file is part of notepad++
//Copyright (C)2003 Don HO ( donho@altern.org )
//
//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., 675 Mass Ave, Cambridge, MA 02139, USA.

#ifndef MISC_COMMON_COMMONGENERICS_H
#define MISC_COMMON_COMMONGENERICS_H

#define CP_ANSI_LATIN_1 1252
#define CP_BIG5 950

#ifdef UNICODE
#define NppMainEntry wWinMain
#define generic_strtol wcstol
#define generic_strncpy(dest, src, size_d) wcsncpy_s(dest, size_d, src, _TRUNCATE)
#define generic_stricmp _wcsicmp
#define generic_strncmp wcsncmp
#define generic_strnicmp _wcsnicmp
#define generic_strncat wcsncat
#define generic_strchr wcschr
#define generic_atoi _wtoi
#define generic_itoa _itow_s
#define generic_atof _wtof
#define generic_strtok wcstok_s
#define generic_strftime wcsftime
#define generic_fprintf fwprintf
#define generic_sscanf swscanf_s
#define generic_fopen(pFile, filename, mode) if(_wfopen_s(&pFile, filename, mode) != 0){pFile = NULL;}
#define generic_fgets fgetws
#define generic_stat _wstat
#define generic_sprintf swprintf
#define COPYDATA_FILENAMES COPYDATA_FILENAMESW
#else
#define NppMainEntry WinMain
#define generic_strtol strtol
#define generic_strncpy(dest, src, size_d) strncpy_s(dest, size_d, src, _TRUNCATE)
#define generic_stricmp _stricmp
#define generic_strncmp strncmp
#define generic_strnicmp _strnicmp
#define generic_strncat strncat
#define generic_strchr strchr
#define generic_atoi atoi
#define generic_itoa _itoa_s
#define generic_atof atof
#define generic_strtok strtok_s
#define generic_strftime strftime
#define generic_fprintf fprintf
#define generic_sscanf sscanf_s
#define generic_fopen(pFile, filename, mode) if(fopen_s(&pFile, filename, mode) != 0){pFile = NULL;}
#define generic_fgets fgets
#define generic_stat _stat
#define generic_sprintf sprintf
#define COPYDATA_FILENAMES COPYDATA_FILENAMESA
#endif

typedef std::basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR> > generic_string;

#endif // MISC_COMMON_COMMONGENERICS_H
167 changes: 158 additions & 9 deletions PowerEditor/src/MISC/Debug/npp_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,170 @@

#include "MISC/Debug/npp_debug.h"

namespace Debug
namespace NppDebug
{
void OutputF(TCHAR* format, ...)
DebugOutput defaultDebugOutput;
DebugOutput* g_debugOutput = &defaultDebugOutput;

DebugOutput::DebugOutput()
{
resetValues();
}

void DebugOutput::printf(const TCHAR* format, ...)
{
if (format)
{
va_list args;
int len;
TCHAR* buffer;

va_start( args, format );
len = _vsctprintf( format, args ) + 1; // _vscprintf doesn't count terminating '\0'
buffer = new TCHAR[len];
_vstprintf_s( buffer, len, format, args );
OutputDebugString(buffer);
delete [] buffer;
int nbWrittenChar = _vsntprintf_s( m_currentPtr, MAX_DEBUG_STR - m_currentLen, _TRUNCATE, format, args );
if (nbWrittenChar >= 0)
{
m_currentLen += nbWrittenChar;
}
else // _vsntprintf_s returned -1, this means we were truncated.
{
m_currentLen = MAX_DEBUG_STR-1;
}
m_currentPtr = &m_outputStr[0] + m_currentLen;
}
else
{
*m_currentPtr = TEXT('\0');
}
}

void DebugOutput::vsprintf(const TCHAR* format, va_list args)
{
if (format)
{
int nbWrittenChar = _vsntprintf_s( m_currentPtr, MAX_DEBUG_STR - m_currentLen, _TRUNCATE, format, args );
if (nbWrittenChar >= 0)
{
m_currentLen += nbWrittenChar;
}
else // _vsntprintf_s returned -1, this means we were truncated.
{
m_currentLen = MAX_DEBUG_STR-1;
}
m_currentPtr = &m_outputStr[0] + m_currentLen;
}
else
{
*m_currentPtr = TEXT('\0');
}
}

void DebugOutput::flush()
{
if (m_outputStr[0] != TEXT('\0'))
{
output(&m_outputStr[0]);
resetValues();
}
}

void DebugOutput::output(const TCHAR* str)
{
OutputDebugString(str);
}

void DebugOutput::resetValues()
{
m_outputStr[0] = TEXT('\0');
m_currentPtr = &m_outputStr[0];
m_currentLen = 0;
}

int FuncGuard::_depth = 0;
TCHAR FuncGuard::_indent[MAX_DEBUG_INDENT];

FuncGuard::FuncGuard( const TCHAR* funcsig, const TCHAR* funcname, const TCHAR* file, int line, State state, const TCHAR* category):
_state(state)
{
if (_state == Enabled)
{
_funcname = funcname;
// JOCE: we currently don't do anything with the category variable. Should it be here at all?
_category = category;

// JOCE Only one call to OutputF.
g_debugOutput->printf(TEXT("%s%s(%d):\n"), getIndent(), file, line);
g_debugOutput->printf(TEXT("%sEntering[ %s ]\n"), getIndent(), funcsig);
indent();
g_debugOutput->flush();
}
}

FuncGuard::~FuncGuard()
{
if (_state == Enabled)
{
unindent();
g_debugOutput->printf(TEXT("%sLeaving[ %s ]\n"), getIndent(), _funcname.c_str());
g_debugOutput->flush();
}
}

void FuncGuard::printf(State printfState, const TCHAR* format, ...)
{
if (printfState == Enabled)
{
if (_state == Enabled)
{
g_debugOutput->printf(getIndent());
}

va_list args;
va_start( args, format );
g_debugOutput->vsprintf(format, args);
g_debugOutput->flush();
va_end(args);
}
}

void FuncGuard::indent()
{
if (_state == Enabled)
{
_depth++;
if (_depth >= MAX_DEBUG_INDENT)
{
DebugBreak();
_depth = MAX_DEBUG_INDENT-1;
}
}
}

void FuncGuard::unindent()
{
if (_state == Enabled)
{
_depth--;
if (_depth < 0)
{
DebugBreak();
_depth = 0;
}
}
}

TCHAR* FuncGuard::getIndent()
{
if (_state == Enabled)
{
int i = 0;;
for (; i < _depth; i++)
{
_indent[i] = TEXT('\t');
}
_indent[i] = TEXT('\0');
return _indent;
}
return TEXT("");
}

} // namespace Debug

#endif // #ifndef SHIPPING

0 comments on commit a75302c

Please sign in to comment.