[Common] some scope and spacing formatting clean-ups

Miserably hated doing this commit.  Couldn't tell which code was whose, which was copyrighted, which was foreign enough to Project64 that I'd probably best just leave-as is, which was even worth considering part of Project64, which cleanups to omit doing and ignore because some ugly practices were rampant throughout the entire file and distracted from the purpose of this pull request too much.  So tried to stick to mostly just the braces/indentation changes here.
This commit is contained in:
unknown 2015-03-17 17:19:42 -04:00
parent fe868a85d5
commit ae04d23d86
6 changed files with 155 additions and 86 deletions

View File

@ -28,13 +28,15 @@ void CIniFileBase::fInsertSpaces ( int Pos, int NoOfSpaces )
m_File.Seek(0,CFileBase::end);
end = m_File.GetPosition();
if (NoOfSpaces > 0) {
if (NoOfSpaces > 0)
{
stdstr_f SpaceBuffer(_T("%*c"),NoOfSpaces,' ');
do {
SizeToRead = end - Pos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; }
if (SizeToRead > 0) {
if (SizeToRead > 0)
{
m_File.Seek(SizeToRead * -1,CFileBase::current);
WritePos = m_File.GetPosition();
memset(Data,0,sizeof(Data));
@ -47,9 +49,12 @@ void CIniFileBase::fInsertSpaces ( int Pos, int NoOfSpaces )
m_File.Seek(WritePos,CFileBase::begin);
}
} while (SizeToRead > 0);
} if (NoOfSpaces < 0) {
}
if (NoOfSpaces < 0)
{
int ReadPos = Pos + (NoOfSpaces * -1);
int WritePos = Pos;
do {
SizeToRead = end - ReadPos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; }
@ -60,6 +65,7 @@ void CIniFileBase::fInsertSpaces ( int Pos, int NoOfSpaces )
ReadPos += SizeToRead;
WritePos += SizeToRead;
} while (SizeToRead > 0);
m_File.Seek(WritePos,CFileBase::begin);
stdstr_f SpaceBuffer(_T("%*c"),(NoOfSpaces * -1),' ');
m_File.Write(SpaceBuffer.c_str(),(ULONG)SpaceBuffer.length());
@ -81,10 +87,12 @@ int CIniFileBase::GetStringFromFile ( char * & String, char * &Data, int & MaxDa
DataSize = m_File.Read(&Data[DataSize],MaxDataSize);
}
for (;;) {
for (;;)
{
int count;
for (count = ReadPos; count < DataSize; count ++) {
for (count = ReadPos; count < DataSize; count ++)
{
if (Data[count] == '\n')
{
int len = (count - ReadPos) + 1;
@ -103,7 +111,9 @@ int CIniFileBase::GetStringFromFile ( char * & String, char * &Data, int & MaxDa
}
DataSize -= ReadPos;
ReadPos = 0;
} else {
}
else
{
//Increase buffer size
int NewMaxDataSize = MaxDataSize + BufferIncrease;
char * NewBuffer = new char[NewMaxDataSize];
@ -159,13 +169,17 @@ void CIniFileBase::SaveCurrentSection ( void )
if (m_File.GetLength() < (int)strlen(m_LineFeed))
{
sprintf(SectionName.get(),"[%s]%s",m_CurrentSection.c_str(),m_LineFeed);
} else {
}
else
{
sprintf(SectionName.get(),"%s[%s]%s",m_LineFeed,m_CurrentSection.c_str(),m_LineFeed);
}
m_File.Write(SectionName.get(),(int)strlen(SectionName.get()));
m_CurrentSectionFilePos = m_File.GetPosition();
m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection,m_CurrentSectionFilePos));
} else {
}
else
{
//increase/decrease space needed
int NeededBufferLen = 0;
{
@ -197,8 +211,7 @@ void CIniFileBase::SaveCurrentSection ( void )
do {
result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
if (result <= 1) { continue; }
if (strlen(CleanLine(Input)) <= 1 ||
Input[0] != '[')
if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
{
EndPos = ((m_File.GetPosition() - DataSize) + ReadPos);
@ -270,7 +283,9 @@ bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurr
}
m_File.Seek(iter->second,CFileBase::begin);
bFoundSection = true;
} else {
}
else
{
m_File.Seek(m_lastSectionSearch, CFileBase::begin);
//long Fpos;
@ -301,14 +316,18 @@ bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurr
m_lastSectionSearch = (m_File.GetPosition() - DataSize) + ReadPos;
m_SectionsPos.insert(FILELOC::value_type(CurrentSection,m_lastSectionSearch));
if (_stricmp(lpSectionName,CurrentSection) != 0) {
if (_stricmp(lpSectionName,CurrentSection) != 0)
{
continue;
}
if (ChangeCurrentSection)
{
m_CurrentSection = lpSectionName;
m_CurrentSectionFilePos = m_lastSectionSearch;
} else {
}
else
{
m_File.Seek(m_lastSectionSearch,CFileBase::begin);
}
bFoundSection = true;
@ -379,7 +398,8 @@ const char * CIniFileBase::CleanLine ( char * const Line )
}
//strip any spaces or line feeds from the end of the line
for (int count = (int)strlen(&Line[0]) - 1; count >= 0; count --) {
for (int count = (int)strlen(&Line[0]) - 1; count >= 0; count --)
{
if (Line[count] != ' ' && Line[count] != '\r') { break; }
Line[count] = 0;
}
@ -423,7 +443,6 @@ bool CIniFileBase::IsEmpty()
{
if (m_File.GetLength() == 0)
return true;
return false;
}
@ -535,7 +554,9 @@ bool CIniFileBase::GetString ( LPCWSTR lpSectionName, LPCWSTR lpKeyName, LPCWSTR
if (lpSectionName == NULL || wcslen(lpSectionName) == 0)
{
strSection = "default";
} else {
}
else
{
stdstr::fromTString(lpSectionName,strSection);
}
@ -570,7 +591,9 @@ ULONG CIniFileBase::GetString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCT
if (lpSectionName == NULL || _tcslen(lpSectionName) == 0)
{
strSection = "default";
} else {
}
else
{
strSection = lpSectionName;
}
@ -605,7 +628,9 @@ bool CIniFileBase::GetNumber ( LPCWSTR lpSectionName, LPCWSTR lpKeyName, ULONG n
{
stdstr::fromTString(lpSectionName,strSection);
return GetNumber(strSection.c_str(),lpKeyName.c_str(),nDefault,Value);
} else {
}
else
{
return GetNumber(NULL,lpKeyName.c_str(),nDefault,Value);
}
}
@ -660,7 +685,9 @@ void CIniFileBase::SaveString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTS
if (lpSectionName == NULL || _tcslen(lpSectionName) == 0)
{
strSection = "default";
} else {
}
else
{
strSection = lpSectionName;
}
@ -681,11 +708,15 @@ void CIniFileBase::SaveString ( LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTS
iter->second = lpString;
m_CurrentSectionDirty = true;
}
} else {
}
else
{
m_CurrentSectionData.erase(iter);
m_CurrentSectionDirty = true;
}
} else {
}
else
{
if (lpString)
{
m_CurrentSectionData.insert(KeyValueList::value_type(lpKeyName,lpString));
@ -757,7 +788,9 @@ void CIniFileBase::GetKeyValueData ( LPCTSTR lpSectionName, KeyValueData & List
if (lpSectionName == NULL || _tcslen(lpSectionName) == 0)
{
strSection = "default";
} else {
}
else
{
strSection = lpSectionName;
}
@ -785,7 +818,9 @@ void CIniFileBase::ClearSectionPosList( long FilePos )
{
m_SectionsPos.clear();
m_lastSectionSearch = 0;
} else {
}
else
{
FILELOC::iterator iter = m_SectionsPos.begin();
while (iter != m_SectionsPos.end())
{

View File

@ -11,7 +11,8 @@ CLog::CLog (void ) :
{
}
CLog::~CLog (void) {
CLog::~CLog (void)
{
}
bool CLog::Open( LPCTSTR FileName, LOG_OPEN_MODE mode /* = Log_New */)
@ -43,7 +44,6 @@ bool CLog::Open( LPCTSTR FileName, LOG_OPEN_MODE mode /* = Log_New */)
m_hLogFile.Seek(0,mode == Log_Append ? CFile::end : CFile::begin);
#ifdef _UNICODE
if (m_hLogFile.GetLength() == 0)
{
WORD wUNICODE = 0xFEFF;

View File

@ -24,13 +24,15 @@
#define MB_SERVICE_NOTIFICATION 0x00200000L
#endif
CMemList *MemList ( void ) {
CMemList *MemList ( void )
{
static CMemList m_MemList;
return &m_MemList;
}
CMemList::CMemList() {
CMemList::CMemList()
{
MemList.clear();
hSemaphone = CreateSemaphore(NULL, 1,1, NULL);
State = Initialized;
@ -51,9 +53,11 @@ CMemList::CMemList() {
}
}
CMemList::~CMemList() {
CMemList::~CMemList()
{
size_t ItemsLeft = MemList.size();
if (ItemsLeft > 0) {
if (ItemsLeft > 0)
{
TCHAR path_buffer[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR];
TCHAR fname[_MAX_FNAME], ext[_MAX_EXT], LogFileName[_MAX_PATH];
@ -69,20 +73,27 @@ CMemList::~CMemList() {
_tmakepath( LogFileName, drive, dir, fname, _T("leak.csv") );
HANDLE hLogFile = INVALID_HANDLE_VALUE;
do
{
hLogFile = CreateFile(LogFileName,GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,
CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
hLogFile = CreateFile(
LogFileName,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
NULL
);
if (hLogFile == INVALID_HANDLE_VALUE)
{
if (GetLastError() == ERROR_SHARING_VIOLATION) {
if (GetLastError() == ERROR_SHARING_VIOLATION)
{
TCHAR Msg[3000];
_stprintf(Msg,TEXT("%s\nCan not be opened for writing please close app using this file\n\nTry Again ?"),LogFileName);
int Result = MessageBox(NULL,Msg,_T("Memory Leak"),MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND | MB_SERVICE_NOTIFICATION);
if (Result == IDNO) {
if (Result == IDNO)
{
break;
}
}
@ -112,7 +123,8 @@ CMemList::~CMemList() {
TCHAR Msg[3000];
_stprintf(Msg,TEXT("%s%s\n\nMemory Leaks detected\n\nOpen the Log File ?"),fname,ext);
int Result = MessageBox(NULL,Msg,_T("Memory Leak"),MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND| MB_SERVICE_NOTIFICATION);
if (Result == IDYES) {
if (Result == IDYES)
{
ShellExecute(NULL,_T("open"),LogFileName,NULL,NULL,SW_SHOW);
}
}
@ -135,10 +147,12 @@ void * CMemList::AddItem ( size_t size, char * filename, int line)
void CMemList::RecordAddItem ( void * ptr, size_t size, const char * filename, int line)
{
__try {
if (State == Initialized && hSemaphone != NULL) {
if (State == Initialized && hSemaphone != NULL)
{
DWORD CurrentThread = GetCurrentThreadId();
DWORD Result = WaitForSingleObject(hSemaphone,CurrentThread != ThreadID ? 30000: 0);
if (Result != WAIT_TIMEOUT) {
if (Result != WAIT_TIMEOUT)
{
ThreadID = CurrentThread;
DEBUG_LOCATION info;
@ -171,12 +185,15 @@ void * CMemList::ReAllocItem ( void * ptr, size_t size, const char * filename, i
{
return res;
}
if (ptr != res) {
if (ptr != res)
{
__try {
if (State == Initialized && hSemaphone != NULL) {
if (State == Initialized && hSemaphone != NULL)
{
DWORD CurrentThread = GetCurrentThreadId();
DWORD Result = WaitForSingleObject(hSemaphone,CurrentThread != ThreadID ? 30000 : 0);
if (Result != WAIT_TIMEOUT) {
if (Result != WAIT_TIMEOUT)
{
ThreadID = CurrentThread;
//Add new pointer
DEBUG_LOCATION info;
@ -206,7 +223,8 @@ void CMemList::Remove(void *ptr)
{
//remove old pointer
MEMLIST_ITER item = MemList.find(ptr);
if (item != MemList.end()) {
if (item != MemList.end())
{
MemList.erase(ptr);
}
}
@ -217,11 +235,14 @@ void CMemList::removeItem (void * ptr, bool bFree )
{
free(ptr);
}
__try {
if (State == Initialized && hSemaphone != NULL) {
if (State == Initialized && hSemaphone != NULL)
{
DWORD CurrentThread = GetCurrentThreadId();
DWORD Result = WaitForSingleObject(hSemaphone,CurrentThread != ThreadID ? 30000 : 0);
if (Result != WAIT_TIMEOUT) {
if (Result != WAIT_TIMEOUT)
{
ThreadID = CurrentThread;
Remove(ptr);
@ -236,15 +257,18 @@ void CMemList::removeItem (void * ptr, bool bFree )
}
}
void MemTest_AddLeak(char* Comment) {
void MemTest_AddLeak(char* Comment)
{
MemList()->AddItem(1,Comment,-1);
}
void* MemTest_malloc (size_t size, char* filename, int line) {
void* MemTest_malloc (size_t size, char* filename, int line)
{
return MemList()->AddItem(size,filename,line);
}
void* MemTest_realloc (void* ptr, size_t size, char* filename, int line) {
void* MemTest_realloc (void* ptr, size_t size, char* filename, int line)
{
return MemList()->ReAllocItem(ptr, size,filename,line);
}

View File

@ -2,12 +2,14 @@
BOOL TraceClosed = FALSE;
class CTraceLog {
class CTraceLog
{
std::vector<CTraceModule *> m_Modules;
CriticalSection m_CS;
public:
CTraceLog() {
CTraceLog()
{
}
~CTraceLog() { CloseTrace (); }

View File

@ -924,11 +924,15 @@ BOOL CPath::FindNext()
{
// Found a directory
UpDirectory();
} else {
}
else
{
SetNameExtension("");
}
AppendDirectory(FindData.cFileName);
} else {
}
else
{
// Found a file
if (IsDirectory())
{

View File

@ -159,7 +159,9 @@ stdstr & stdstr::Trim (const char * chars2remove)
if (pos != std::string::npos)
{
erase(0,pos);
} else {
}
else
{
erase(begin(), end()); // make empty
}
@ -167,7 +169,9 @@ stdstr & stdstr::Trim (const char * chars2remove)
if (pos != std::string::npos)
{
erase(pos+1);
} else {
}
else
{
erase(begin(), end()); // make empty
}
}