private void Redirect(string[] what) { int unitId = int.Parse(what[0]); if (what[1] == "console" || what[1] == "stdout") { machine.RedirectDevice(unitId, Console.OpenStandardOutput()); } else if (what[1] == "stdout") { machine.RedirectDevice(unitId, Console.OpenStandardInput()); } else { machine.RedirectDevice(unitId, null); FileStream fs; if (unitId == MIXMachine.CARD_READER) { fs = new FileStream(what[1], FileMode.Open); } else { fs = new FileStream(what[1], FileMode.Append); } machine.RedirectDevice(unitId, fs); } }
static void Main(string[] args) { Dictionary <string, string> aliases = new Dictionary <string, string>(); aliases.Add("-d", "--deck"); aliases.Add("-b", "--binary"); aliases.Add("-?", "--help"); aliases.Add("-h", "--help"); Dictionary <string, string> cmdLine = CommandLineHelper.SplitCommandLine(Environment.CommandLine, aliases, true); if (cmdLine.Count == 0) { Console.WriteLine("This is MIX v0.1, (c) 2009 George Tryfonas\nAn mplementation of the machine described by Don Knuth.\n\nType '?' or 'help' at the prompt for instructions.\n"); MIXController c = new MIXController(); c.Interface(); } else { Stream stream; MIXMachine machine = new MIXMachine(); string inFile = GetInputFile(cmdLine); if (string.IsNullOrEmpty(inFile)) { stream = Console.OpenStandardInput(); } else { stream = new FileStream(inFile, FileMode.Open); } if (cmdLine.ContainsKey("--deck")) { machine.RedirectDevice(MIXMachine.CARD_READER, stream); machine.LoadDeck(); } else if (cmdLine.ContainsKey("--binary")) { IFormatter formatter = new BinaryFormatter(); MIXWord startLoc = (MIXWord)formatter.Deserialize(stream); List <MemoryCell> data = (List <MemoryCell>)formatter.Deserialize(stream); machine.LoadImage(data); machine.PC = startLoc; machine.Run(); } } }