-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcppparse.cpp
More file actions
executable file
·58 lines (47 loc) · 1.16 KB
/
cppparse.cpp
File metadata and controls
executable file
·58 lines (47 loc) · 1.16 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
#include "cppparse.h"
CppParser::CppParser() {
ifstream keyFile("keywords/cpp.kwd");
char keyword[MAX_KEYWORD];
int i = 0;
while(keyFile >> keyword) {
keyWords[i] = new char[MAX_KEYWORD];
strcpy((char*)keyWords[i], (const char*)keyword);
i++;
KEYWORDS++;
}
}
void CppParser::handle_multiline_comment(ifstream& inFile, ofstream& outFile) {
char ch;
outFile << "<font color=\"green\">";
outFile << "/*";
while(inFile.get(ch)) {
outFile << ch; // normal char
if(ch == '*') {
while(inFile.get(ch) && ch == '*')
outFile << ch;
if(ch == '/') {
outFile << ch;
outFile << "</font>";
break;
}
}
}
}
void CppParser::handle_single_comment(ifstream& inFile, ofstream& outFile) {
char ch;
outFile << "<font color=\"green\">";
outFile << "//";
while(inFile.get(ch) && ch != '\n')
outFile.put(ch);
outFile << "</font><br>\n";
}
int main(int argc, char* argv[]) {
if (argc < 2) {
cout << "Usage: " << argv[0] << " <filename>" << endl;
return 1;
}
CppParser* cpp = new CppParser();
cpp->parse(argv[1]);
delete cpp;
return 0;
}