-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·85 lines (69 loc) · 1.83 KB
/
main.cpp
File metadata and controls
executable file
·85 lines (69 loc) · 1.83 KB
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
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "split.h"
#include "analysis.h"
using namespace std;
void dumpWordVector(Meta_Vector & wordVector)
{
// dump wordVector
for(size_t i=0; i<wordVector.size(); i++)
{
printf("[%3d:%2d] type %d, word[%d]:%s\n", wordVector[i].line, wordVector[i].pos,
wordVector[i].type, wordVector[i].len, wordVector[i].data);
}
}
void freeWordVector(Meta_Vector & wordVector)
{
// free wordVector data
for(size_t i=0; i<wordVector.size(); i++)
{
free(wordVector[i].data);
}
wordVector.clear();
}
int main(int argc, char * argv[])
{
Meta_Vector wordVector;
wordVector.clear();
// const char * str = " if ( (parser->flags & SKIP_SP) && (*c == ' ' || *c == '\\t'))";
// const char * str = " HTTP_TOKEN1 = 0,// must be 0";
// const char * str = " a /= 3; // must be 0";
// const char * str = " a /= 3; ////// must be 0";
// const char * str = "typedef vector< pair<char *,int> > Meta_Vector;";
char * lineData = NULL;
size_t lineLen = 0;
ssize_t read;
int lineOffset = -1, lineNum = 0;
if (argc > 2){
lineOffset = atoi(argv[2]);
}
FILE * fp = fopen(argv[1], "r");
if(!fp)
{
printf("open file failed!\n");
return -1;
}
while ((read = getline(&lineData, &lineLen, fp)) != -1)
{
lineNum++;
if (lineNum < lineOffset){
continue;
}
split(lineData, read, lineNum, wordVector);
#ifdef _DEBUG
dumpWordVector(wordVector);
freeWordVector(wordVector);
getchar();
#endif
}
if (lineData)
free(lineData);
// dump
// dumpWordVector(wordVector);
analysis(wordVector);
freeWordVector(wordVector);
fclose(fp);
return 0;
}