about summary refs log tree commit diff stats
path: root/089scenario_filesystem.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-08-20 18:51:35 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-08-20 18:51:35 -0700
commit18261f194d34d6d8aa2f359052796c4f6d373c1b (patch)
tree238719fbc95476dcde46f4a6ebb7290971bba456 /089scenario_filesystem.cc
parentebea4c3f4a3aed3bb0f6c16edd1d44eea965ca6b (diff)
downloadmu-18261f194d34d6d8aa2f359052796c4f6d373c1b.tar.gz
3232
Support pipe characters in fake files. Still super ugly, though.
Diffstat (limited to '089scenario_filesystem.cc')
-rw-r--r--089scenario_filesystem.cc35
1 files changed, 34 insertions, 1 deletions
diff --git a/089scenario_filesystem.cc b/089scenario_filesystem.cc
index 0c3d1202..120d30b7 100644
--- a/089scenario_filesystem.cc
+++ b/089scenario_filesystem.cc
@@ -49,6 +49,33 @@ de f
   ]
 ]
 
+:(scenario escaping_file_contents)
+scenario assume-filesystem [
+  local-scope
+  assume-filesystem [
+    # file 'a' containing a '|'
+    # ugly as hell that this requires 8 (!) backslashes for 3 '[' block escapes
+    # todo: use Sam Putman's idea to change the delimitors for the '[' blocks
+    # to:
+    #   [''[ ... ['[ ... [ ... ] ... ]'] ... ]'']
+    # That way we'd need just a single backslash -- to escape the |...| environment.
+    [a] <- [
+      |x\\\\\\\\|yz|
+    ]
+  ]
+  data:address:array:file-mapping <- get *filesystem:address:filesystem, data:offset
+  file1:file-mapping <- index *data, 0
+  file1-name:address:array:character <- get file1, name:offset
+  10:array:character/raw <- copy *file1-name
+  file1-contents:address:array:character <- get file1, contents:offset
+  20:array:character/raw <- copy *file1-contents
+  memory-should-contain [
+    10:array:character <- [a]
+    20:array:character <- [x|yz
+]
+  ]
+]
+
 :(before "End Globals")
 const int FILESYSTEM = Next_predefined_global_for_scenarios++;
 //: give 'filesystem' a fixed location in scenarios
@@ -148,8 +175,14 @@ string munge_filesystem_contents(const string& data, const string& filename, con
     string line;
     getline(in, line);
     for (int i = 0; i < SIZE(line); ++i) {
-      // todo: handle escaped '|'
       if (line.at(i) == '|') break;
+      if (line.at(i) == '\\') {
+        ++i;  // skip
+        if (i == SIZE(line)) {
+          raise << caller << ": assume-filesystem: file contents can't end a line with '\\'\n" << end();
+          break;
+        }
+      }
       out << line.at(i);
     }
     // todo: some way to represent a file without a final newline