Beispiel #1
0
        static int HandleEofOrErrorIfNonConsoleShell(List <String> scriptFilename, bool success, bool nonDebugNonGuiExitOnError,
                                                     GrShell shell, GrShellDriver driver,
                                                     ref TextReader reader, ref bool showPrompt, ref bool readFromConsole)
        {
            if (readFromConsole || (!driver.Eof && success))
            {
                return(0);
            }

            if (nonDebugNonGuiExitOnError && !success)
            {
                return(-1);
            }

            if (scriptFilename.Count != 0)
            {
                TextReader newReader;
                try
                {
                    newReader = new StreamReader((String)scriptFilename[0]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to read file \"" + scriptFilename[0] + "\": " + e.Message);
                    return(-1);
                }
                scriptFilename.RemoveAt(0);
                shell.ReInit(newReader);
                driver.Eof = false;
                reader.Close();
                reader = newReader;
            }
            else
            {
                shell.ReInit(WorkaroundManager.Workaround.In);
                driver.tokenSources.Pop();
                driver.tokenSources.Push(shell.token_source);
                showPrompt      = true;
                readFromConsole = true;
                driver.Eof      = false;
                reader.Close();
            }

            return(0);
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            String        command                   = null;
            List <String> scriptFilename            = new List <String>();
            bool          showUsage                 = false;
            bool          nonDebugNonGuiExitOnError = false;
            bool          showIncludes              = false;
            int           errorCode                 = 0; // 0==success, the return value

            PrintVersion();

            ParseArguments(args,
                           out command, out scriptFilename, out showUsage,
                           out nonDebugNonGuiExitOnError, out showIncludes, out errorCode);

            if (showUsage)
            {
                PrintUsage();
                return(errorCode);
            }

            TextReader reader;
            bool       showPrompt;
            bool       readFromConsole;

            errorCode = DetermineAndOpenInputSource(command, scriptFilename,
                                                    out reader, out showPrompt, out readFromConsole);
            if (errorCode != 0)
            {
                return(errorCode);
            }

            GrShell               shell     = new GrShell(reader);
            GrShellImpl           shellImpl = new GrShellImpl();
            IGrShellImplForDriver impl      = shellImpl;
            GrShellDriver         driver    = new GrShellDriver(shell, impl);

            shell.SetImpl(shellImpl);
            shell.SetDriver(driver);
            driver.tokenSources.Push(shell.token_source);
            driver.showIncludes            = showIncludes;
            impl.nonDebugNonGuiExitOnError = nonDebugNonGuiExitOnError;

            try
            {
                driver.conditionalEvaluationResults.Push(true);

                while (!driver.Quitting && !driver.Eof)
                {
                    driver.ShowPromptAsNeeded(showPrompt);

                    bool success = shell.ParseShellCommand();

                    errorCode = HandleEofOrErrorIfNonConsoleShell(scriptFilename, success, nonDebugNonGuiExitOnError,
                                                                  shell, driver,
                                                                  ref reader, ref showPrompt, ref readFromConsole);
                    if (errorCode != 0)
                    {
                        return(errorCode);
                    }
                }

                driver.conditionalEvaluationResults.Pop();
            }
            catch (Exception e)
            {
                Console.WriteLine("exit due to " + e.Message);
                errorCode = -2;
            }
            finally
            {
                impl.Cleanup();
            }

            return(errorCode);
        }