Esempio n. 1
0
        private void ChangeDir(CTokenizer localTok)
        {
            string path = localTok.GetNextToken();

            path.Replace(c_altPathDelim, c_pathDelim);

            CTokenizer pathTokens = new CTokenizer(path, c_cPathDelim);
            string     newPath;

            // absolute path
            if (path.StartsWith(c_pathDelim))
            {
                newPath = c_pathDelim;
            }
            // relative path
            else
            {
                newPath = MBPath;
            }

            for (int pathIndex = 0; pathIndex < pathTokens.NumToks; pathIndex++)
            {
                string pathToken = pathTokens.GetNextToken();

                // ".."
                if (String.Equals(pathToken, c_upPath))
                {
                    int lastSlash = newPath.LastIndexOf(c_pathDelim);
                    newPath = newPath.Remove(lastSlash, newPath.Length - lastSlash);

                    if (0 == newPath.Length)
                    {
                        newPath = c_pathDelim;
                    }
                }

                else
                {
                    if (newPath.EndsWith(c_pathDelim))
                    {
                        newPath = newPath + pathToken;
                    }
                    else
                    {
                        newPath = newPath + c_pathDelim + pathToken;
                    }
                }
            }

            MBPath = newPath;
        }
Esempio n. 2
0
        public void DoWork()
        {
            m_bWorkDone = false;

            while (!m_bWorkDone)
            {
                try
                {
                    string s_inputLine;
                    string token;

                    CTokenizer localTok;

                    s_inputLine = ShowPrompt();

                    localTok = new CTokenizer(s_inputLine, null);

                    token = localTok.GetNextToken();
                    token = token.ToUpper();

                    if (String.Equals(token, m_commandPrefix + m_resources.GetString("engCommand")))
                    {
                        // change the scripting engine

                        if (localTok.NumToks < 2)
                        {
                            throw new CMbshException(m_resources.GetString("engError"));
                        }

                        string language = localTok.GetNextToken();

                        InitEngine(language);
                    }

                    else if (String.Equals(token, m_commandPrefix + m_resources.GetString("helpCommand")))
                    {
                        // help command

                        if (localTok.NumToks < 2)
                        {
                            // general help

                            Console.WriteLine(m_resources.GetString("generalHelp"));
                        }

                        else
                        {
                            // specific help

                            Console.WriteLine(m_resources.GetString("specificHelp"));
                        }
                    }

                    else if (String.Equals(token, m_commandPrefix + m_resources.GetString("dirCommand")))
                    {
                        EnumProps();
                    }

                    else if (String.Equals(token, m_commandPrefix + m_resources.GetString("setCommand")))
                    {
                        if (localTok.NumToks < 3)
                        {
                            throw new CMbshException(m_resources.GetString("setError"));
                        }

                        string propName = localTok.GetNextToken();
                        string propVal  = localTok.GetNextToken();

                        SetProperty(propName, propVal);
                    }

                    else if (String.Equals(token, m_commandPrefix + m_resources.GetString("getCommand")))
                    {
                        if (localTok.NumToks < 2)
                        {
                            throw new CMbshException(m_resources.GetString("getError"));
                        }

                        GetProperty(localTok.GetNextToken());
                    }

                    else if (String.Equals(token, m_commandPrefix + m_resources.GetString("cdCommand")))
                    {
                        //change metabase node

                        if (localTok.NumToks < 2)
                        {
                            throw new CMbshException(m_resources.GetString("cdError"));
                        }

                        ChangeDir(localTok);
                    }

                    else if ((String.Equals(token, m_commandPrefix + m_resources.GetString("exitCommand"))) ||
                             (String.Equals(token, m_commandPrefix + m_resources.GetString("quitCommand"))))
                    {
                        // quitting
                        m_bWorkDone = true;
                    }

                    else if (token.StartsWith(m_commandPrefix))
                    {
                        // unknown command
                        throw new CMbshException(m_resources.GetString("unknownCommand") + token +
                                                 "\n" + m_resources.GetString("useHelp") + m_commandPrefix +
                                                 m_resources.GetString("helpCommand"));
                    }

                    else
                    {
                        m_scriptControl.ExecuteStatement(s_inputLine);
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }