16進ログ
4330 ワード
struct {
char name[32];
char address[64];
char userid[9];
char uclass[31];
int age;
double income;
double deposit;
} table;
/*
** , HexLog 。
*/
strcpy(table.name , " 1");
strcpy(table.address, " 32 ");
strcpy(table.userid , "99876");
strcpy(table.uclass , " ");
table.age = 32;
table.income = 3618.90;
table.deposit = 10239.51;
set_logRunLevel(LOGDEBUG);
set_logStyle(0);
wLog(LOGDEBUG, "====== table ============");
wLog(LOGDEBUG, "table.name = [%s]", table.name);
wLog(LOGDEBUG, "table.address= [%s]", table.address);
wLog(LOGDEBUG, "table.userid = [%s]", table.userid);
wLog(LOGDEBUG, "table.uclass = [%s]", table.uclass);
wLog(LOGDEBUG, "table.age = [%d]", table.age );
wLog(LOGDEBUG, "table.income = [%.2f]", table.income);
wLog(LOGDEBUG, "table.deposit= [%.2f]", table.deposit);
wLog(LOGWARN, "====== table ==========");
wHex(LOGWARN, &table, sizeof(table), " %s ", "table");
restore_logStyle();
これは構造データを印刷するログです.以下は対応するログの印刷効果です.
[WARN ][ ] style[20]
[DEBUG]====== table ============
[DEBUG]table.name = [ 1]
[DEBUG]table.address= [ 32 ]
[DEBUG]table.userid = [99876]
[DEBUG]table.uclass = [ ]
[DEBUG]table.age = [32]
[DEBUG]table.income = [3618.90]
[DEBUG]table.deposit= [10239.51]
[WARN ]====== table ==========
########[testlog.c][43] [FUNC]-=-=-=-=- ( table ) (156) ########
+ 01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17-18-19-20 + ====== ASCII ====== +
000001: b2 e2 ca d4 c8 cb d4 b1 31 00 00 00 20 00 00 00 e0 9a fb 4c | 1... ... ? |
000021: 00 00 00 00 f4 9f fb 4c 03 00 00 00 b6 ab b3 c7 b4 f3 bd d6 | .... .... |
000041: 33 32 ba c5 00 f2 04 08 e0 e5 04 08 00 00 00 00 28 c1 ee bf | 32 .?. ......( ?|
000061: 03 00 00 00 07 00 00 00 03 00 00 00 b3 a4 04 08 03 00 00 00 | ............ ...... |
000081: c0 d5 04 08 25 00 00 00 10 e9 04 08 d0 e8 04 08 39 39 38 37 | ..%....?. ..998. |
000101: 36 00 00 00 00 d6 d0 ce c4 d7 a8 d2 b5 00 ff ff 00 00 00 00 | ..... ..... |
000121: e4 ca 50 54 9f 88 09 00 18 00 00 00 09 00 00 00 20 00 00 00 | PT .......... ... |
000141: cd cc cc cc cc 45 ac 40 7b 14 ae 47 c1 ff c3 40 | {. ? |
+ ----------------------------------------------------------- + -------------------- +
上記のログデータでは、各行に20文字が表示され、ユーザーがデータの位置付けを容易にするとともに、右側のASCII方式で表示され、漢字の問題を比較的よく処理し、多くの漢字が見られる.
以下、具体的なプログラム実装
#define HEXLEN 20 /* */
struct HEXBUF
{
int point; /* */
int chn ; /* */
char scop[ 6 + 1 ]; /* */
char sstr[ 20 + 1 ]; /* ASCII */
char shex[ 61 + 1 ]; /* */
} ;
/*
**
*/
void HexBuf_init(struct HEXBUF *p )
{
p->point = 0;
memset(p->scop, 0x0 , sizeof(p->scop));
memset(p->sstr, 0x20, HEXLEN );
memset(p->shex, 0x20, HEXLEN*3 );
return ;
}
/*
**
*/
int printHexLog( void *PInfo, char *Title, int mLen)
{
int cnt; //
int point ;
char temp[5];
unsigned char *ptr = (unsigned char *) PInfo ;
struct HEXBUF hex;
memset(&hex, 0x0, sizeof(hex));
printf( "%25s------- %s (%d) -------
", "", Title, mLen);
HexBuf_init(&hex);
for( cnt = 0; cnt < mLen ; cnt ++, ptr ++ )
{
if(hex.point && (cnt % HEXLEN) == 0 )
{
hex.chn = hex.chn & 0x01;
if( hex.chn ) hex.sstr[HEXLEN-1]='.';
printf("%s: %s | %s |
", hex.scop, hex.shex, hex.sstr);
HexBuf_init( &hex );
}
if(hex.point == 0 )
sprintf(hex.scop, "%04d", cnt );
point = hex.point;
if( (*ptr) < 0x20 ) hex.sstr[point] = '.';
else {
if(point == 0 && hex.chn )
{
hex.chn = 0;
hex.sstr[0] = '.';
}
else
{
hex.sstr[point] = (*ptr);
if( (*ptr & 0x80) == 0x80 ) hex.chn ++ ;
}
}
point *= 3;
sprintf(temp, "%02x ", (*ptr & 0xff ) );
memcpy(hex.shex + point , temp, 3);
hex.point ++;
}
if( hex.point )
printf("%s: %s | %s |
", hex.scop, hex.shex, hex.sstr);
printf("%25s------- End -------
", "");
return 0 ;
}