aboutsummaryrefslogtreecommitdiffstats
path: root/debug.c
blob: b319b57417d384704f75c4047cc1989859722332 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "debug.h"

#ifdef NEED_DEBUG_HELPER
#include <stdio.h>
#include <time.h>
#include <sys/time.h>

void debug_print_time()
{
 struct timeval debug_tv;
 struct tm *debug_tm;
 char debug_buffer[10];

 gettimeofday(&debug_tv,NULL);
 debug_tm=localtime(&debug_tv.tv_sec);
 strftime(debug_buffer,10, "%T",debug_tm);
 fprintf(stderr,"%s.%06d: ",debug_buffer,(int)debug_tv.tv_usec);
}

#endif

#ifdef NEED_HEXDUMP_HELPER
#include <stdio.h>

void hexdump(unsigned char *data,int len)
{
 int count;
 int count2;
 int max;

 for(count=0;count<len;count+=16)
 {
#ifdef SET_DEBUG_PRINT_PREFIX
  fprintf(stderr,"%s",SET_DEBUG_PRINT_PREFIX);
#endif
  fprintf(stderr,"%04x  ",count);

  max=count+16;
  if (max>len) max=len;

  for(count2=count;count2<max;count2++)
  {
   if (count2%8==0) fprintf(stderr," ");
   fprintf(stderr,"%02x ",data[count2]);
  }

  if (max<count+16)
  {
   for(count2=max;count2<count+16;count2++)
   {
    if (count2%8==0) fprintf(stderr," ");
    fprintf(stderr,"   ");
   }
  }
  fprintf(stderr,"  ");

  for(count2=count;count2<max;count2++)
  {
   if (count2%8==0) fprintf(stderr," ");
   if ((data[count2]>=32) && (data[count2]<127))
   {
    fprintf(stderr,"%c",data[count2]);
   } else {
    fprintf(stderr,".");
   }
  }

  fprintf(stderr,"\n");
 }
}
#endif