You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.3 KiB
138 lines
3.3 KiB
#include "dosdebug.h"
|
|
|
|
//extern unsigned _heaplen = 54321U;
|
|
#ifdef DEBUG_OUT_FILE
|
|
static FILE * DEBUG_FD = NULL;
|
|
#endif
|
|
static int DDcurrentIndent=0;
|
|
static int DDoldIndent = 0;
|
|
void debug( char *msg, ... ){
|
|
struct time t;
|
|
va_list valist;
|
|
char Format[256];
|
|
char Buffer[256];
|
|
|
|
sprintf( Format, "\n%%02d:%%02d:%%02d.%%02d " );
|
|
|
|
int la = strlen( Format );
|
|
for( int i=0; i < (DDcurrentIndent-1); i++) Format[la+i] = (char) 0xB3;
|
|
if( DDcurrentIndent ){
|
|
Format[la+i]=(char)0xC3;
|
|
Format[la+i+1]='%';
|
|
Format[la+i+2]='s';
|
|
Format[la+i+3]=(char)0x00;
|
|
} else {
|
|
Format[la+i]='%';
|
|
Format[la+i+1]='s';
|
|
Format[la+i+2]=(char)0x00;
|
|
};
|
|
gettime( &t );
|
|
sprintf( Buffer, Format, t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund, msg );
|
|
va_start( valist, msg );
|
|
vsprintf( Format, Buffer, valist );
|
|
va_end( valist );
|
|
for( i = strlen( Format ); i < 70; i++ ) Format[i]=(char)32;
|
|
Format[i] = (char) 0;
|
|
#ifdef DEBUG_OUT_FILE
|
|
DEBUG_FD = fopen( DEBUG_OUT_FILE ,"a+");
|
|
if( DEBUG_FD ){
|
|
fprintf( DEBUG_FD, Format );
|
|
fclose( DEBUG_FD );
|
|
DEBUG_FD = NULL;
|
|
};
|
|
#else
|
|
printf( Format );
|
|
#endif
|
|
};
|
|
|
|
void debugAddIndent( unsigned char i){
|
|
DDcurrentIndent+=i;
|
|
};
|
|
void debugDelIndent( unsigned char i){
|
|
DDcurrentIndent-=i;
|
|
};
|
|
void debugProcBegin( char *msg, ... ){
|
|
struct time t;
|
|
va_list valist;
|
|
char Format[256];
|
|
char Buffer[256];
|
|
sprintf( Format, "\n%%02d:%%02d:%%02d.%%02d " );
|
|
int la = strlen( Format );
|
|
for( int i=0; i < (DDcurrentIndent-1); i++) Format[la+i] = (char) 0xB3;
|
|
if( DDcurrentIndent ){
|
|
Format[la+i]=(char)0xC3;
|
|
Format[la+i+1]='%';
|
|
Format[la+i+2]='s';
|
|
Format[la+i+3]=(char)0x00;
|
|
} else {
|
|
Format[la+i]='%';
|
|
Format[la+i+1]='s';
|
|
Format[la+i+2]=(char)0x00;
|
|
};
|
|
gettime( &t );
|
|
sprintf( Buffer, Format, t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund, msg );
|
|
va_start( valist, msg );
|
|
vsprintf( Format, Buffer, valist );
|
|
va_end( valist );
|
|
for( i = strlen( Format ); i < 70; i++ ) Format[i]=(char)32;
|
|
Format[i] = (char) 0;
|
|
#ifdef DEBUG_OUT_FILE
|
|
DEBUG_FD = fopen( DEBUG_OUT_FILE ,"a+");
|
|
if( DEBUG_FD ){
|
|
fprintf( DEBUG_FD, Format );
|
|
fclose( DEBUG_FD );
|
|
DEBUG_FD = NULL;
|
|
};
|
|
#else
|
|
printf( Format );
|
|
#endif
|
|
debugAddIndent();
|
|
};
|
|
void debugProcEnd( unsigned char z){
|
|
debugDelIndent();
|
|
if( DDoldIndent <= DDcurrentIndent ){
|
|
if( z ) {
|
|
DEBUG_FD = fopen("c:\\debug.log","a+");
|
|
if( DEBUG_FD ){
|
|
fprintf( DEBUG_FD, "[OK]" );
|
|
fclose( DEBUG_FD );
|
|
DEBUG_FD = NULL;
|
|
};
|
|
} else {
|
|
DEBUG_FD = fopen("c:\\debug.log","a+");
|
|
if( DEBUG_FD ){
|
|
fprintf( DEBUG_FD, "[ERROR]" );
|
|
fclose( DEBUG_FD );
|
|
DEBUG_FD = NULL;
|
|
};
|
|
};
|
|
} else {
|
|
struct time t;
|
|
char Format[256];
|
|
char Buffer[256];
|
|
sprintf( Format, "\n%%02d:%%02d:%%02d.%%02d " );
|
|
int la = strlen( Format );
|
|
for( int i=0; i < DDcurrentIndent; i++) Format[la+i] = (char) 0xB3;
|
|
Format[la+i]=(char)0xC0;
|
|
Format[la+i+1]='%';
|
|
Format[la+i+2]='s';
|
|
Format[la+i+3]=(char)0x00;
|
|
gettime( &t );
|
|
if( z ) {
|
|
sprintf( Buffer, Format, t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund, "[OK]" );
|
|
} else {
|
|
sprintf( Buffer, Format, t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund, "[ERRROR]" );
|
|
};
|
|
#ifdef DEBUG_OUT_FILE
|
|
DEBUG_FD = fopen( DEBUG_OUT_FILE ,"a+");
|
|
if( DEBUG_FD ){
|
|
fprintf( DEBUG_FD, Buffer );
|
|
fclose( DEBUG_FD );
|
|
DEBUG_FD = NULL;
|
|
};
|
|
#else
|
|
printf( Buffer );
|
|
#endif
|
|
};
|
|
DDoldIndent = DDcurrentIndent;
|
|
};
|