Skip to content

Commit

Permalink
Update for VisualStudio 17.3
Browse files Browse the repository at this point in the history
Update for StyleFramework
Update for SQLComponents
Update for BaseLibrary
Update for Marlin
Implemented DARK theme!
  • Loading branch information
edwig committed Jun 18, 2023
1 parent 1c75593 commit 605608a
Show file tree
Hide file tree
Showing 82 changed files with 2,592 additions and 570 deletions.
2 changes: 2 additions & 0 deletions BaseLibrary/BaseLibrary.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<ClInclude Include="StdException.h" />
<ClInclude Include="StoreMessage.h" />
<ClInclude Include="StringUtilities.h" />
<ClInclude Include="XSDSchema.h" />
<ClInclude Include="XStringBuilder.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="unzip.h" />
Expand Down Expand Up @@ -233,6 +234,7 @@
<ClCompile Include="StdException.cpp" />
<ClCompile Include="StoreMessage.cpp" />
<ClCompile Include="StringUtilities.cpp" />
<ClCompile Include="XSDSchema.cpp" />
<ClCompile Include="XStringBuilder.cpp" />
<ClCompile Include="unzip.cpp" />
<ClCompile Include="WideMessageBox.cpp" />
Expand Down
12 changes: 9 additions & 3 deletions BaseLibrary/BaseLibrary.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@
<ClInclude Include="AuthenticationHeader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="XSDSchema.h">
<Filter>Header Files\XML_SOAP</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="bcd.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -485,5 +485,11 @@
<ClCompile Include="AuthenticationHeader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="XSDSchema.cpp">
<Filter>Source Files\XML_SOAP</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Configuration</Filter>
</ClCompile>
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions BaseLibrary/LogAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ LogAnalysis::ReadConfig()
else break;
}
// Look for a comment
if(buffer[0] == ';' || buffer[0] == '#')
if(buffer[0] == ';' || buffer[0] == '#' || !buffer[0])
{
continue;
}
Expand All @@ -699,9 +699,9 @@ LogAnalysis::ReadConfig()
m_logFileName = &buffer[8];
continue;
}
if(_strnicmp(buffer,"loglevel=",8) == 0)
if(_strnicmp(buffer,"loglevel=",9) == 0)
{
int logLevel = atoi(&buffer[8]) > 0;
int logLevel = atoi(&buffer[9]);
SetLogLevel(logLevel);
continue;
}
Expand Down
21 changes: 20 additions & 1 deletion BaseLibrary/QueryReWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ static const char* all_tokens[] =
,"HAVING"
,"INTO"
,"UNION"
,"STATISTICS"
,"FOR"
};

// All registered SQL words including tokens and special registrations
Expand Down Expand Up @@ -334,21 +336,36 @@ QueryReWriter::ParseStatement(bool p_closingEscape /*= false*/)
odbc = true;
}

if(m_token == Token::TK_STATISTICS)
{
m_inStatement = m_token;
PrintToken();
continue;
}
if(m_token == Token::TK_FOR)
{
m_nextTable = false;
}

// Append schema
if(m_nextTable)
{
AppendSchema();
}

// Find next table for appending a schema
if(m_inStatement == Token::TK_SELECT && (m_token == Token::TK_FROM || m_token == Token::TK_JOIN))
if(m_inStatement == Token::TK_SELECT && (m_token == Token::TK_FROM || m_token == Token::TK_JOIN ))
{
m_nextTable = true;
if(m_token == Token::TK_FROM)
{
m_inFrom = true;
}
}
if(m_inStatement == Token::TK_STATISTICS && m_token == Token::TK_FOR)
{
m_nextTable = true;
}
if(m_inStatement == Token::TK_SELECT && m_inFrom && m_token == Token::TK_COMMA)
{
m_nextTable = true;
Expand Down Expand Up @@ -454,6 +471,8 @@ QueryReWriter::PrintToken()
case Token::TK_ORDER: [[fallthrough]];
case Token::TK_HAVING: [[fallthrough]];
case Token::TK_INTO: [[fallthrough]];
case Token::TK_STATISTICS:[[fallthrough]];
case Token::TK_FOR: [[fallthrough]];
case Token::TK_UNION: m_output += all_tokens[(int)m_token];
break;
case Token::TK_EOS: break;
Expand Down
3 changes: 3 additions & 0 deletions BaseLibrary/QueryReWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ enum class Token
,TK_HAVING
,TK_INTO
,TK_UNION
,TK_STATISTICS
,TK_FOR
};

enum class SROption
Expand Down Expand Up @@ -137,6 +139,7 @@ class QueryReWriter
void PrintOuterJoin();
Token FindToken();
void AppendSchema();

void SkipSpaceAndComment();
Token CommentSQL();
Token CommentCPP();
Expand Down
85 changes: 57 additions & 28 deletions BaseLibrary/Redirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <process.h>
#include <assert.h>
#include <time.h>
#include <corecrt_io.h>
#include <fcntl.h>

#ifdef _DEBUG
#define new DEBUG_NEW
Expand Down Expand Up @@ -67,9 +69,11 @@ Redirect::Redirect()
m_bRunThread = FALSE;
m_exitCode = 0;
m_eof_input = 0;
m_eof_error = 0;
m_timeoutChild = INFINITE;
m_timeoutIdle = MAXWAIT_FOR_INPUT_IDLE;
m_terminated = false;
m_bRunThread = TRUE;

InitializeCriticalSection((LPCRITICAL_SECTION)&m_critical);
}
Expand All @@ -94,6 +98,7 @@ Redirect::StartChildProcess(LPCSTR lpszCmdLine,UINT uShowChildWindow /*=SW_HIDE*
HANDLE hProcess = ::GetCurrentProcess();

m_eof_input = 0;
m_eof_error = 0;
m_exitCode = 0;

// Set up the security attributes struct.
Expand Down Expand Up @@ -155,6 +160,7 @@ Redirect::StartChildProcess(LPCSTR lpszCmdLine,UINT uShowChildWindow /*=SW_HIDE*

m_terminated = 1;
m_eof_input = 1;
m_eof_error = 1;

return FALSE;
}
Expand Down Expand Up @@ -220,7 +226,7 @@ Redirect::TerminateChildProcess()
m_bRunThread = FALSE;
::SetEvent(m_hExitEvent);

WaitForSingleObject(m_hProcessThread,3000);
WaitForSingleObject(m_hProcessThread,1000);
m_hProcessThread = NULL;
}

Expand Down Expand Up @@ -265,11 +271,23 @@ Redirect::TerminateChildProcess()
int maxWaittime = DRAIN_STDOUT_MAXWAIT;
while(maxWaittime >= 0)
{
Sleep(DRAIN_STDOUT_INTERVAL);
if(!m_hStdOutRead)
{
break;
}
Sleep(DRAIN_STDOUT_INTERVAL);
maxWaittime -= DRAIN_STDOUT_INTERVAL;
}

// Wait for the stderr to drain
maxWaittime = DRAIN_STDOUT_MAXWAIT;
while(maxWaittime >= 0)
{
if(!m_hStdErrRead)
{
break;
}
Sleep(DRAIN_STDOUT_INTERVAL);
maxWaittime -= DRAIN_STDOUT_INTERVAL;
}

Expand Down Expand Up @@ -396,41 +414,45 @@ Redirect::PrepAndLaunchRedirectedChild(LPCSTR lpszCmdLine
return pi.hProcess;
}

BOOL Redirect::m_bRunThread = TRUE;

// Thread to read the child stdout.
int
Redirect::StdOutThread(HANDLE hStdOutRead)
{
DWORD nBytesRead;
CHAR lpszBuffer[10];
CHAR lineBuffer[BUFFER_SIZE+10];
CHAR lineBuffer[BUFFER_SIZE + 10] = {0} ;
char* linePointer = lineBuffer;
// FOR DEBUGGING: See below
// int i = 0;

while(true)
{
nBytesRead = 0;
if(!::ReadFile(hStdOutRead, lpszBuffer, 1, &nBytesRead, NULL) || !nBytesRead)
if(!::ReadFile(hStdOutRead, lpszBuffer, 1, &nBytesRead, NULL) || !nBytesRead || lpszBuffer[0] == EOT)
{
if(::GetLastError() != ERROR_IO_PENDING)
// pipe done - normal exit path.
// Partial input line left hanging?
if(linePointer != lineBuffer)
{
// pipe done - normal exit path.
// Partial input line left hanging?
if(linePointer != lineBuffer)
{
*linePointer = 0;
OnChildStdOutWrite(lineBuffer);
}
m_eof_input = 1;
break;
*linePointer = 0;
OnChildStdOutWrite(lineBuffer);
}
m_eof_input = 1;
break;
}
// Add to line
*linePointer++ = lpszBuffer[0];

// Add end-of-line or line overflow, write to listener
if(lpszBuffer[0] == '\n' || ((linePointer - lineBuffer) > BUFFER_SIZE))
{
// USED FOR DEBUGGING PURPOSES ONLY!!
// So we can detect the draining of the standard output from the process
// if(i++ % 20 == 0)
// {
// Sleep(1);
// }

// Virtual function to notify derived class that
// characters are written to stdout.
*linePointer = 0;
Expand All @@ -449,35 +471,42 @@ Redirect::StdErrThread(HANDLE hStdErrRead)
{
DWORD nBytesRead;
CHAR lpszBuffer[10];
CHAR lineBuffer[BUFFER_SIZE + 1];
CHAR lineBuffer[BUFFER_SIZE + 10] = { 0 };
char* linePointer = lineBuffer;
// FOR DEBUGGING: See below
// int i = 0;

while(m_bRunThread)
{
if(!::ReadFile(hStdErrRead,lpszBuffer,1,&nBytesRead,NULL) || !nBytesRead)
if(!::ReadFile(hStdErrRead,lpszBuffer,1,&nBytesRead,NULL) || !nBytesRead || lpszBuffer[0] == EOT)
{
if(::GetLastError() != ERROR_IO_PENDING)
// pipe done - normal exit path.
// Partial input line left hanging?
if(linePointer != lineBuffer)
{
// pipe done - normal exit path.
// Partial input line left hanging?
if(linePointer != lineBuffer)
{
*linePointer = 0;
OnChildStdErrWrite(lineBuffer);
}
break;
*linePointer = 0;
OnChildStdErrWrite(lineBuffer);
}
m_eof_error = 1;
break;
}
// Add to line: caller sees stdout AND stderr alike
*linePointer++ = lpszBuffer[0];

// Add end-of-line or line overflow, write to listener
if(lpszBuffer[0] == '\n' || ((linePointer - lineBuffer) > BUFFER_SIZE))
{
// USED FOR DEBUGGING PURPOSES ONLY!!
// So we can detect the draining of the standard output from the process
// if(i++ % 20 == 0)
// {
// Sleep(1);
// }

// Virtual function to notify derived class that
// characters are written to stdout.
*linePointer = 0;
OnChildStdErrWrite(lpszBuffer);
OnChildStdErrWrite(lineBuffer);
linePointer = lineBuffer;
}
}
Expand Down
5 changes: 4 additions & 1 deletion BaseLibrary/Redirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
// After the process we must wait for the stdout to be completely read
#define DRAIN_STDOUT_MAXWAIT 10000
#define DRAIN_STDOUT_INTERVAL 50
// END-OF-TRANSMISSION is ASCII 4
#define EOT '\x4'

/////////////////////////////////////////////////////////////////////////////
// Redirect class
Expand Down Expand Up @@ -62,6 +64,7 @@ class Redirect

mutable int m_exitCode;
mutable int m_eof_input;
mutable int m_eof_error;
mutable int m_terminated;
protected:
HANDLE m_hExitEvent;
Expand All @@ -87,7 +90,7 @@ class Redirect
,UINT uShowChildWindow = SW_HIDE
,BOOL bWaitForInputIdle = FALSE);

static BOOL m_bRunThread;
BOOL m_bRunThread;
static unsigned int WINAPI staticStdOutThread(void* pRedirect)
{
Redirect* redir = reinterpret_cast<Redirect*>(pRedirect);
Expand Down
Loading

0 comments on commit 605608a

Please sign in to comment.