예제 #1
0
        static void Main(string[] args)
        {
            var information = new ExecuteInformation
            {
                Time = false
            };
            string target = null;

            for (var i = 0; i < args.Length; ++i)
            {
                if (CheckFullCommand(args[i]) is string fullCommand)
                {
                    if (fullCommands.TryGetValue(fullCommand, out var func))
                    {
                        if (func(information))
                        {
                            return;
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine($"--{fullCommand} is not command");
                        return;
                    }
                }
                else if (CheckShortCommand(args[i]) is string shortCommand)
                {
                    if (shortCommands.TryGetValue(shortCommand, out var func))
                    {
                        ++i;
                        if (i < args.Length)
                        {
                            func(information, args[i]);
                        }
                        else
                        {
                            Console.Error.WriteLine($"-{shortCommand} have no argument");
                            return;
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine($"-{shortCommand} is not command");
                    }
                }
                else
                {
                    target = args[i];
                }
            }
            if (target is null)
            {
                Console.Error.WriteLine("CScript: fatal error: no input files");
                return;
            }
            Script.Run(target, information);
        }
예제 #2
0
        public static void Run(string target, ExecuteInformation information)
        {
            string source;

            using (var stream = new StreamReader(target))
            {
                source = stream.ReadToEnd();
            }
            var stopwatch = new Stopwatch();

            try
            {
                stopwatch.Start();
                Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.RunAsync(source, globals: new PredefinedFunctions(
                                                                                  Console.ReadLine,
                                                                                  Console.Write,
                                                                                  Console.WriteLine,
                                                                                  Console.Error.WriteLine)).Wait();
                stopwatch.Stop();
                if (information.Time)
                {
                    Console.WriteLine($"実行時間 {TimeString(stopwatch.ElapsedMilliseconds)}");
                }
            }
            catch (Exception exp)
            {
                stopwatch.Stop();
                Console.Error.WriteLine(exp.Message);
                if (information.Time)
                {
                    Console.Error.WriteLine($"異常終了しました: 実行時間 {TimeString(stopwatch.ElapsedMilliseconds)}");
                }
                else
                {
                    Console.Error.WriteLine("異常終了しました");
                }
            }
        }
예제 #3
0
 static public bool Function(ExecuteInformation information)
 {
     Console.WriteLine(Resource1.FunctionsInformation);
     return(true);
 }
예제 #4
0
 static public bool Time(ExecuteInformation information)
 {
     information.Time = true;
     return(false);
 }
예제 #5
0
 static public bool Help(ExecuteInformation information)
 {
     Console.WriteLine(Resource1.HelpInformation);
     return(true);
 }