Antlr4.AntlrTool.HandleArgs C# (CSharp) Method

HandleArgs() protected method

protected HandleArgs ( ) : void
return void
        protected virtual void HandleArgs()
        {
            int i = 0;
            while (args != null && i < args.Length)
            {
                string arg = args[i];
                i++;
                if (arg.StartsWith("-D"))
                {
                    // -Dlanguage=Java syntax
                    HandleOptionSetArg(arg);
                    continue;
                }

                if (arg[0] != '-')
                {
                    // file name
                    if (!grammarFiles.Contains(arg))
                        grammarFiles.Add(arg);
                    continue;
                }

                bool found = false;
                foreach (Option o in optionDefs)
                {
                    if (arg.Equals(o.name))
                    {
                        found = true;
                        string argValue = null;
                        if (o.argType == OptionArgType.STRING)
                        {
                            argValue = args[i];
                            i++;
                        }

                        // use reflection to set field
                        try
                        {
                            FieldInfo f = GetField(GetType(), o.fieldName);
                            if (argValue == null)
                            {
                                if (arg.StartsWith("-no-"))
                                    f.SetValue(this, false);
                                else
                                    f.SetValue(this, true);
                            }
                            else
                                f.SetValue(this, argValue);
                        }
                        catch (Exception)
                        {
                            errMgr.ToolError(ErrorType.INTERNAL_ERROR, "can't access field " + o.fieldName);
                        }
                    }
                }
                if (!found)
                {
                    errMgr.ToolError(ErrorType.INVALID_CMDLINE_ARG, arg);
                }
            }
            if (outputDirectory != null)
            {
                if (outputDirectory.EndsWith("/") ||
                    outputDirectory.EndsWith("\\"))
                {
                    outputDirectory =
                        outputDirectory.Substring(0, outputDirectory.Length - 1);
                }

                string outDir = outputDirectory;
                haveOutputDir = true;
                if (File.Exists(outDir))
                {
                    errMgr.ToolError(ErrorType.OUTPUT_DIR_IS_FILE, outputDirectory);
                    libDirectory = ".";
                }
            }
            else
            {
                outputDirectory = ".";
            }
            if (libDirectory != null)
            {
                if (libDirectory.EndsWith("/") ||
                    libDirectory.EndsWith("\\"))
                {
                    libDirectory = libDirectory.Substring(0, libDirectory.Length - 1);
                }

                string outDir = libDirectory;
                if (!Directory.Exists(outDir))
                {
                    errMgr.ToolError(ErrorType.DIR_NOT_FOUND, libDirectory);
                    libDirectory = ".";
                }
            }
            else
            {
                libDirectory = ".";
            }

            if (launch_ST_inspector)
            {
                //TemplateGroup.trackCreationEvents = true;
                return_dont_exit = true;
            }
        }