From dff9b4698f2c5bd769f0ea8775e7296ac1e4792f Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 9 Mar 2022 11:41:22 +0100 Subject: [PATCH] main.cpp: added command-option "-is" to specify usage of std::istream interface in reading initial file --- main.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index da420d1e..08c089b5 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,7 @@ int main(int argc, char **argv) { const char *filename = nullptr; + bool use_istream = false; // Settings.. simplecpp::DUI dui; @@ -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) @@ -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 files; - //std::ifstream f(filename); - simplecpp::TokenList rawtokens(files,filename,&outputList); - rawtokens.removeComments(); - std::map 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 included = simplecpp::load(*rawtokens, files, dui, &outputList); for (std::pair 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;