Skip to content

Commit 892183e

Browse files
committed
main.cpp: added command-option "-is" to specify usage of std::istream interface in reading initial file
1 parent 95c747b commit 892183e

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

main.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
int main(int argc, char **argv)
2626
{
2727
bool error = false;
28+
const char *filename = nullptr;
29+
bool use_istream = false;
2830

2931
// Settings..
30-
const char *filename = nullptr;
3132
simplecpp::DUI dui;
3233
bool quiet = false;
3334
for (int i = 1; i < argc; i++) {
@@ -54,6 +55,10 @@ int main(int argc, char **argv)
5455
dui.includes.push_back(arg+9);
5556
found = true;
5657
}
58+
else if (std::strncmp(arg, "-is",3)==0) {
59+
use_istream = true;
60+
found = true;
61+
}
5762
break;
5863
case 's':
5964
if (std::strncmp(arg, "-std=",5)==0) {
@@ -87,20 +92,29 @@ int main(int argc, char **argv)
8792
std::cout << " -UNAME Undefine NAME." << std::endl;
8893
std::cout << " -std=STD Specify standard." << std::endl;
8994
std::cout << " -q Quiet mode (no output)." << std::endl;
95+
std::cout << " -is Use std::istream interface." << std::endl;
9096
std::exit(0);
9197
}
9298

9399
// Perform preprocessing
94100
simplecpp::OutputList outputList;
95101
std::vector<std::string> files;
96-
//std::ifstream f(filename);
97-
simplecpp::TokenList rawtokens(files,filename,&outputList);
98-
rawtokens.removeComments();
99-
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(rawtokens, files, dui, &outputList);
102+
simplecpp::TokenList *rawtokens;
103+
if (use_istream) {
104+
std::ifstream f(filename);
105+
rawtokens = new simplecpp::TokenList(f, files,filename,&outputList);
106+
}
107+
else {
108+
rawtokens = new simplecpp::TokenList(files,filename,&outputList);
109+
}
110+
rawtokens->removeComments();
111+
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(*rawtokens, files, dui, &outputList);
100112
for (std::pair<std::string, simplecpp::TokenList *> i : included)
101113
i.second->removeComments();
102114
simplecpp::TokenList outputTokens(files);
103-
simplecpp::preprocess(outputTokens, rawtokens, files, included, dui, &outputList);
115+
simplecpp::preprocess(outputTokens, *rawtokens, files, included, dui, &outputList);
116+
delete rawtokens;
117+
rawtokens = nullptr;
104118

105119
// Output
106120
if (!quiet) {

0 commit comments

Comments
 (0)