Skip to content

Commit 4b4263c

Browse files
author
Oleg Sesov
committed
[main.cpp] added flag '-C' to keep comments
1 parent 0f7d8f0 commit 4b4263c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int main(int argc, char **argv)
1818
bool error = false;
1919
const char *filename = nullptr;
2020
bool use_istream = false;
21+
bool keep_comments = false;
2122

2223
// Settings..
2324
simplecpp::DUI dui;
@@ -70,6 +71,10 @@ int main(int argc, char **argv)
7071
error_only = true;
7172
found = true;
7273
break;
74+
case 'C':
75+
keep_comments = true;
76+
found = true;
77+
break;
7378
}
7479
if (!found) {
7580
std::cout << "error: option '" << arg << "' is unknown." << std::endl;
@@ -102,10 +107,11 @@ int main(int argc, char **argv)
102107
std::cout << " -q Quiet mode (no output)." << std::endl;
103108
std::cout << " -is Use std::istream interface." << std::endl;
104109
std::cout << " -e Output errors only." << std::endl;
110+
std::cout << " -C Keep comments." << std::endl;
105111
std::exit(0);
106112
}
107113

108-
dui.removeComments = true;
114+
dui.removeComments = !keep_comments;
109115

110116
// Perform preprocessing
111117
simplecpp::OutputList outputList;
@@ -121,7 +127,8 @@ int main(int argc, char **argv)
121127
} else {
122128
rawtokens = new simplecpp::TokenList(filename,files,&outputList);
123129
}
124-
rawtokens->removeComments();
130+
if (!keep_comments)
131+
rawtokens->removeComments();
125132
simplecpp::TokenList outputTokens(files);
126133
std::map<std::string, simplecpp::TokenList*> filedata;
127134
simplecpp::preprocess(outputTokens, *rawtokens, files, filedata, dui, &outputList);

0 commit comments

Comments
 (0)