Beispiel #1
0
        /// <summary>
        /// Shows common elements when stopping BF program.
        /// </summary>
        private void ShowCommonElements_StopRun()
        {
            // GUI initialization
            this.BEditor.IsReadOnly = false;
            this.FileMenu.IsEnabled = true;
            this.EditMenu.IsEnabled = true;
            this.InterpreterMenu.IsEnabled = true;
            this.DebuggerMenu.IsEnabled = true;
            this.StartDebug.IsEnabled = true;
            this.StopDebug.IsEnabled = false;
            this.NextStep.IsEnabled = false;
            this.RunUntilBP.IsEnabled = false;
            this.Title = "NXU Brainfuck Developer";
            this.DebuggerTab.IsEnabled = false;
            this.RightTab.SelectedIndex = 0;
            this.InputTab.IsEnabled = true;

            // Dereference input manager
            this.inputManager = null;
        }
Beispiel #2
0
        /// <summary>
        /// Sets start parameters.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        private static void SetStartParameters(string[] args)
        {
            if (args.Length < 1)
            {
                PrintUsage();
                Environment.Exit(2);
            }

            bool memSet = false;

            // Step through the arguments
            foreach (var arg in args)
            {
                if (arg.StartsWith("-it:") || arg.StartsWith("-ib:"))
                {
                    // Input method
                    if (inputManager != null)
                    {
                        Error("Multiple input method definiton: " + arg, 2);
                    }
                    if (arg.Length <= 4)
                    {
                        Error("Invalid parameter \"-it:\" - no file specified", 2);
                    }
                    else
                    {
                        Stream source = null;
                        try
                        {
                             source = File.OpenRead(arg.Substring(4, arg.Length - 4));
                        }
                        catch(Exception ex)
                        {
                            Error("Can't open file for input: " + ex.Message, 2);
                        }

                        if (arg.StartsWith("-it:"))
                        {
                            // Text mode
                            inputManager = new TextInputManager(source);
                        }
                        else
                        {
                            // Binary mode
                            inputManager = new BinaryInputManager(source);
                        }
                    }
                }
                else if (arg.StartsWith("-m:"))
                {
                    int mem = -1;

                    // Memory limit
                    if (memSet)
                    {
                        Error("Multiple memory limit definitions", 2);
                    }
                    else if (arg.Length <= 3)
                    {
                        Error("No memory limit specified", 2);
                    }
                    else if (!int.TryParse(arg.Substring(3, arg.Length - 3), out mem) || mem < 0)
                    {
                        Error("Invalid memory limit: " + arg.Substring(3, arg.Length - 3), 2);
                    }
                    else
                    {
                        memoryLimit = mem;
                        memSet = true;
                    }
                }
                else
                {
                    if (codebase != null)
                        Error("Multiple source files defined or invalid argument: " + arg, 2);

                    try
                    {
                        codebase = File.ReadAllText(arg);
                    }
                    catch
                    {
                        Error("Error while opening source file: " + arg, 2);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the input manager.
        /// </summary>
        /// <returns>Brainfuck input function.</returns>
        private Func<int> GetInputMethod()
        {
            if (true == this.CBUseFileInput.IsChecked)
            {
                // Use file as input source
                if (this.inputFileName == null || this.inputFileName.Length < 1)
                {
                    // No file specified!
                    MessageBox.Show("No input file specified", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return null;
                }
                try
                {
                    // Open file for read
                    Stream source = File.OpenRead(this.inputFileName);

                    if (this.CBInputFileMethod.SelectedIndex == 0)
                    {
                        // Binary mode
                        this.inputManager = new BinaryInputManager(source);
                    }
                    else
                    {
                        // Text mode
                        this.inputManager = new TextInputManager(source);
                    }
                }
                catch (Exception ex)
                {
                    // File I/O error
                    MessageBox.Show("Error while opening file:\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    this.CBUseFileInput.IsChecked = false;
                    return null;
                }
            }
            else
            {
                // Use inputbox for input (text mode)
                this.inputManager = new TextInputManager(this.TBXInputBox.Text);
            }

            // Use input manager for input function
            return new Func<int>(() => this.inputManager.Read());
        }