37 # pragma warning(disable : 4996) 131 cDBG(
bool flag=
false,
char const* color=
"red", std::ostream *fd=&std::cerr )
136 mywidth = output->width();
172 debug_color = GetColor( color );
173 if ( !strcmp( debug_color,
"" ) )
175 normal_color = debug_color;
178 normal_color = GetColor(
"normal" );
204 if (!debug_flag)
return;
209 va_start( arglist, fmt );
211 vsnprintf_s( buffer, 256, 256, fmt, arglist );
213 vsnprintf( buffer, 256, fmt, arglist );
217 *output << debug_color << buffer << normal_color << std::flush;
232 char const* GetColor(
char const* c )
234 char* sdh_no_color = getenv(
"SDH_NO_COLOR" );
235 if ( sdh_no_color !=
NULL )
238 char* os = getenv(
"OS" );
239 char* ostype = getenv(
"OSTYPE" );
240 if ( os && (!strncmp( os,
"WIN", 3 ) || !strncmp( os,
"Win", 3 )) && (! ostype || (ostype && strcmp( ostype,
"cygwin" ))) )
243 if ( !strcmp( c,
"normal" ) )
return "\x1b[0m";
244 if ( !strcmp( c,
"bold" ) )
return "\x1b[1m";
245 if ( !strcmp( c,
"red" ) )
return "\x1b[31m";
246 if ( !strcmp( c,
"green" ) )
return "\x1b[32m";
247 if ( !strcmp( c,
"yellow" ) )
return "\x1b[33m";
248 if ( !strcmp( c,
"blue" ) )
return "\x1b[34m";
249 if ( !strcmp( c,
"magenta" ) )
return "\x1b[35m";
250 if ( !strcmp( c,
"cyan" ) )
return "\x1b[36m";
251 if ( !strcmp( c,
"white" ) )
return "\x1b[37m";
252 if ( !strcmp( c,
"black" ) )
return "\x1b[39m";
253 if ( !strcmp( c,
"black_back" ) )
return "\x1b[40m";
254 if ( !strcmp( c,
"red_back" ) )
return "\x1b[41m";
255 if ( !strcmp( c,
"green_back" ) )
return "\x1b[42m";
256 if ( !strcmp( c,
"yellow_back" ) )
return "\x1b[43m";
257 if ( !strcmp( c,
"blue_back" ) )
return "\x1b[44m";
258 if ( !strcmp( c,
"cyan_back" ) )
return "\x1b[45m";
259 if ( !strcmp( c,
"magenta_back" ) )
return "\x1b[46m";
260 if ( !strcmp( c,
"white_back" ) )
return "\x1b[47m";
273 template <
typename T>
276 if (!debug_flag)
return *
this;
279 *output << debug_color;
280 output->width( mywidth );
282 mywidth = output->width();
284 *output << normal_color << std::flush;
291 return output->flush();
309 # define VAR( _d, _var ) \ 310 (_d) << #_var << "='" << _var << "'\n" 324 # define VAL( _var ) \ 325 #_var << "='" << _var << "' " 348 bool is_all_printable_ascii =
true;
349 for (
int i = 0; i < s.
len; i++ )
351 stream << std::hex << std::setw(2) << std::setfill(
'0') << int( ((
unsigned char const*)s.
bytes)[i] ) <<
" ";
352 if ( s.
bytes[i] < 0x20 || ((
unsigned char) s.
bytes[i]) >= 0x80 )
353 is_all_printable_ascii =
false;
359 if ( is_all_printable_ascii && s.
len >= 0 )
360 stream <<
"= \"" << std::string( s.
bytes, s.
len ) <<
"\"";
363 return stream << std::dec;
void SetColor(char const *color)
A class to print colored debug messages.
VCC_EXPORT std::ostream & operator<<(std::ostream &stream, cHexByteString const &s)
output the bytes in s to stream as a list of space separated hex bytes (without 0x prefix) ...
cDBG(bool flag=false, char const *color="red", std::ostream *fd=&std::cerr)
cHexByteString(char const *_bytes, int _len)
ctor: create a cHexByteString with _len bytes at _bytes
void SetOutput(std::ostream *fd)
dummy class for (debug) stream output of bytes as list of hex values
#define NAMESPACE_SDH_START
*output<< debug_color<< buffer<< normal_color<< std::flush;}char const *GetColor(char const *c){char *sdh_no_color=getenv("SDH_NO_COLOR");if(sdh_no_color!=NULL) return"";char *os=getenv("OS");char *ostype=getenv("OSTYPE");if(os &&(!strncmp(os,"WIN", 3)||!strncmp(os,"Win", 3))&&(!ostype||(ostype &&strcmp(ostype,"cygwin")))) return"";if(!strcmp(c,"normal")) return"\x1b[0m";if(!strcmp(c,"bold")) return"\x1b[1m";if(!strcmp(c,"red")) return"\x1b[31m";if(!strcmp(c,"green")) return"\x1b[32m";if(!strcmp(c,"yellow")) return"\x1b[33m";if(!strcmp(c,"blue")) return"\x1b[34m";if(!strcmp(c,"magenta")) return"\x1b[35m";if(!strcmp(c,"cyan")) return"\x1b[36m";if(!strcmp(c,"white")) return"\x1b[37m";if(!strcmp(c,"black")) return"\x1b[39m";if(!strcmp(c,"black_back")) return"\x1b[40m";if(!strcmp(c,"red_back")) return"\x1b[41m";if(!strcmp(c,"green_back")) return"\x1b[42m";if(!strcmp(c,"yellow_back")) return"\x1b[43m";if(!strcmp(c,"blue_back")) return"\x1b[44m";if(!strcmp(c,"cyan_back")) return"\x1b[45m";if(!strcmp(c,"magenta_back")) return"\x1b[46m";if(!strcmp(c,"white_back")) return"\x1b[47m";return"";}template< typename T > cDBG & operator<<(T const &v)
#define SDH__attribute__(...)
#define NAMESPACE_SDH_END
This file contains settings to make the SDHLibrary compile on differen systems:
char const * normal_color