@@ -36,130 +36,146 @@ int main(int argc, char* argv[])
3636
3737 if (fileC.is_open ())
3838 {
39+ bool readComment = false ;
40+ string temp = " " ;
3941 while (!fileC.eof ())
4042 {
4143 string stringLanguageC = " " ;
42- string temp = " " ;
4344 getline (fileC, stringLanguageC);
4445 for (unsigned int i = 0 ; i < stringLanguageC.length (); i++)
4546 {
4647 if (isServiceSymbols ((int )stringLanguageC[i]) == true )
4748 continue ;
48-
49- if (isSeparators ((int )stringLanguageC[i]) == true && temp[0 ] != ' \" ' )
49+ if (isComment ((int )stringLanguageC[i], (int )stringLanguageC[i + 1 ]) == true )
50+ readComment = true ;
51+ if (readComment == false && isOneStringComment ((int )stringLanguageC[i], (int )stringLanguageC[i + 1 ]) == true )
5052 {
51- if (temp.length () != 0 )
52- fileAnalysis << getCodeWord (temp) << " " ;
53- temp = stringLanguageC[i];
54- fileAnalysis << getCodeWord (temp) << " " ;
53+ string temp2 = " " ;
54+ temp2.assign (stringLanguageC, i, stringLanguageC.length () - i);
55+ fileAnalysis << temp2 << " " ;
56+ break ;
57+ }
58+ if (readComment == true && isComment ((int )stringLanguageC[i + 1 ], (int )stringLanguageC[i]) == true )
59+ {
60+ readComment = false ;
61+ temp += stringLanguageC[i];
62+ temp += stringLanguageC[i + 1 ];
63+ if (temp != " \0 " && temp!= " /**/" )
64+ fileAnalysis << temp << " " ;
5565 temp = " " ;
66+ i++;
5667 continue ;
68+
5769 }
58-
59- // <library.h> and "string"
60- if (stringLanguageC[i] == ' <' || stringLanguageC[i] == ' \" ' )
70+
71+ if (readComment == false )
6172 {
62- int posClose = 0 ;
63- int countSymbols = 0 ;
64- if (stringLanguageC[i] == ' <' )
65- posClose = stringLanguageC.find (" >" , 1 );
66- else
67- posClose = stringLanguageC.rfind (' \" ' );
68-
69- if (posClose != -1 )
73+ if (isSeparators ((int )stringLanguageC[i]) == true && temp[0 ] != ' \" ' )
7074 {
71- countSymbols = posClose + 1 - i;
72- temp.assign (stringLanguageC, i, countSymbols);
73- if (temp.find (" .h" ) != -1 )
74- {
75+ if (temp.length () != 0 )
7576 fileAnalysis << getCodeWord (temp) << " " ;
76- temp = " " ;
77- if (stringLanguageC[posClose + 1 ] == ' \0 ' )
78- break ;
79- else
80- i = posClose;
81- }
77+ temp = stringLanguageC[i];
78+ fileAnalysis << getCodeWord (temp) << " " ;
79+ temp = " " ;
80+ continue ;
81+ }
82+
83+ // <library.h> and "string"
84+ if (stringLanguageC[i] == ' <' || stringLanguageC[i] == ' \" ' )
85+ {
86+ int posClose = 0 ;
87+ int countSymbols = 0 ;
88+ if (stringLanguageC[i] == ' <' )
89+ posClose = stringLanguageC.find (" >" , 1 );
8290 else
91+ posClose = stringLanguageC.rfind (' \" ' );
92+
93+ if (posClose != -1 )
8394 {
84- if (temp[0 ] == ' \" ' )
95+ countSymbols = posClose + 1 - i;
96+ temp.assign (stringLanguageC, i, countSymbols);
97+ if (temp.find (" .h" ) != -1 )
8598 {
8699 fileAnalysis << getCodeWord (temp) << " " ;
87- i = posClose;
100+ temp = " " ;
101+ if (stringLanguageC[posClose + 1 ] == ' \0 ' )
102+ break ;
103+ else
104+ i = posClose;
105+ }
106+ else
107+ {
108+ if (temp[0 ] == ' \" ' )
109+ {
110+ fileAnalysis << getCodeWord (temp) << " " ;
111+ i = posClose;
88112
113+ }
89114 }
115+ temp = " " ;
90116 }
91- temp = " " ;
92- // continue;
93117 }
94- }
95118
96- if (isOperation (stringLanguageC, i) == true || isLogicalOperation (stringLanguageC, i) == true )
97- {
98- if (isIncrement (stringLanguageC, i) == true || isDoubleOperation (stringLanguageC, i) == true )
119+ if (isOperation (stringLanguageC, i) == true || isLogicalOperation (stringLanguageC, i) == true )
99120 {
121+ if (isIncrement (stringLanguageC, i) == true || isDoubleOperation (stringLanguageC, i) == true )
122+ {
123+ temp += stringLanguageC[i];
124+ i++;
125+ }
100126 temp += stringLanguageC[i];
101- i++;
127+ fileAnalysis << getCodeWord (temp) << " " ;
128+ temp = " " ;
129+ continue ;
102130 }
103- temp += stringLanguageC[i];
104- fileAnalysis << getCodeWord (temp) << " " ;
105- temp = " " ;
106- continue ;
107- }
108-
109- if (stringLanguageC[i] != ' ' )
110- {
111- if (isLetter ((int )stringLanguageC[i]) == true && (isLetter ((int )stringLanguageC[i+1 ])==false && isDigit ((int )stringLanguageC[i+1 ])==false ))
131+
132+ if (stringLanguageC[i] != ' ' )
112133 {
113- /* if (temp[0] == '\"' )
134+ if (isLetter (( int )stringLanguageC[i]) == true && ( isLetter (( int )stringLanguageC[i + 1 ]) == false && isDigit (( int )stringLanguageC[i + 1 ]) == false ) )
114135 {
115- if (stringLanguageC[i] == '\"' && stringLanguageC[i + 1] == ' ' && stringLanguageC[i + 1] == '\0')
116- {
117- temp += stringLanguageC[i];
118- fileAnalysis << getCodeWord(temp) << " ";
119- temp = "";
120- continue;
121- }
122- else
136+
137+ temp += stringLanguageC[i];
138+ fileAnalysis << getCodeWord (temp) << " " ;
139+ temp = " " ;
140+ continue ;
141+ }
142+ else
143+ {
144+ if (stringLanguageC[i] == ' #' )
123145 {
124146 temp += stringLanguageC[i];
125147 continue ;
126148 }
149+
127150 }
128- else
129- {*/
130- temp += stringLanguageC[i];
131- fileAnalysis << getCodeWord (temp) << " " ;
132- temp = " " ;
133- continue ;
134-
151+ temp += stringLanguageC[i];
135152 }
136153 else
137154 {
138- if (stringLanguageC[i] == ' #' )
139- {
140- temp += stringLanguageC[i];
155+ if (temp == " \0 " )
141156 continue ;
157+ else
158+ {
159+ fileAnalysis << getCodeWord (temp) << " " ;
160+ temp = " " ;
142161 }
143-
144162 }
145- temp += stringLanguageC[i];
146163 }
147164 else
148165 {
149- if (temp == " \0 " )
150- continue ;
151- else
152- {
153- fileAnalysis << getCodeWord (temp) << " " ;
154- temp = " " ;
155- }
166+ temp += stringLanguageC[i];
156167 }
168+
157169 }
158170 if (temp != " \0 " )
159171 {
160- fileAnalysis << getCodeWord (temp);
172+ if (readComment == false )
173+ fileAnalysis << getCodeWord (temp);
174+ else
175+ temp += ' \n ' ;
161176 }
162- fileAnalysis << " \n " ;
177+ if (readComment==false )
178+ fileAnalysis << " \n " ;
163179 }
164180 }
165181
0 commit comments