From 08cf048f2a8ed0fa096f2c82e147b61ffc480e2a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 17 Nov 2015 01:21:00 -0800 Subject: 2454 Another gotcha uncovered in the process of sorting out the previous commit: I keep using eof() but forgetting that there are two other states an istream can get into. Just never use eof(). --- 011load.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to '011load.cc') diff --git a/011load.cc b/011load.cc index b318e88a..578e2b46 100644 --- a/011load.cc +++ b/011load.cc @@ -19,9 +19,9 @@ vector load(string form) { vector load(istream& in) { in >> std::noskipws; vector result; - while (!in.eof()) { + while (has_data(in)) { skip_whitespace_and_comments(in); - if (in.eof()) break; + if (!has_data(in)) break; string command = next_word(in); // Command Handlers if (command == "recipe") { @@ -82,25 +82,25 @@ void slurp_body(istream& in, recipe& result) { bool next_instruction(istream& in, instruction* curr) { curr->clear(); - if (in.eof()) { + if (!has_data(in)) { raise_error << "0: unbalanced '[' for recipe\n" << end(); return false; } skip_whitespace(in); - if (in.eof()) { + if (!has_data(in)) { raise_error << "1: unbalanced '[' for recipe\n" << end(); return false; } skip_whitespace_and_comments(in); - if (in.eof()) { + if (!has_data(in)) { raise_error << "2: unbalanced '[' for recipe\n" << end(); return false; } vector words; - while (in.peek() != '\n' && !in.eof()) { + while (has_data(in) && in.peek() != '\n') { skip_whitespace(in); - if (in.eof()) { + if (!has_data(in)) { raise_error << "3: unbalanced '[' for recipe\n" << end(); return false; } @@ -117,7 +117,7 @@ bool next_instruction(istream& in, instruction* curr) { curr->is_label = true; curr->label = words.at(0); trace(9993, "parse") << "label: " << curr->label << end(); - if (in.eof()) { + if (!has_data(in)) { raise_error << "7: unbalanced '[' for recipe\n" << end(); return false; } @@ -151,7 +151,7 @@ bool next_instruction(istream& in, instruction* curr) { for (vector::iterator p = curr->products.begin(); p != curr->products.end(); ++p) { trace(9993, "parse") << " product: " << p->to_string() << end(); } - if (in.eof()) { + if (!has_data(in)) { raise_error << "9: unbalanced '[' for recipe\n" << end(); return false; } @@ -176,7 +176,7 @@ string Ignore(","); // meaningless except within [] strings :(code) void slurp_word(istream& in, ostream& out) { char c; - if (!in.eof() && Terminators.find(in.peek()) != string::npos) { + if (has_data(in) && Terminators.find(in.peek()) != string::npos) { in >> c; out << c; return; @@ -198,7 +198,7 @@ void skip_ignored_characters(istream& in) { void skip_whitespace_and_comments(istream& in) { while (true) { - if (in.eof()) break; + if (!has_data(in)) break; if (isspace(in.peek())) in.get(); else if (in.peek() == ',') in.get(); else if (in.peek() == '#') skip_comment(in); @@ -207,9 +207,9 @@ void skip_whitespace_and_comments(istream& in) { } void skip_comment(istream& in) { - if (!in.eof() && in.peek() == '#') { + if (has_data(in) && in.peek() == '#') { in.get(); - while (!in.eof() && in.peek() != '\n') in.get(); + while (has_data(in) && in.peek() != '\n') in.get(); } } -- cgit 1.4.1-2-gfad0