about summary refs log tree commit diff stats
path: root/011load.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-17 01:21:00 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-17 01:21:00 -0800
commit08cf048f2a8ed0fa096f2c82e147b61ffc480e2a (patch)
tree80493ca241c9172e21df76cedb98312af6de8113 /011load.cc
parent21c277062ef151ad86e2003ad0e2bfb09f3d4c2d (diff)
downloadmu-08cf048f2a8ed0fa096f2c82e147b61ffc480e2a.tar.gz
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().
Diffstat (limited to '011load.cc')
-rw-r--r--011load.cc26
1 files changed, 13 insertions, 13 deletions
diff --git a/011load.cc b/011load.cc
index b318e88a..578e2b46 100644
--- a/011load.cc
+++ b/011load.cc
@@ -19,9 +19,9 @@ vector<recipe_ordinal> load(string form) {
 vector<recipe_ordinal> load(istream& in) {
   in >> std::noskipws;
   vector<recipe_ordinal> 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<string> 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<reagent>::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();
   }
 }