-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace_debug.h
154 lines (107 loc) · 2.4 KB
/
trace_debug.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//#define __DEBUG__ // debug log dump
#ifdef __DEBUG__
#define trace DoTrace
#define trace1 DoTrace
#else
#define trace
#define trace1
#define __TRACE_DEBUG__
#endif
#include "stdlib.h"
static inline void DoTrace(char *fmt, ...);
static void fileappend( char* filename, char* buf);
#ifndef __TRACE_DEBUG__
#define __TRACE_DEBUG__
/* {{{ trace */
static inline void DoTrace(char *fmt, ...)
{
va_list ap;
char buf[4096];
//sprintf(buf, "T=%08x ", tsrm_thread_id());
//OutputDebugString(buf);
//fileappend("c:\\phpdebuglog.txt", buf);
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
OutputDebugString(buf);
fileappend("c:\\phpdebuglog.txt", buf);
va_end(ap);
}
/* }}} */
#endif // __TRACE_DEBUG__
#ifndef __STRING_TRIM__
#define __STRING_TRIM__
static void trim(char * src)
{
unsigned int i = 0;
char *begin = src;
for(i = 0; i < strlen(src) ; i++){
if(src[i] != 0x20){
break;
}else{
begin++;
}
}
trace1("\r\n %s src=%d, begin= %d", src, src, begin);
for(i = strlen(src)-1; i >= 0; i--){
if(src[i] != 0x20){
break;
}else{
src[i] = '\0';
}
}
for(i = 0; i < strlen(begin); i++){
src[i] = begin[i];
}
src[i] = 0x00;
return ;
}
static char* replace(char* src,char* seps)
{
char* token=NULL;
char * buf;
int len = strlen(src);
buf = (char*)malloc(len);
memset(buf,0,len);
/* Establish string and get the first token: */
token = strtok(src, seps);
while( token != NULL )
{
/* While there are tokens in "string" */
strcat(buf,token);
/* Get next token: */
token = strtok( NULL, seps );
}
strcpy(src,buf);
free(buf);
return src;
}
static char* getfilecontents( char* filename, char* buf, unsigned int len)
{
FILE *fp;
fp=fopen(filename,"r");
if(fp==NULL)
{
return NULL;
}
char line[128];
memset(buf,0, len);
while(!feof(fp))
{
fgets(line,128,fp);
if(strlen(buf) +strlen(line) >= len) break;
strcat(buf,line);
}
return buf;
}
static void fileappend( char* filename, char* buf)
{
FILE *fp;
fp=fopen(filename,"a");
if(fp!=NULL)
{
//fwrite( buf, strlen(buf),1, fp);
fputs(buf,fp) ;
fclose(fp);
}
}
#endif // __STRING_TRIM__