|
25 | 25 | int main(int argc, char **argv) |
26 | 26 | { |
27 | 27 | const char *filename = nullptr; |
| 28 | + bool use_istream = false; |
28 | 29 |
|
29 | 30 | // Settings.. |
30 | 31 | simplecpp::DUI dui; |
@@ -48,6 +49,8 @@ int main(int argc, char **argv) |
48 | 49 | case 'i': |
49 | 50 | if (std::strncmp(arg, "-include=",9)==0) |
50 | 51 | dui.includes.push_back(arg+9); |
| 52 | + else if (std::strncmp(arg, "-is",3)==0) |
| 53 | + use_istream = true; |
51 | 54 | break; |
52 | 55 | case 's': |
53 | 56 | if (std::strncmp(arg, "-std=",5)==0) |
@@ -66,20 +69,29 @@ int main(int argc, char **argv) |
66 | 69 | std::cout << " -IPATH Include path." << std::endl; |
67 | 70 | std::cout << " -include=FILE Include FILE." << std::endl; |
68 | 71 | std::cout << " -UNAME Undefine NAME." << std::endl; |
| 72 | + std::cout << " -is Use std::istream interface." << std::endl; |
69 | 73 | std::exit(0); |
70 | 74 | } |
71 | 75 |
|
72 | 76 | // Perform preprocessing |
73 | 77 | simplecpp::OutputList outputList; |
74 | 78 | 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); |
79 | 89 | for (std::pair<std::string, simplecpp::TokenList *> i : included) |
80 | 90 | i.second->removeComments(); |
81 | 91 | 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; |
83 | 95 |
|
84 | 96 | // Output |
85 | 97 | std::cout << outputTokens.stringify() << std::endl; |
|