Skip to content
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

s/t/bamtools_filter.cpp: simplify GetScriptContents(). #238

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
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
16 changes: 6 additions & 10 deletions src/toolkit/bamtools_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,22 +540,18 @@ const std::string FilterTool::FilterToolPrivate::GetScriptContents()
// read in entire script contents
char buffer[1024];
std::ostringstream docStream;
while (true) {

// peek ahead, make sure there is data available
char ch = fgetc(inFile);
ungetc(ch, inFile);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man this is terrible code

if (feof(inFile)) {
while (!feof(inFile)) {
// read next block of data
char *data = fgets(buffer, 1024, inFile);
if (data == 0) {
break;
}

// read next block of data
if (fgets(buffer, 1024, inFile) == 0) {
if (ferror(inFile)) {
std::cerr << "bamtools filter ERROR: could not read script contents" << std::endl;
return std::string();
}

docStream << buffer;
docStream << data;
}

// close script file
Expand Down