forked from redxu/sihook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
145 lines (133 loc) · 2.49 KB
/
utils.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
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
#include <string.h>
#include "utils.h"
//输出调试信息
void WINAPI OutputDebugStringEx(LPCTSTR lpcFormatText, ...)
{
char szBuffer[1024];
va_list argptr;
va_start(argptr, lpcFormatText);
wvsprintf(szBuffer, lpcFormatText, argptr);
va_end(argptr);
OutputDebugString(szBuffer);
}
//获取短标题
char* GetSiSwTitle(const char* lpc,char* title)
{
int i,len;
int skip_flag;
int index;
skip_flag=0;
i = index = 0;
len = strlen(lpc);
while(i<len)
{
if(lpc[i] == '(')
{
skip_flag = 1;
}
else if(lpc[i] == ')')
{
skip_flag = 0;
i++;
continue;
}
if(skip_flag == 0)
{
title[index++] = lpc[i];
}
i++;
}
title[index] = '\0';
return title;
}
static const char* strstri(const char* str,const char* subStr)
{
int len = strlen(subStr);
if(len == 0)
{
return NULL;
}
while(*str)
{
if(strncasecmp(str, subStr, len) == 0)
{
return str;
}
++str;
}
return NULL;
}
//获取文件类型
//0 无类型默认
//1 *.c *.cpp *.cxx *.cs
//2 *.h *.hpp *.hxx *.inc
//3 *.txt *.text *.doc
//4 *.php *.php3 *.htm *.js
//5 *.pas *.vb *.pb *.vbs
int GetColorIndex(const char* filename)
{
const char *p = NULL;
//type 1
p = strstri(filename,".c");
if(p != NULL)
return 1;
p = strstri(filename,".cpp");
if(p != NULL)
return 1;
p = strstri(filename,".cxx");
if(p != NULL)
return 1;
p = strstri(filename,".cs");
if(p != NULL)
return 1;
//type 2
p = strstri(filename,".h");
if(p != NULL)
return 2;
p = strstri(filename,".hpp");
if(p != NULL)
return 2;
p = strstri(filename,".hxx");
if(p != NULL)
return 2;
p = strstri(filename,".inc");
if(p != NULL)
return 2;
//type 3
p = strstri(filename,".txt");
if(p != NULL)
return 3;
p = strstri(filename,".text");
if(p != NULL)
return 3;
p = strstri(filename,".doc");
if(p != NULL)
return 3;
//type 4
p = strstri(filename,".php");
if(p != NULL)
return 4;
p = strstri(filename,".php3");
if(p != NULL)
return 4;
p = strstri(filename,".htm");
if(p != NULL)
return 4;
p = strstri(filename,".js");
if(p != NULL)
return 4;
//type 5
p = strstri(filename,".pas");
if(p != NULL)
return 5;
p = strstri(filename,".pb");
if(p != NULL)
return 5;
p = strstri(filename,".vbs");
if(p != NULL)
return 5;
p = strstri(filename,".vb");
if(p != NULL)
return 5;
return 0;
}