Skip to content

Commit 108d80a

Browse files
committed
main.cpp: added command-option "-is" to specify usage of std::istream interface in reading initial file
1 parent 312233f commit 108d80a

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

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;
@@ -49,6 +50,8 @@ int main(int argc, char **argv)
4950
case 'i':
5051
if (std::strncmp(arg, "-include=",9)==0)
5152
dui.includes.push_back(arg+9);
53+
else if (std::strncmp(arg, "-is",3)==0)
54+
use_istream = true;
5255
break;
5356
case 's':
5457
if (std::strncmp(arg, "-std=",5)==0)
@@ -72,20 +75,29 @@ int main(int argc, char **argv)
7275
std::cout << " -UNAME Undefine NAME." << std::endl;
7376
std::cout << " -std=STD Specify standard." << std::endl;
7477
std::cout << " -q Quiet mode (no output)." << std::endl;
78+
std::cout << " -is Use std::istream interface." << std::endl;
7579
std::exit(0);
7680
}
7781

7882
// Perform preprocessing
7983
simplecpp::OutputList outputList;
8084
std::vector<std::string> files;
81-
//std::ifstream f(filename);
82-
simplecpp::TokenList rawtokens(files,filename,&outputList);
83-
rawtokens.removeComments();
84-
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(rawtokens, files, dui, &outputList);
85+
simplecpp::TokenList *rawtokens;
86+
if (use_istream) {
87+
std::ifstream f(filename);
88+
rawtokens = new simplecpp::TokenList(f, files,filename,&outputList);
89+
}
90+
else {
91+
rawtokens = new simplecpp::TokenList(files,filename,&outputList);
92+
}
93+
rawtokens->removeComments();
94+
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(*rawtokens, files, dui, &outputList);
8595
for (std::pair<std::string, simplecpp::TokenList *> i : included)
8696
i.second->removeComments();
8797
simplecpp::TokenList outputTokens(files);
88-
simplecpp::preprocess(outputTokens, rawtokens, files, included, dui, &outputList);
98+
simplecpp::preprocess(outputTokens, *rawtokens, files, included, dui, &outputList);
99+
delete rawtokens;
100+
rawtokens = nullptr;
89101

90102
// Output
91103
if (!quiet) {

0 commit comments

Comments
 (0)