/
entry.cpp
57 lines (44 loc) · 976 Bytes
/
entry.cpp
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
#include "acsm.h"
/*
* Text Data Buffer
*/
unsigned char text[MAXLEN];
extern int nline;
int main(int argc, char **argv)
{
int i, nocase = 0;
FILE *fd;
char filename[20];
ACSM_STRUCT * acsm;
// if (argc < 3)
// {
// fprintf(stderr, "Usage: acsmx filename pattern1 pattern2 ... -nocase\n");
// exit(0);
// }
acsm = acsmNew();
strcpy_s(filename, "test.txt");
fd = fopen(filename, "r");
if (fd == NULL)
{
fprintf(stderr, "Open file error!\n");
exit(1);
}
for (i = 1; i < argc; i++)
if (strcmp(argv[i], "-nocase") == 0)
nocase = 1;
char a[] = { "test" };
acsmAddPattern(acsm, (unsigned char *)a, strlen(a), nocase);
/* Generate GtoTo Table and Fail Table */
acsmCompile(acsm);
/*Search Pattern*/
while (fgets(( char*)text, MAXLEN, fd))
{
acsmSearch(acsm, text, strlen((char*)text), PrintMatch);
nline++;
}
PrintSummary(acsm->acsmPatterns);
acsmFree(acsm);
printf("\n### AC Match Finished ###\n");
system("pause");
return (0);
}