Exemplo n.º 1
0
        public static unsafe int ExecuteGOACommand(IntPtr clientData, IntPtr interp, int objc, IntPtr *argv)
        {
            string command = TclAPI.GetCsString(argv[0]);

            for (int i = 1; i < objc; i++)
            {
                command += " " + TclAPI.GetCsString(argv[i]);
            }
            command += ";";

            CommandStringParser parser = new CommandStringParser(command);

            foreach (string cmdstr in parser.Parse())
            {
                bool valid = parser.ParseCommand(cmdstr, true, out Command cmd, out string errorDescr);
                if (valid)
                {
                    CommandExecuter.Instance.Execute(cmd);
                    Objects.CommandStackManager.Instance.Execute();
                    if (Program.mainInterpreter.context != null)
                    {
                        Program.mainInterpreter.context.Invalidate();
                    }
                }
                else
                {
                    MessageBox.Show("Could not parse command " + Environment.NewLine + cmdstr + Environment.NewLine + "Error: " + errorDescr, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(1);
                }
            }

            return(0);
        }
        protected void UserDefinedAction(object sender, EventArgs e)
        {
            CommandStringParser parser = new CommandStringParser(Command);
            bool cmdFound = false;

            foreach (string subComd in parser.Parse())
            {
                cmdFound = true;
                Command cmd = null;
                string  errorDescr;
                bool    valid = parser.ParseCommand(subComd, true, out cmd, out errorDescr);
                if (valid)
                {
                    CommandExecuter.Instance.Execute(cmd);
                }
                else
                {
                    MessageBox.Show(errorDescr + " when parsing " + Command, "Error during command parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (!cmdFound && !string.IsNullOrEmpty(Command))
            {
                MessageBox.Show("Could not extract a command from " + Command + ". Missing semicolon after the last command?", "No commands executed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Start the shell and run until exit command
        /// </summary>
        public void Run()
        {
            Console.WriteLine("GoAhead shell mode. Enter your command:");
            Console.Write(">");

            string cmdString = "";

            while (true)
            {
                ConsoleKeyInfo info = Console.ReadKey();

                if (info.Key.Equals(ConsoleKey.Enter))
                {
                    // clear command for command trace
                    Console.WriteLine("");
                    // remove trailing ;
                    cmdString = cmdString.Replace(";", "");
                    Command             cmd;
                    string              errorDescr;
                    CommandStringParser parser = new CommandStringParser(cmdString);
                    bool valid = parser.ParseCommand(cmdString, true, out cmd, out errorDescr);

                    if (valid)
                    {
                        CommandExecuter.Instance.Execute(cmd);
                        CommandStackManager.Instance.Execute();

                        // new line printed by CommandExecuter already
                        Console.Write(">");
                        cmdString = "";
                    }
                    else
                    {
                        Console.WriteLine(errorDescr);
                        Console.Write(">");
                        cmdString = "";
                    }
                }
                else if (info.Key.Equals(ConsoleKey.Backspace))
                {
                    if (cmdString.Length > 0)
                    {
                        cmdString = cmdString.Substring(0, cmdString.Length - 1);
                    }
                }
                else if (info.Key.Equals(ConsoleKey.Escape))
                {
                    Console.WriteLine("");
                    Console.Write(">");
                    cmdString = "";
                }
                else
                {
                    cmdString += info.KeyChar;

                    //Console.Write(info.KeyChar);
                }
            }
        }
Exemplo n.º 4
0
        public void Run(int portNumber)
        {
            TcpListener serverSocket = new TcpListener(portNumber);
            TcpClient   clientSocket = default(TcpClient);

            serverSocket.Start();
            Console.WriteLine(">> GoAhead Command Server Started");
            clientSocket = serverSocket.AcceptTcpClient();

            CommandStringParser parser = new CommandStringParser("");

            while ((true))
            {
                try
                {
                    NetworkStream networkStream = clientSocket.GetStream();
                    byte[]        bytesFrom     = new byte[10025];
                    networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);

                    string dataFromClient = Encoding.ASCII.GetString(bytesFrom);
                    dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf('$'));
                    string[] atoms = dataFromClient.Split(';');

                    foreach (string commandString in atoms.Where(s => !string.IsNullOrEmpty(s)))
                    {
                        string  errorDescription = "";
                        Command cmd = null;

                        bool valid = parser.ParseCommand(commandString, true, out cmd, out errorDescription);
                        if (valid)
                        {
                            CommandExecuter.Instance.Execute(cmd);
                            byte[] sendBytes = Encoding.ASCII.GetBytes("result=" + cmd.OutputManager.GetOutput() + "$");
                            networkStream.Write(sendBytes, 0, sendBytes.Length);
                            networkStream.Flush();
                        }
                        else
                        {
                            byte[] sendBytes = Encoding.ASCII.GetBytes(errorDescription);
                            networkStream.Write(sendBytes, 0, sendBytes.Length);
                            networkStream.Flush();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    break;
                }
            }

            clientSocket.Close();
            serverSocket.Stop();
            Console.ReadLine();
        }
Exemplo n.º 5
0
        protected override void DoCommandAction()
        {
            FileStream fs = File.OpenRead(OverlayScript);

            byte[] byteBuffer = new byte[fs.Length];
            int    length     = Convert.ToInt32(fs.Length);

            fs.Read(byteBuffer, 0, length);
            fs.Close();

            CommandExecuter.Instance.MuteCommandTrace = true;

            CommandStringParser parser = new CommandStringParser(byteBuffer, length);

            TextWriter sl    = new StreamWriter(SearchLoad, false);
            TextWriter fence = new StreamWriter(Fence, false);

            foreach (string cmdString in parser.Parse())
            {
                Command resolvedCommand = null;
                string  errorDescr;

                bool valid = parser.ParseCommand(cmdString, true, out resolvedCommand, out errorDescr);

                if (resolvedCommand is Set)
                {
                    CommandExecuter.Instance.Execute(resolvedCommand);

                    Set    setCmd = (Set)resolvedCommand;
                    string value  = setCmd.Value;
                    if (Objects.IdentifierManager.Instance.IsMatch(value, Objects.IdentifierManager.RegexTypes.CLB))
                    {
                        AddToSelectionLoc addCmd = new AddToSelectionLoc();
                        addCmd.Location = value;
                        fence.WriteLine(addCmd.ToString());
                    }
                }
                else if (resolvedCommand is PathSearchOnFPGA)
                {
                    CommandExecuter.Instance.MuteCommandTrace = false;
                    PathSearchOnFPGA searchCmd = (PathSearchOnFPGA)resolvedCommand;
                    //String from
                    //this.OutputManager.WriteOutput(searchCmd.StartLocation + "." + searchCmd.StartPort + "-" + searchCmd.TargetLocation + "." + searchCmd.TargetPort);
                    sl.WriteLine(searchCmd.StartLocation + "." + searchCmd.StartPort + "-" + searchCmd.TargetLocation + "." + searchCmd.TargetPort);
                }
                else
                {
                }
            }

            sl.Close();
            fence.Close();
        }
Exemplo n.º 6
0
        private void ShowToolTipAfterTimerFired(object sender, EventArgs e)
        {
            if (StoredPreferences.Instance.ShowToolTips)
            {
                Point p = (Point)m_timer.Tag;

                // only show a new tool tip, if the position changes
                if (m_lastToolTipLocation.Equals(p))
                {
                    return;
                }

                m_lastToolTipLocation = p;

                int cmdIndex = GetCommandIndex(p);
                if (cmdIndex == -1)
                {
                    return;
                }

                int from   = m_commandIndeces[cmdIndex].Item1;
                int length = m_commandIndeces[cmdIndex].Item2 - m_commandIndeces[cmdIndex].Item1;

                string commandString = m_txtCmds.Text.Substring(from, length);

                Command             cmd = null;
                string              errorDescription = "";
                CommandStringParser parser           = new CommandStringParser(commandString);
                bool valid = parser.ParseCommand(commandString, false, out cmd, out errorDescription);
                if (valid)
                {
                    // print command action to text box
                    foreach (Attribute attr in Attribute.GetCustomAttributes(cmd.GetType()).Where(a => a is CommandDescription))
                    {
                        CommandDescription descr   = (CommandDescription)attr;
                        string             toolTip = descr.Description;

                        m_toolTip.Show(toolTip, this, p.X, p.Y + 20, 10000);
                        break;
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// handle user cmds
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_txtInputTrace_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                try
                {
                    CommandStringParser parser = new CommandStringParser(m_txtInput.Text);
                    foreach (string cmdString in parser.Parse())
                    {
                        Command cmd;
                        string  errorDescr;
                        bool    valid = parser.ParseCommand(cmdString, true, out cmd, out errorDescr);
                        if (valid)
                        {
                            CommandExecuter.Instance.Execute(cmd);
                        }
                        else
                        {
                            MessageBox.Show("Could not parse command " + Environment.NewLine + cmdString + Environment.NewLine + "Error: " + errorDescr, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        // update shell
                        Objects.CommandStackManager.Instance.Execute();

                        if (Parent != null)
                        {
                            Parent.Invalidate();
                        }
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK);
                }
                m_txtInput.Clear();
            }
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            // TCL API init
            //TclAPI.Initialize();
            mainInterpreter = new TclInterpreter();
            unsafe
            {
                ExecuteGOAcmd = TclProcs.ExecuteGOACommand;
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "cs", TclProcs.Cs);
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "cshelp", TclProcs.CsHelp);
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "cslist", TclProcs.CsList);
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "clear", TclProcs.Clear);
                TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "clearcontext", TclProcs.ClearContext);
                //TclDLL.Helper_RegisterProc(mainInterpreter.ptr, "test", TclProcs.Test);
            }
            //int rc = mainInterpreter.EvalScript("puts [testproc Tile]");
            //Console.WriteLine("rc=" + rc + " Interp.Result = " + mainInterpreter.Result);

            // restore settings
            StoredPreferences.LoadPrefernces();

            // check vars
            StringBuilder errorList;

            if (!EnvChecker.CheckEnv(out errorList))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(errorList.ToString());
                Console.ResetColor();
            }

            // detect commands without default constructor
            foreach (Type type in CommandStringParser.GetAllCommandTypes())
            {
                try
                {
                    Command cmd = (Command)Activator.CreateInstance(type);
                    TclDLL.Helper_RegisterProc(mainInterpreter.ptr, type.Name, ExecuteGOAcmd);
                    unsafe
                    {
                        //string[] parts = cmd.ToString().Split(' ');
                        //if (parts[0].EndsWith(";")) parts[0] = parts[0].Substring(0, parts[0].Length - 1);
                        TclDLL.Helper_RegisterProc(mainInterpreter.ptr, type.Name, ExecuteGOAcmd);
                    }
                }
                catch (Exception)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Warning: No default constructor found for command " + type.Name);
                    Console.ResetColor();
                }
            }



            // register console hook
            // first hook print progress to clean the % output
            CommandExecuter.Instance.AddHook(new PrintProgressToConsoleHook());
            // the profiling hook must be added before the output hook hooks as it produces output
            CommandExecuter.Instance.AddHook(new ProfilingHook());
            CommandExecuter.Instance.AddHook(new ConsoleCommandHook());
            CommandExecuter.Instance.AddHook(new PrintOutputHook());

            // check if init.goa is found in binary of the current assembly
            string dir      = AssemblyDirectory;
            string initFile = dir + Path.DirectorySeparatorChar + "init.goa";

            // if so, execute init.goa
            if (File.Exists(initFile))
            {
                RunScript runInitCmd = new RunScript();
                runInitCmd.FileName = initFile;
                CommandExecuter.Instance.Execute(runInitCmd);
                //FileInfo fi = new FileInfo(initFile);
                //CommandExecuter.Instance.Execute(fi);
            }
            else
            {
                Console.WriteLine("GoAhead did not find the init file: " + initFile);
            }

            bool   showGUIOnly = false;
            bool   execScript  = false;
            string scriptFile  = "";
            bool   shellMode   = false;
            bool   serverMode  = false;
            int    portNumber  = 0;
            bool   commandMode = false;

            if (args.Length == 0)
            {
                showGUIOnly = true;
            }
            else
            {
                int i = 0;
                while (i < args.Length)
                {
                    switch (args[i])
                    {
                    case "-gui":
                        showGUIOnly = true;
                        break;

                    case "-exec":
                        execScript = true;
                        scriptFile = GetScriptFileName(args, i + 1);
                        i++;
                        break;

                    case "-shell":
                        shellMode = true;
                        break;

                    case "-command":
                    case "-commands":
                        commandMode = true;
                        break;

                    case "-server":
                        portNumber = int.Parse(args[i + 1]);
                        i++;
                        break;

                    default:
                        if (args[i].EndsWith(".goa") && File.Exists(args[i]))
                        {
                            execScript = true;
                            scriptFile = GetScriptFileName(args, i);
                        }
                        break;
                    }
                    i++;
                }
            }
            if (showGUIOnly)
            {
                // open gui
                CommandExecuter.Instance.Execute(new Commands.GUI.ShowGUI());
            }
            else if (execScript)
            {
                if (!File.Exists(scriptFile))
                {
                    string errorMessage = "Error: File " + scriptFile + " not found";
                    // allow the test scripts to catch this string (goahead -exec script.goa | tee.goa)
                    Console.WriteLine(errorMessage);
                    throw new ArgumentException(errorMessage);
                }

                // command file mode
                FileInfo fi = new FileInfo(scriptFile);
                CommandExecuter.Instance.Execute(fi);
            }
            else if (shellMode)
            {
                Objects.CommandShell shell = new Objects.CommandShell();
                shell.Run();
            }
            else if (serverMode)
            {
                Objects.CommandServer server = new Objects.CommandServer();
                server.Run(portNumber);
            }
            else if (commandMode)
            {
                string cmdString = "";
                if (args.Length > 1)
                {
                    for (int i = 1; i < args.Length; i++)
                    {
                        cmdString += args[i] + " ";
                    }
                }
                if (string.IsNullOrEmpty(cmdString))
                {
                    Console.WriteLine("GoAhead was started with -commands, but no command was given");
                }
                Command             cmd;
                string              errorDescr;
                CommandStringParser parser = new CommandStringParser(cmdString);
                foreach (string subCommandString in parser.Parse())
                {
                    bool valid = parser.ParseCommand(subCommandString, true, out cmd, out errorDescr);
                    if (!valid)
                    {
                        Console.WriteLine(errorDescr);
                    }
                    CommandExecuter.Instance.Execute(cmd);
                }
            }
            else
            {
                Console.WriteLine("No switch found. Start GoAhead with one of the following options:");
                Console.WriteLine("GoAhead -gui             : Open GoAhead in GUI-Mode");
                Console.WriteLine("GoAhead -exec script.goa : Execute script.goa");
                Console.WriteLine("GoAhead script.goa       : Execute script.goa");
                Console.WriteLine("GoAhead -shell           : Start GoAhead shell (interactive Command mode)");
                Console.WriteLine("GoAhead -command(s)      : Execute GoAhead commands (e.g GoAhead -command \"FixS6XDLBug XDLInFile=in.xdl XDLOutFile=out.xdl;\"");
            }

            // save settings
            StoredPreferences.SavePrefernces();
        }
Exemplo n.º 9
0
        private void ReloadScript()
        {
            string scriptFile = m_lblScriptFiled.Text;

            if (!File.Exists(scriptFile))
            {
                MessageBox.Show("Script file not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            m_txtCmds.Clear();
            m_txtLineNumber.Clear();
            m_commandIndeces.Clear();
            m_commandIndex = 0;
            m_form         = 0;
            m_length       = 0;
            m_lblCmd.Text  = "No command selected";

            // copy file into text box
            StreamReader sr   = new StreamReader(scriptFile);
            string       line = "";

            int lineCount = 0;

            while ((line = sr.ReadLine()) != null)
            {
                m_txtCmds.AppendText(line + Environment.NewLine);
                m_txtLineNumber.AppendText((lineCount + 1).ToString() + Environment.NewLine);
                lineCount++;
            }
            sr.Close();

            m_context = new CommandExecutionContext();

            CommandStringParser parser = new CommandStringParser(m_txtCmds.Text);

            foreach (string cmdStr in parser.Parse())
            {
                Command cmd;
                string  errorDescr;
                bool    valid = parser.ParseCommand(cmdStr, false, out cmd, out errorDescr);
                if (valid)
                {
                    m_context.Parsed(cmdStr, cmd);
                }
                else
                {
                    MessageBox.Show(errorDescr + Environment.NewLine + parser.State.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            m_context.SetLabels();

            foreach (Tuple <int, int> range in parser.Topology.GetBorders(CommandStringTopology.TopologyType.Comment))
            {
                m_txtCmds.Select(range.Item1, (range.Item2 - range.Item1) + 1);
                m_txtCmds.SelectionColor = Color.Green;
            }
            foreach (Tuple <int, int> range in parser.Topology.GetBorders(CommandStringTopology.TopologyType.CommandTag))
            {
                m_txtCmds.Select(range.Item1, (range.Item2 - range.Item1) + 1);
                m_txtCmds.SelectionColor = Color.Red;
            }
            foreach (Tuple <int, int> range in parser.Topology.GetBorders(CommandStringTopology.TopologyType.ArgumentNames))
            {
                m_txtCmds.Select(range.Item1, (range.Item2 - range.Item1) + 1);
                m_txtCmds.SelectionColor = Color.Blue;
            }
            foreach (Tuple <int, int> range in parser.Topology.GetBorders(CommandStringTopology.TopologyType.ArgumentValues))
            {
                m_txtCmds.Select(range.Item1, (range.Item2 - range.Item1) + 1);
                m_txtCmds.SelectionColor = Color.Black;
            }
            foreach (Tuple <int, int> range in parser.Topology.GetBorders(CommandStringTopology.TopologyType.CompleteCommand))
            {
                m_commandIndeces.Add(new Tuple <int, int>(range.Item1, range.Item2));
            }

            SetSelectedItemToNextCommandListView();
        }