-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.c
71 lines (54 loc) · 1.22 KB
/
util.c
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 <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <windows.h>
#include "common.h"
#include "util.h"
#define _TRACE_WHITE_ " "
#define _TRACE_TRAIL_ 60
#ifdef _TRACE_
void __trace_at_out(const char* buff)
{
printf(">%s\n\r", buff);
}
void __trace_at_in(const char* buff, int len)
{
printf("<%.*s", len, buff);
}
void __trace_log(const char* format, ...)
{
va_list arg;
va_start(arg, format);
char buff[256];
_vsprintf_l(buff, format, NULL, arg);
va_end(arg);
printf("\n\r%.*s%s\n\r", _TRACE_TRAIL_, _TRACE_WHITE_, buff);
}
#else
void __trace_at_out(const char* buff) {}
void __trace_at_in(const char* buff, int len) {}
void __trace_log(const char* buff, ...) {}
#endif
static short is_space(char c)
{
return c == '\n' || c == '\r' || c == ' ';
}
void strtrim(const char *src, char* dest)
{
char *end;
// Trim leading space
while (is_space(*src)) src++;
if (*src == 0) // All spaces?
{
return;
}
// Trim trailing space
end = (char*)src + strlen(src) - 1;
while (end > src && is_space(*end)) end--;
strncpy(dest, src, end - src + 1);
dest[end - src + 1] = 0;
}
void sleep(int millis)
{
Sleep(millis);
}