about summary refs log tree commit diff stats
path: root/subx/022transform_immediate.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-10 20:23:14 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-10 20:26:35 -0700
commit5e2e2eb5da2bcbb0d4e485ecc73bb9697afa1bac (patch)
tree4ec0401ec4aba95afc3ca780ff882720a92e2381 /subx/022transform_immediate.cc
parentced962dbf8ac4ad6616c1b3573f268a83a925c8b (diff)
downloadmu-5e2e2eb5da2bcbb0d4e485ecc73bb9697afa1bac.tar.gz
4337
Return to the usual whitespace-skipping istreams. No need to go beyond
word-based parsing.

This exercise reinforces the amount of duplication between
load_program() and transform_immediate().
Diffstat (limited to 'subx/022transform_immediate.cc')
-rw-r--r--subx/022transform_immediate.cc28
1 files changed, 20 insertions, 8 deletions
diff --git a/subx/022transform_immediate.cc b/subx/022transform_immediate.cc
index eefe9a40..48f5dfa9 100644
--- a/subx/022transform_immediate.cc
+++ b/subx/022transform_immediate.cc
@@ -23,17 +23,29 @@ Transform.push_back(transform_immediate);
 :(code)
 void transform_immediate(const string& input, string& output) {
   istringstream in(input);
-  in >> std::noskipws;
   ostringstream out;
   while (has_data(in)) {
-    string word = next_word(in);
-    if (word.find("/imm") == string::npos)
-      out << word << ' ';
-    else {
-      string output = transform_immediate(word);
-      trace("translate") << "converting '" << word << "' to '" << output << "'" << end();
-      out << output << ' ';
+    string line_data;
+    getline(in, line_data);
+    istringstream line(line_data);
+    while (has_data(line)) {
+      string word;
+      line >> word;
+      if (word.empty()) continue;
+      if (word[0] == '#') {
+        // skip comment
+        break;
+      }
+      if (word.find("/imm") == string::npos) {
+        out << word << ' ';
+      }
+      else {
+        string output = transform_immediate(word);
+        trace("translate") << "converting '" << word << "' to '" << output << "'" << end();
+        out << output << ' ';
+      }
     }
+    out << '\n';
   }
   out.str().swap(output);
 }