コード例 #1
0
ファイル: ScriptFilter.cs プロジェクト: dwhobrey/BabelTools
        public static string Filter(ScriptEngine se, StringSplitter ss, string s)
        {
            ArrayList args = ss.Split(s);

            if (args == null)
            {
                return(s);
            }
            int n = args.Count - 1;

            s = (string)args[0];
            // Check if it's a script name, map to: load( "scriptname" , ...);
            bool   isHelp   = "help".Equals(s);
            string f        = Scripts.GetScriptFilePath(s);
            bool   isScript = (!String.IsNullOrWhiteSpace(f));

            if (!isScript)
            {
                s += '(';
            }
            else
            {
                s = "load(\"" + s + "\",";
            }
            if (n != 0)
            {
                for (int k = 1; k <= n; k++)
                {
                    string arg = (string)args[k];
                    if (isHelp || se.ApplyQuotes(arg))
                    {
                        if (arg.Length == 0 || (arg[0] != '"' && arg[0] != '\''))
                        {
                            arg = "'" + arg + "'";
                        }
                    }
                    s += arg;
                    if (k < n)
                    {
                        s += ',';
                    }
                }
            }
            else if (isScript)
            {
                s += "[]";
            }
            if (ss.GetBuffer().EndsWith("\n"))
            {
                s += ");\n";
            }
            else
            {
                s += ");";
            }
            return(s);
        }
コード例 #2
0
        public static string Col(int col, string text)
        {
            StringSplitter ss   = new StringSplitter();
            ArrayList      cols = ss.SplitArgs(text);

            if (cols != null && col >= 0 && cols.Count > col)
            {
                return((string)(cols[col]));
            }
            return("");
        }
コード例 #3
0
        public static string LoadScript(ScriptEngine se, String scriptName, ArrayList args)
        {
            string result = ""; int lineNum = 0;
            string filePath = GetScriptFilePath(scriptName);

            if (String.IsNullOrWhiteSpace(filePath))
            {
                return("Error: script name not found: try updating script cache.");
            }
            ArrayList ary = new ArrayList();

            ary.Add(EscapeStringLiteral(filePath));
            foreach (string s in args)
            {
                ary.Add(EscapeStringLiteral(s));
            }
            try {
                StreamReader   sr = new StreamReader(filePath);
                StringSplitter ss = new StringSplitter(Scripts.IsValidName);
                string         s, r;
                while ((s = sr.ReadLine()) != null)
                {
                    s = StripComments(s);
                    if (s != null)
                    {
                        try {
                            ++lineNum;
                            r = SubVars(s, ary);
                            if (se.GetScriptFilteringEnabled())
                            {
                                result += ScriptFilter.Filter(se, ss, r);
                            }
                            else
                            {
                                result += r;
                            }
                            result += "\n";
                        } catch (Exception e) {
                            result = "Error: filtering script " + scriptName + " line:" + lineNum + ":" + s + "\n"
                                     + "Exception:" + e.Message;
                        }
                    }
                }
                sr.Close();
                sr = null;
            } catch (Exception e) {
                result = "Error: loading script " + scriptName + " from " + filePath + "\n"
                         + "Exception:" + e.Message;
            }
            return(result);
        }
コード例 #4
0
ファイル: ScriptEngine.cs プロジェクト: dwhobrey/BabelTools
 // TODO: detect case when function call used as arg: "...,fred(1),...".
 public bool ApplyQuotes(string arg)
 {
     return(AutoQuotingEnabled && arg.Length > 0 &&
            StringSplitter.IsAlpha(arg[0]) &&
            !IsVarInScope(arg));
 }