64 lines
1.5 KiB
C++
64 lines
1.5 KiB
C++
/*
|
|
* LogCore.cpp
|
|
*
|
|
* Created on: 17 May 2016
|
|
* Author: wentzelc
|
|
*/
|
|
|
|
// redA Libraries
|
|
#include "LogCore.h"
|
|
|
|
// Standard C/C++ Libraries
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool ShowOutput( const char * Heading, const short Show, const char * Buffer, int Len )
|
|
{
|
|
// Validate values
|
|
if (!Buffer)
|
|
return false;
|
|
if (Len == -1)
|
|
Len = strlen( Buffer );
|
|
|
|
// Show Hex output
|
|
if (Show & OUT_HEX) {
|
|
printf( "%s [%d]: ", Heading, Len );
|
|
for (int i=0; i<Len; i++) {
|
|
printf( "%02X ", Buffer[i] );
|
|
}
|
|
printf( "\n" );
|
|
}
|
|
|
|
// Show normal output
|
|
if (Show & OUT_NORMAL) {
|
|
printf( "%s [%d]: ", Heading, Len );
|
|
if (Show & OUT_ASIS) {
|
|
printf( "%s", Buffer );
|
|
}
|
|
else {
|
|
for (int i=0; i<Len; i++) {
|
|
if ((Buffer[i] < 32) || (Buffer[i] > 126)) {
|
|
if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n')))
|
|
printf( "%c", Buffer[i] );
|
|
else
|
|
printf( "." );
|
|
}
|
|
else {
|
|
printf( "%c", Buffer[i] );
|
|
}
|
|
}
|
|
}
|
|
if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) {
|
|
printf( "\n" );
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|