示例#1
0
文件: Document.cs 项目: xyuan/BoSSS
            /// <summary>
            /// Evaluates this command and updated <see cref="InterpreterTextOutput"/>.
            /// </summary>
            public bool Evaluate()
            {
                StringWriter stw    = new StringWriter();
                bool         supOut = ilPSP.Environment.StdOut.surpressStream0;
                //ilPSP.Environment.StdOut.surpressStream0 = true;
                bool superr = ilPSP.Environment.StdErr.surpressStream0;

                //ilPSP.Environment.StdErr.surpressStream0 = true;

                ilPSP.Environment.StdOut.WriterS.Add(stw);
                ilPSP.Environment.StdErr.WriterS.Add(stw);

                if (this.Command != null && this.Command.Length > 0)
                {
                    this.Result = ReadEvalPrintLoop.EvalPrint(this.Command, out AssemblyProduced);
                }
                else
                {
                    this.Result = null;
                }

                Console.Out.Flush();
                Console.Error.Flush();

                this.InterpreterTextOutput = stw.ToString();
                ilPSP.Environment.StdOut.WriterS.Remove(stw);
                ilPSP.Environment.StdErr.WriterS.Remove(stw);

                //ilPSP.Environment.StdOut.surpressStream0 = supOut;
                //ilPSP.Environment.StdErr.surpressStream0 = superr;

                return(InteractiveShell.LastError == null &&
                       ReadEvalPrintLoop.cmpCont != null && // wenn das nix ist eh irgendwas oberfaul
                       ReadEvalPrintLoop.cmpCont.Report.Errors == 0);
            }
示例#2
0
 /// <summary>
 /// Saves the current interactive session as a worksheet that can be
 /// loaded by the worksheet edition of the BoSSSPad
 /// </summary>
 /// <param name="path"></param>
 public static void SaveSessionAsWorksheet(string path)
 {
     ReadEvalPrintLoop.SaveSessionAsWorksheet(path);
 }
示例#3
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.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";

                // 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);
                    }
                }
                break;

            default:
                throw new NotImplementedException();
            }

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

            return(errCount);
        }