Skip to content

Commit dff9b46

Browse files
committed
main.cpp: added command-option "-is" to specify usage of std::istream interface in reading initial file
1 parent 967bcf3 commit dff9b46

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

main.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
int main(int argc, char **argv)
2626
{
2727
const char *filename = nullptr;
28+
bool use_istream = false;
2829

2930
// Settings..
3031
simplecpp::DUI dui;
@@ -48,6 +49,8 @@ int main(int argc, char **argv)
4849
case 'i':
4950
if (std::strncmp(arg, "-include=",9)==0)
5051
dui.includes.push_back(arg+9);
52+
else if (std::strncmp(arg, "-is",3)==0)
53+
use_istream = true;
5154
break;
5255
case 's':
5356
if (std::strncmp(arg, "-std=",5)==0)
@@ -66,20 +69,29 @@ int main(int argc, char **argv)
6669
std::cout << " -IPATH Include path." << std::endl;
6770
std::cout << " -include=FILE Include FILE." << std::endl;
6871
std::cout << " -UNAME Undefine NAME." << std::endl;
72+
std::cout << " -is Use std::istream interface." << std::endl;
6973
std::exit(0);
7074
}
7175

7276
// Perform preprocessing
7377
simplecpp::OutputList outputList;
7478
std::vector<std::string> files;
75-
//std::ifstream f(filename);
76-
simplecpp::TokenList rawtokens(files,filename,&outputList);
77-
rawtokens.removeComments();
78-
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(rawtokens, files, dui, &outputList);
79+
simplecpp::TokenList *rawtokens;
80+
if (use_istream) {
81+
std::ifstream f(filename);
82+
rawtokens = new simplecpp::TokenList(f, files,filename,&outputList);
83+
}
84+
else {
85+
rawtokens = new simplecpp::TokenList(files,filename,&outputList);
86+
}
87+
rawtokens->removeComments();
88+
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(*rawtokens, files, dui, &outputList);
7989
for (std::pair<std::string, simplecpp::TokenList *> i : included)
8090
i.second->removeComments();
8191
simplecpp::TokenList outputTokens(files);
82-
simplecpp::preprocess(outputTokens, rawtokens, files, included, dui, &outputList);
92+
simplecpp::preprocess(outputTokens, *rawtokens, files, included, dui, &outputList);
93+
delete rawtokens;
94+
rawtokens = nullptr;
8395

8496
// Output
8597
std::cout << outputTokens.stringify() << std::endl;

0 commit comments

Comments
 (0)