From 1c9d527ba084dfca2548eb739536f7fbe7a2f086 Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Mon, 19 Jun 2017 17:43:53 +1000 Subject: [PATCH] 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 --- ShiftOS_TheReturn/BFInterpreter.cs | 12 +++++++++--- 1 file 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 ']':