CharBuffer search fixed & Log/Util buffer changed:
- Char/ShiftBuffer: Fixed multi-char string search
- UtilCore: Always pass output buffer & remove own buffer for conversions
- UtilCore: Remove optional parameters to force passing of buffer
- LogCore: Add TempBuffer for output conversion (using UtilCore)
- ApplicationCore: Allow setting size of TempBuffer via config
- Optimize use of {}
This commit is contained in:
82
LogCore.cpp
82
LogCore.cpp
@@ -17,28 +17,44 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Global vars
|
||||
char LogStr[10000]; // Temporary var to create log messages, globally available to save on memory operations
|
||||
|
||||
const char * LogOutputName[] = { "None", "Raw", "Normal", "Hex", "Bin" };
|
||||
const char * LogOutputName[] = { "None", "Raw", "Normal", "Hex", "Bin" };
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CLogCore::CLogCore( FILE * pOutputFile )
|
||||
CLogCore::CLogCore( FILE * pOutputFile, int pBufferSize )
|
||||
{
|
||||
OutputFile = pOutputFile;
|
||||
BufferSize = pBufferSize;
|
||||
TempBuffer = (char*)malloc( BufferSize * sizeof(char) );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int CLogCore::ReadLogBufSize( CDataMember * LogConfig )
|
||||
{
|
||||
int NewBufSize;
|
||||
|
||||
// Get buffer size
|
||||
NewBufSize = LogConfig->GetChInt( "BufferSize", BufferSize, true );
|
||||
|
||||
// Update buffer if size different
|
||||
if ((NewBufSize > 0) && (NewBufSize != BufferSize)) {
|
||||
free( TempBuffer );
|
||||
BufferSize = NewBufSize;
|
||||
TempBuffer = (char*)malloc( BufferSize * sizeof(char) );
|
||||
}
|
||||
return BufferSize;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
EDebugLevel CLogCore::ReadLogLevel( CDataMember * LogConfig )
|
||||
{
|
||||
char * TempStr;
|
||||
const char * TempStr;
|
||||
EDebugLevel LogLevel;
|
||||
|
||||
// Get debug level
|
||||
LogLevel = dlNone;
|
||||
TempStr = (char*)LogConfig->GetChStr( "Level", "Medium", true );
|
||||
if (TempStr)
|
||||
{
|
||||
TempStr = LogConfig->GetChStr( "Level", "Medium", true );
|
||||
if (TempStr) {
|
||||
if (!strcasecmp( TempStr, "None" ))
|
||||
LogLevel = dlNone;
|
||||
else if (!strcasecmp( TempStr, "Low" ))
|
||||
@@ -58,16 +74,15 @@ EDebugLevel CLogCore::ReadLogLevel( CDataMember * LogConfig )
|
||||
int CLogCore::ReadLogOutput( CDataMember * LogConfig )
|
||||
{
|
||||
CDataMember * ItemConfig;
|
||||
char * TempStr;
|
||||
const char * TempStr;
|
||||
|
||||
ELogOutput LogOutput = loNone;
|
||||
int LogOutOpt = 0;
|
||||
|
||||
// Get Output format
|
||||
LogOutput = loNone;
|
||||
TempStr = (char*)LogConfig->GetChStr( "Output", "Normal", true );
|
||||
if (TempStr)
|
||||
{
|
||||
TempStr = LogConfig->GetChStr( "Output", "Normal", true );
|
||||
if (TempStr) {
|
||||
if (!strcasecmp( TempStr, "None" )) // Do not print output (may use option OUT_COUNT)
|
||||
LogOutput = loNone;
|
||||
else if (!strcasecmp( TempStr, "Raw" )) // Print all output as is
|
||||
@@ -84,10 +99,8 @@ int CLogCore::ReadLogOutput( CDataMember * LogConfig )
|
||||
|
||||
// Set debug output
|
||||
ItemConfig = LogConfig->GetChElement( "Options", 0, true );
|
||||
while (ItemConfig)
|
||||
{
|
||||
if ((TempStr = (char*)ItemConfig->GetStr( "Normal" )))
|
||||
{
|
||||
while (ItemConfig) {
|
||||
if ((TempStr = (char*)ItemConfig->GetStr( "Normal" ))) {
|
||||
if (!strcasecmp( TempStr, "Count" )) // Print number of characters
|
||||
LogOutOpt |= OUT_COUNT;
|
||||
else if (!strcasecmp( TempStr, "NoCRLF" )) // With Normal, replace CR/LF with "."
|
||||
@@ -111,14 +124,12 @@ bool CLogCore::Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char
|
||||
return false;
|
||||
|
||||
// Check debug level
|
||||
if (!OutputFile || (MsgLevel > DebugLevel)) {
|
||||
if (!OutputFile || (MsgLevel > DebugLevel))
|
||||
return true;
|
||||
}
|
||||
|
||||
// Show Date & Time
|
||||
if (OutputFile->_fileno > 3) {
|
||||
if (OutputFile->_fileno > 3)
|
||||
fprintf( OutputFile, "%s", GetDateTimeStr( "/", ":" ));
|
||||
}
|
||||
|
||||
// Print formated message
|
||||
va_start( ArgPtr, Format );
|
||||
@@ -141,18 +152,16 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
||||
return false;
|
||||
|
||||
// Check debug level
|
||||
if (!OutputFile || (MsgLevel > DebugLevel)) {
|
||||
if (!OutputFile || (MsgLevel > DebugLevel))
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get length
|
||||
if (Len == -1)
|
||||
Len = strlen( Buffer );
|
||||
|
||||
// Show date & time
|
||||
if (OutputFile->_fileno > 3) {
|
||||
if (OutputFile->_fileno > 3)
|
||||
fprintf( OutputFile, "%s", GetDateTimeStr( "/", ":" ));
|
||||
}
|
||||
|
||||
// Show Lead
|
||||
if (Format && *Format) {
|
||||
@@ -162,39 +171,32 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
||||
}
|
||||
|
||||
// Show byte count
|
||||
if (ShowCount)
|
||||
{
|
||||
// Print byte count
|
||||
if (ShowCount) {
|
||||
fprintf( OutputFile, " [%d] ", Len );
|
||||
if (!OutFormat) fprintf( OutputFile, "\n" ); // EOL if only count wanted
|
||||
}
|
||||
|
||||
// Show output
|
||||
if (OutFormat == loRaw)
|
||||
{
|
||||
if (OutFormat == loRaw) {
|
||||
// Print entire buffer as is (line feeds included)
|
||||
fprintf( OutputFile, "%.*s\n", Len, Buffer );
|
||||
}
|
||||
else if (OutFormat == loNormal)
|
||||
{
|
||||
else if (OutFormat == loNormal) {
|
||||
// Remove special char
|
||||
fprintf( OutputFile, "%s", BytesToSafeStr(Buffer, Len, NoCrLf, '.') );
|
||||
fprintf( OutputFile, "%s", BytesToSafeStr(Buffer, Len, NoCrLf, '.', TempBuffer) );
|
||||
|
||||
// Add EOL if not present or ignored
|
||||
if (NoCrLf || (Buffer[Len-1] != '\n')) {
|
||||
if (NoCrLf || (Buffer[Len-1] != '\n'))
|
||||
fprintf( OutputFile, "\n" );
|
||||
}
|
||||
}
|
||||
else if (OutFormat == loHex)
|
||||
{
|
||||
else if (OutFormat == loHex) {
|
||||
// Print Hex values of individual bytes
|
||||
fprintf( OutputFile, "%s", BytesToHexStr(Buffer, Len, " ") );
|
||||
fprintf( OutputFile, "%s", BytesToHexStr(Buffer, Len, " ", TempBuffer) );
|
||||
fprintf( OutputFile, "\n" );
|
||||
}
|
||||
else if (OutFormat == loBin)
|
||||
{
|
||||
else if (OutFormat == loBin) {
|
||||
// Print each byte as 8-bit binary
|
||||
fprintf( OutputFile, "%s", BytesToBinStr(Buffer, Len, " ") );
|
||||
fprintf( OutputFile, "%s", BytesToBinStr(Buffer, Len, " ", TempBuffer) );
|
||||
fprintf( OutputFile, "\n" );
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user