Skip to content

Commit

Permalink
main.cpp: added command-option "-is" to specify usage of std::istream…
Browse files Browse the repository at this point in the history
… interface in reading initial file
  • Loading branch information
firewave committed Mar 9, 2022
1 parent 967bcf3 commit dff9b46
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
int main(int argc, char **argv)
{
const char *filename = nullptr;
bool use_istream = false;

// Settings..
simplecpp::DUI dui;
Expand All @@ -48,6 +49,8 @@ int main(int argc, char **argv)
case 'i':
if (std::strncmp(arg, "-include=",9)==0)
dui.includes.push_back(arg+9);
else if (std::strncmp(arg, "-is",3)==0)
use_istream = true;
break;
case 's':
if (std::strncmp(arg, "-std=",5)==0)
Expand All @@ -66,20 +69,29 @@ int main(int argc, char **argv)
std::cout << " -IPATH Include path." << std::endl;
std::cout << " -include=FILE Include FILE." << std::endl;
std::cout << " -UNAME Undefine NAME." << std::endl;
std::cout << " -is Use std::istream interface." << std::endl;
std::exit(0);
}

// Perform preprocessing
simplecpp::OutputList outputList;
std::vector<std::string> files;
//std::ifstream f(filename);
simplecpp::TokenList rawtokens(files,filename,&outputList);
rawtokens.removeComments();
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(rawtokens, files, dui, &outputList);
simplecpp::TokenList *rawtokens;
if (use_istream) {
std::ifstream f(filename);
rawtokens = new simplecpp::TokenList(f, files,filename,&outputList);
}
else {
rawtokens = new simplecpp::TokenList(files,filename,&outputList);
}
rawtokens->removeComments();
std::map<std::string, simplecpp::TokenList*> included = simplecpp::load(*rawtokens, files, dui, &outputList);
for (std::pair<std::string, simplecpp::TokenList *> i : included)
i.second->removeComments();
simplecpp::TokenList outputTokens(files);
simplecpp::preprocess(outputTokens, rawtokens, files, included, dui, &outputList);
simplecpp::preprocess(outputTokens, *rawtokens, files, included, dui, &outputList);
delete rawtokens;
rawtokens = nullptr;

// Output
std::cout << outputTokens.stringify() << std::endl;
Expand Down

0 comments on commit dff9b46

Please sign in to comment.