diff options
| author | RogueAI42 <[email protected]> | 2017-06-19 17:43:53 +1000 |
|---|---|---|
| committer | RogueAI42 <[email protected]> | 2017-06-19 17:48:02 +1000 |
| commit | 1c9d527ba084dfca2548eb739536f7fbe7a2f086 (patch) | |
| tree | 35403f1d8916c1f2eaa8770e9b1babeb66ab3876 /ShiftOS_TheReturn/BFInterpreter.cs | |
| parent | 40b4c29b969f97004ec51c3c22b4b8263fadbef4 (diff) | |
| download | shiftos_thereturn-1c9d527ba084dfca2548eb739536f7fbe7a2f086.tar.gz shiftos_thereturn-1c9d527ba084dfca2548eb739536f7fbe7a2f086.tar.bz2 shiftos_thereturn-1c9d527ba084dfca2548eb739536f7fbe7a2f086.zip | |
Normalise newlines for BFInterpreter I/O
when the stream sends \r, the program will receive \n
when the program sends \n, the stream will receive Environment.NewLine
Diffstat (limited to 'ShiftOS_TheReturn/BFInterpreter.cs')
| -rw-r--r-- | ShiftOS_TheReturn/BFInterpreter.cs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/ShiftOS_TheReturn/BFInterpreter.cs b/ShiftOS_TheReturn/BFInterpreter.cs index da4b44e..1ff5358 100644 --- a/ShiftOS_TheReturn/BFInterpreter.cs +++ b/ShiftOS_TheReturn/BFInterpreter.cs @@ -53,7 +53,9 @@ namespace ShiftOS.Engine private Stream str; public IBFListener lst = null; - + + private static byte[] newline = Encoding.UTF8.GetBytes(Environment.NewLine); + public BFInterpreter(Stream io, IBFListener listener = null, string program = "") { lck = new object(); @@ -91,10 +93,15 @@ namespace ShiftOS.Engine lst.MemChanged(ptr, mem[ptr]); break; case '.': - str.WriteByte(mem[ptr]); + if (mem[ptr] == 10) + str.Write(newline, 0, newline.Length); // normalise newline + else + str.WriteByte(mem[ptr]); break; case ',': mem[ptr] = (byte)str.ReadByte(); + if (mem[ptr] == 13) + mem[ptr] = 10; // normalise newline if (lst != null) lst.MemChanged(ptr, mem[ptr]); break; @@ -113,7 +120,6 @@ namespace ShiftOS.Engine string block = program.Substring(oldc, c - oldc - 1); while (mem[ptr] != 0) Execute(block, offset + oldc); - } break; case ']': |
