示例#1
0
        public static int Main(string[] args)
        {
            int errCount = 0;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // interpretation of command line options
            // ======================================
            string fileToOpen;
            Modes  mode;

            {
                bool parseModeSuccesfully = true;
                if (args.Length == 0)
                {
                    // assuming the user wants to run the worksheet mode
                    mode       = Modes.Worksheet;
                    fileToOpen = null;
                }
                else if (args.Length == 1)
                {
                    if (args[0].StartsWith("--"))
                    {
                        parseModeSuccesfully = Enum <Modes> .TryParse(args[0].Substring(2), out mode);

                        fileToOpen = null;
                    }
                    else
                    {
                        mode       = Modes.Worksheet;
                        fileToOpen = args[0];
                    }
                }
                else if (args.Length == 2)
                {
                    parseModeSuccesfully = Enum <Modes> .TryParse(args[0].Substring(2), out mode);

                    fileToOpen = args[1];
                }
                else
                {
                    PrintUsage();
                    return(int.MinValue);
                }

                if (!parseModeSuccesfully)
                {
                    PrintUsage();
                    return(int.MinValue);
                }

                if (mode == Modes.Console && fileToOpen != null)
                {
                    PrintUsage();
                    return(int.MinValue);
                }

                if ((mode == Modes.Batch || mode == Modes.TexBatch) && (fileToOpen == null))
                {
                    PrintUsage();
                    return(int.MinValue);
                }
            }

            // launch the app
            // ==============
            ilPSP.Environment.Bootstrap(
                new string[0],
                Utils.GetBoSSSInstallDir(),
                out bool mpiInitialized);

            switch (mode)
            {
            case Modes.Worksheet:
                var ws = new Worksheet(fileToOpen);
                ws.Shown += Worksheet.OnShown; // Workaround for wrong word-wrap on start-up of the application
                System.Windows.Forms.Application.Run(ws);

                ws.m_ExecutorOfCommandQueue_RegularTermination = false;
                Thread.Sleep(800);

                if (ws.m_ExecutorOfCommandQueue.IsAlive)
                {
                    // hardcore
                    Thread.Sleep(5000);
                    if (ws.m_ExecutorOfCommandQueue.IsAlive)
                    {
                        ws.m_ExecutorOfCommandQueue.Abort();
                    }
                }
                break;

            case Modes.Console:
                ReadEvalPrintLoop.REPL();
                break;

            case Modes.SimpleConsole:
                ReadEvalPrintLoop.REPL_Simple();
                break;

            case Modes.Check:
                InstallationChecker.CheckSetup();
                break;

            case Modes.Batch:
            case Modes.TexBatch:
                Document doc;
                if (fileToOpen.ToLowerInvariant().EndsWith(".tex"))
                {
                    List <string> dummy;
                    LatexIO.SplitTexFile(fileToOpen, out dummy, out doc);
                }
                else
                {
                    doc = Document.Deserialize(fileToOpen);
                }
                string OutDir = Path.GetDirectoryName(fileToOpen);
                string DocNam = Path.GetFileNameWithoutExtension(fileToOpen) + ".texbatch";
                InteractiveShell.CurrentDoc      = doc;
                InteractiveShell._CurrentDocFile = (new FileInfo(fileToOpen)).FullName;

                // Which text boxes should be removed before 'restart' occurs
                int f = 0;
                if (mode == Modes.TexBatch)
                {
                    // bws was produced by Latex - some string replacements are necessary
                    for (int iEntry = 0; iEntry < doc.CommandAndResult.Count; iEntry++)
                    {
                        var Entry = doc.CommandAndResult[iEntry];

                        // Check whether there are boxes before restart
                        if (Entry.Command.Equals("restart") || Entry.Command.Equals("restart;"))
                        {
                            f = iEntry;
                        }

                        Entry.Command = LatexIO.Tex2Bws(Entry.Command);
                    }

                    GnuplotExtensions.UseCairoLatex = true;
                }

                // All boxes before 'restart' should not be counted as error
                int count = 0;
                foreach (Document.Tuple dt in doc.CommandAndResult)
                {
                    Console.WriteLine(dt.Command);
                    bool success = dt.Evaluate();

                    if (!success && count >= f)
                    {
                        errCount++;
                    }

                    Console.WriteLine(Document.ResultStartMarker);
                    Console.WriteLine(dt.InterpreterTextOutput);
                    Console.WriteLine(Document.ResultEndMarker);

                    count++;
                }

                if (mode == Modes.TexBatch)
                {
                    LatexIO.Save_Texbatch(OutDir, DocNam, doc);
                }
                else
                {
                    if (fileToOpen.EndsWith(".tex"))
                    {
                    }
                    else
                    {
                        doc.Serialize(fileToOpen);
                    }
                }
                InteractiveShell.CurrentDoc = null;
                break;

            default:
                throw new NotImplementedException();
            }

            if (mpiInitialized)
            {
                csMPI.Raw.mpiFinalize();
            }

            return(errCount);
        }