GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — main.cpp: added command-option "-is" to specify usage of std::istream… · cppcheck-opensource/simplecpp@dff9b46

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • main.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎main.cpp‎

Copy file name to clipboardExpand all lines: main.cpp
+17-5Lines 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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.