Ejemplo n.º 1
0
        private static AppBehavior ProcessEncodingKey(CmdLineHelper helper)
        {
            var param     = helper.Current();
            var prefixLen = ("-encoding=").Length;

            if (param.Length > prefixLen)
            {
                var      encValue = param.Substring(prefixLen);
                Encoding encoding;
                try
                {
                    encoding = Encoding.GetEncoding(encValue);
                }
                catch
                {
                    Output.WriteLine("Wrong console encoding");
                    encoding = null;
                }

                if (encoding != null)
                {
                    Program.ConsoleOutputEncoding = encoding;
                }

                return(Select(helper.Tail()));
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static AppBehavior Select(string[] cmdLineArgs)
        {
            var    helper = new CmdLineHelper(cmdLineArgs);
            string arg    = helper.Next();

            if (arg == null)
            {
                return(new ShowUsageBehavior());
            }

            if (!arg.StartsWith("-"))
            {
                var path = arg;
                return(new ExecuteScriptBehavior(path, helper.Tail()));
            }

            var selected = SelectParametrized(helper);

            if (selected == null)
            {
                selected = new ShowUsageBehavior();
            }

            return(selected);
        }
Ejemplo n.º 3
0
        private static AppBehavior ProcessEncodingKey(CmdLineHelper helper)
        {
            var param = helper.Parse(helper.Current());

            if (!string.IsNullOrEmpty(param.Value))
            {
                var      encValue = param.Value;
                Encoding encoding;
                try
                {
                    encoding = Encoding.GetEncoding(encValue);
                }
                catch
                {
                    Output.WriteLine("Wrong console encoding");
                    encoding = null;
                }

                if (encoding != null)
                {
                    Program.ConsoleOutputEncoding = encoding;
                }

                return(Select(helper.Tail()));
            }

            return(null);
        }
Ejemplo n.º 4
0
        private static AppBehavior SelectParametrized(CmdLineHelper helper)
        {
            var initializers = new Dictionary <string, Func <CmdLineHelper, AppBehavior> >();

            initializers.Add("-measure", MeasureBehavior.Create);
            initializers.Add("-compile", ShowCompiledBehavior.Create);
            initializers.Add("-check", CheckSyntaxBehavior.Create);
            initializers.Add("-make", MakeAppBehavior.Create);
            initializers.Add("-cgi", h => new CgiBehavior());
            initializers.Add("-version", h => new ShowVersionBehavior());
            initializers.Add("-v", h => new ShowVersionBehavior());
            initializers.Add("-encoding", ProcessEncodingKey);
            initializers.Add("-codestat", EnableCodeStatistics);
            initializers.Add("-debug", DebugBehavior.Create);
            initializers.Add("-serialize", SerializeModuleBehavior.Create);

            var param = helper.Parse(helper.Current());

            if (initializers.TryGetValue(param.Name.ToLowerInvariant(), out var action))
            {
                return(action(helper));
            }

            return(null);
        }
Ejemplo n.º 5
0
        public static AppBehavior Create(CmdLineHelper helper)
        {
            if (helper.Next() == null)
            {
                return(null);
            }

            bool cgiMode = false;
            var  arg     = helper.Current();

            if (arg.ToLowerInvariant() == "-cgi")
            {
                cgiMode = true;
                arg     = helper.Next();
            }

            var path = arg;
            var env  = helper.Next();

            if (env != null && env.StartsWith("-env="))
            {
                env = env.Substring(5);
            }

            return(new CheckSyntaxBehavior(path, env, cgiMode));
        }
Ejemplo n.º 6
0
        public static AppBehavior Create(CmdLineHelper helper)
        {
            var path = helper.Next();

            if (path != null)
            {
                return(new SerializeModuleBehavior(path));
            }

            return(new ShowUsageBehavior());
        }
Ejemplo n.º 7
0
        public static AppBehavior Create(CmdLineHelper helper)
        {
            int               port         = 2801;
            string            path         = null;
            DebugProtocolType protocolType = DebugProtocolType.Tcp;

            while (true)
            {
                var arg = helper.Next();
                if (arg == null)
                {
                    break;
                }

                var parsedArg = helper.Parse(arg);
                if (parsedArg.Name == "-port")
                {
                    var portString = parsedArg.Value;
                    if (string.IsNullOrEmpty(portString))
                    {
                        return(null);
                    }

                    if (!Int32.TryParse(portString, out port))
                    {
                        Output.WriteLine("Incorrect port: " + portString);
                        return(null);
                    }
                }
                else if (parsedArg.Name == "-protocol")
                {
                    var proto = parsedArg.Value;
                    if (string.IsNullOrEmpty(proto) || !Enum.TryParse(proto, true, out protocolType))
                    {
                        Output.WriteLine("Unknown protocol. Using default");
                        protocolType = DebugProtocolType.Tcp;
                    }
                }
                else
                {
                    path = arg;
                    break;
                }
            }

            return(path == null ? null : new DebugBehavior(port, path, helper.Tail())
            {
                ProtocolType = protocolType
            });
        }
Ejemplo n.º 8
0
        private static AppBehavior EnableCodeStatistics(CmdLineHelper helper)
        {
            var param = helper.Parse(helper.Current());

            if (string.IsNullOrEmpty(param.Value))
            {
                return(null);
            }

            var outputStatFile = param.Value;

            ScriptFileHelper.EnableCodeStatistics(outputStatFile);
            return(Select(helper.Tail()));
        }
Ejemplo n.º 9
0
        public static AppBehavior Create(CmdLineHelper helper)
        {
            var codepath = helper.Next();
            var output   = helper.Next();
            var makeBin  = helper.Next();

            if (output == null || codepath == null)
            {
                return(null);
            }

            var appMaker = new MakeAppBehavior(codepath, output);

            if (makeBin != null && makeBin == "-bin")
            {
                appMaker.CreateDumpOnly = true;
            }

            return(appMaker);
        }
Ejemplo n.º 10
0
        private static AppBehavior SelectParametrized(CmdLineHelper helper)
        {
            var param = helper.Current().ToLowerInvariant();

            if (param == "-measure")
            {
                var path = helper.Next();
                if (path != null)
                {
                    return(new MeasureBehavior(path, helper.Tail()));
                }
            }
            else if (param == "-compile")
            {
                var path = helper.Next();
                if (path != null)
                {
                    return(new ShowCompiledBehavior(path));
                }
            }
            else if (param == "-check")
            {
                return(ProcessCheckKey(helper));
            }
            else if (param == "-make")
            {
                var codepath = helper.Next();
                var output   = helper.Next();
                var makeBin  = helper.Next();
                if (output != null && codepath != null)
                {
                    var appMaker = new MakeAppBehavior(codepath, output);
                    if (makeBin != null && makeBin == "-bin")
                    {
                        appMaker.CreateDumpOnly = true;
                    }

                    return(appMaker);
                }
            }
            else if (param == "-cgi")
            {
                return(new CgiBehavior());
            }
            else if (param == "-version" || param == "-v")
            {
                return(new ShowVersionBehavior());
            }
            else if (param.StartsWith("-encoding="))
            {
                return(ProcessEncodingKey(helper));
            }
            else if (param.StartsWith("-codestat="))
            {
                var prefixLen = ("-codestat=").Length;
                if (param.Length > prefixLen)
                {
                    var outputStatFile = param.Substring(prefixLen);
                    ScriptFileHelper.EnableCodeStatistics(outputStatFile);
                    return(Select(helper.Tail()));
                }
            }
            else if (param == "-debug")
            {
                var arg  = helper.Next();
                int port = 2801;
                if (arg != null && arg.StartsWith("-port="))
                {
                    var prefixLen = ("-port=").Length;
                    if (arg.Length > prefixLen)
                    {
                        var value = arg.Substring(prefixLen);
                        if (!Int32.TryParse(value, out port))
                        {
                            Output.WriteLine("Incorrect port: " + value);
                            return(null);
                        }
                    }
                }
                else if (arg != null)
                {
                    var path = arg;
                    return(new DebugBehavior(port, path, helper.Tail()));
                }
            }
            else if (param == "-serialize")
            {
                var path = helper.Next();
                if (path != null)
                {
                    return(new SerializeModuleBehavior(path));
                }

                return(new ShowUsageBehavior());
            }

            return(null);
        }
Ejemplo n.º 11
0
        public static AppBehavior Create(CmdLineHelper helper)
        {
            var path = helper.Next();

            return(path != null ? new ShowCompiledBehavior(path) : null);
        }
Ejemplo n.º 12
0
        public static AppBehavior Create(CmdLineHelper helper)
        {
            var path = helper.Next();

            return(path != null ? new MeasureBehavior(path, helper.Tail()) : null);
        }