Skip to content

added TokenList::Stream class to wrap std::istream usage and implemented alternative C I/O version #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Mar 2, 2023
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
097a765
added wrapper class "Stream" to TokenList
firewave Mar 5, 2022
c2ae449
moved some helper function into TokenList::Stream
firewave Mar 5, 2022
62acc58
simplified UTF-16 checks
firewave Mar 5, 2022
a2cc676
made simplecpp::TokenList::Stream an abstract class and moved impleme…
firewave Mar 5, 2022
07ec136
added simplecpp::TokenList::Stream implementation "FileStream" which …
firewave Mar 5, 2022
81fe8cd
use FileStream for includes as well
firewave Mar 5, 2022
4f0da78
constness
firewave Mar 5, 2022
1b52b22
made some TokenList::Stream members private
firewave Mar 5, 2022
95c747b
pulled out repeated UTF-16 character generation code
firewave Mar 5, 2022
892183e
main.cpp: added command-option "-is" to specify usage of std::istream…
firewave Mar 9, 2022
26ccd24
test.cpp: got rid of another `std::istringstream` usage
firewave Apr 14, 2022
e57f312
fixed FileStream::unget() with subsequent calls (i.e. UTF-16 encoding)
firewave Apr 19, 2022
bdc7f3c
simplified newline handling in TokenList::Stream::readChar()
firewave Apr 19, 2022
76b94e3
fixed handling of incomplete UTF-8 BOM 0xefbbbf
firewave Apr 19, 2022
cd084ae
test.cpp: added tests for incomplete UTF sequences
firewave Apr 19, 2022
797f899
keep lastCh intact when using FileStream::peek()
firewave Apr 20, 2022
c1da435
fixed uninitialized members in `FileStream`
firewave Oct 6, 2022
52b4b61
.clang-tidy: disabled `modernize-use-override` warning
firewave Oct 6, 2022
7ff8c98
fixed `readability-inconsistent-declaration-parameter-name` clean-tid…
firewave Oct 6, 2022
c9605fe
fixed `-Wshadow` Clang compiler warning
firewave Oct 6, 2022
557099c
adjusted parameter order in added `TokenList()` constructor / added s…
firewave Feb 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
main.cpp: added command-option "-is" to specify usage of std::istream…
… interface in reading initial file
  • Loading branch information
firewave committed Feb 25, 2023
commit 892183ecbdf32ae2be55d2032905c5ab9e757c9b
26 changes: 20 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
int main(int argc, char **argv)
{
bool error = false;
const char *filename = nullptr;
bool use_istream = false;

// Settings..
const char *filename = nullptr;
simplecpp::DUI dui;
bool quiet = false;
for (int i = 1; i < argc; i++) {
Expand All @@ -54,6 +55,10 @@ int main(int argc, char **argv)
dui.includes.push_back(arg+9);
found = true;
}
else if (std::strncmp(arg, "-is",3)==0) {
use_istream = true;
found = true;
}
break;
case 's':
if (std::strncmp(arg, "-std=",5)==0) {
Expand Down Expand Up @@ -87,20 +92,29 @@ int main(int argc, char **argv)
std::cout << " -UNAME Undefine NAME." << std::endl;
std::cout << " -std=STD Specify standard." << std::endl;
std::cout << " -q Quiet mode (no output)." << 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
if (!quiet) {
Expand Down