Skip to content

Commit 8926c28

Browse files
committed
save space string on wordVecto
1 parent 7f62828 commit 8926c28

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

analysis.cpp

+31-29
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ void getIncludeFiles(Meta_Vector & wordVector, size_t index)
1212
char headerStr[256] = {'\0'};
1313

1414
// #include <string.h> or #include <vector>
15-
if (index + 4 >= wordVector.size() || wordVector[index+4].line != curLine){
15+
if (index + 5 >= wordVector.size() || wordVector[index+5].line != curLine){
1616
printf("not a full header include statement [%d, %d].\n", (int)index, (int)wordVector.size());
1717
return ;
1818
}
1919

20-
if (wordVector[index+2].data[0] == '\"'){
20+
if (wordVector[index+3].data[0] == '\"'){
2121
headerType = TYPE_USER;
2222
}
23-
else if (wordVector[index+2].data[0] == '<'){
23+
else if (wordVector[index+3].data[0] == '<'){
2424
headerType = TYPE_SYSTEM;
2525
}
2626
else{
27-
printf("not a valid header include statement [%s].\n", wordVector[index+2].data);
27+
printf("not a valid header include statement [%s].\n", wordVector[index+3].data);
2828
return;
2929
}
3030

31-
// skip '#' and "include" and header type char '"' or '<'
32-
for(size_t i=index+3; i < wordVector.size(); i++)
31+
// skip '#', "include", space and header type char '"' or '<'
32+
for(size_t i=index+4; i < wordVector.size(); i++)
3333
{
3434
if (wordVector[i].line != wordVector[index].line)
3535
break;
@@ -66,37 +66,38 @@ void getDefine(Meta_Vector & wordVector, size_t index)
6666
char defineStr[256] = {'\0'};
6767

6868
// #define A a or just #define A
69-
if (index + 2 >= wordVector.size() || wordVector[index+2].line != curLine){
69+
if (index + 3 >= wordVector.size() || wordVector[index+3].line != curLine){
7070
printf("not a full define statement [%d, %d].\n", (int)index, (int)wordVector.size());
7171
return ;
7272
}
7373

74-
if (wordVector[index+3].line != curLine) {
75-
if (wordVector[index+2].type == TYPE_WORD){
76-
printf("Line %d is a NULL constant define: %s\n", curLine, wordVector[index+2].data);
74+
if (wordVector[index+4].line != curLine) {
75+
if (wordVector[index+3].type == TYPE_WORD){
76+
printf("Line %d is a NULL constant define: %s\n", curLine, wordVector[index+3].data);
7777
return ;
7878
}
7979
else
80-
printf("not a valid header include statement [%s].\n", wordVector[index+2].data);
80+
printf("not a valid define statement [%s].\n", wordVector[index+2].data);
8181
}
8282
else{
83-
if (wordVector[index+2].data[0] == '('){
83+
if (wordVector[index+3].data[0] == '('){
8484
defineType = TYPE_FUNCTION;
8585
}
86-
else if (wordVector[index+2].type == TYPE_WORD){
86+
else if (wordVector[index+3].type == TYPE_WORD){
8787
defineType = TYPE_CONSTANT;
8888
}
8989
else{
90-
printf("not a valid header include statement [%s].\n", wordVector[index+2].data);
90+
printf("not a valid define statement [%s].\n", wordVector[index+3].data);
9191
return;
9292
}
9393
}
9494

9595
if (defineType == TYPE_CONSTANT){
96+
int defineStrLen = 0;
97+
bool addSpace = false;
9698

97-
int lastPos = -1, defineStrLen = 0;
98-
// skip '#' and "define" and constant define
99-
for(size_t i=index+3; i < wordVector.size(); i++)
99+
// skip '#', "define", space, constant define and space
100+
for(size_t i=index+5; i < wordVector.size(); i++)
100101
{
101102
if (wordVector[i].line != wordVector[index].line)
102103
break;
@@ -106,24 +107,25 @@ void getDefine(Meta_Vector & wordVector, size_t index)
106107
break;
107108
}
108109

109-
if (lastPos == -1){
110-
lastPos = wordVector[i].pos;
110+
if (wordVector[i].type == TYPE_SPACE){
111+
if (addSpace == false) {
112+
addSpace = true;
113+
}
111114
}
115+
else{
116+
if (addSpace == true) {
117+
addSpace = false;
118+
strcat(defineStr, wordVector[i-1].data);
119+
defineStrLen += wordVector[i-1].len;
120+
}
112121

113-
// FIXME: should save space string on wordVector
114-
if (lastPos != wordVector[i].pos) {
115-
memset(defineStr + defineStrLen, 0x20, wordVector[i].pos - lastPos);
116-
defineStrLen += wordVector[i].pos - lastPos;
122+
strcat(defineStr, wordVector[i].data);
123+
defineStrLen += wordVector[i].len;
117124
}
118-
119-
strcat(defineStr, wordVector[i].data);
120-
121-
lastPos = wordVector[i].pos + wordVector[i].len;
122-
defineStrLen += wordVector[i].len;
123125
}
124126

125127
printf("Line %d is a constant define: %s, value is %s, len is %d\n", curLine,
126-
wordVector[index+2].data, defineStr, defineStrLen);
128+
wordVector[index+3].data, defineStr, defineStrLen);
127129
}
128130
}
129131

split.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ void split(const char * data, int datalen, int line, Meta_Vector & wordVector)
5858

5959
else if (isspace(c)){
6060
CHECK_LAST_TYPE(TYPE_SPACE);
61+
if (c == ' ' || c == '\t')
62+
word[wordlen++] = c;
6163
}
6264
else{
6365
CHECK_LAST_TYPE(TYPE_SPECIAL);

0 commit comments

Comments
 (0)