⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 options.cs

📁 charp compiler
💻 CS
📖 第 1 页 / 共 2 页
字号:
        
    }

    //-------------------------------------------------------------------------    
    // Dispatch a single option
    //-------------------------------------------------------------------------    
    internal void DispatchOption(string stArg, ArrayList alFiles)
    {
        int cch = stArg.Length;
        if (cch >= 2)
        {
            // Repsonse file
            if (stArg[0] == '@')
            {
                 DispatchResponseFile(stArg.Substring(1), alFiles);       
            }
                    
            // Normal option, connected to an OptionHandler
            else if (stArg[0] == '/')
            {
                string stParam = "";
                int i = stArg.IndexOf(':');
                if (i > -1)
                    stParam = stArg.Substring(i + 1);
                                
                string stOption = (i == -1) ? stArg : stArg.Substring(0, i);
                
                OptionInfo info = m_tblOptions[stOption.Substring(1)] as OptionInfo;
                                
                if (info != null)
                {    
                    Blue.Public.OptionHandler handler = info.Handler;
                
                    try
                    {                
                        handler(stParam);                 
                    }
                    catch(OptionErrorException e)
                    {
                        PrintError_OptionError(stOption, stParam, e.Message);
                    }
                } else {                    
                    PrintError_UnrecognizedOption(stOption); 
                }
            }
                    
            // Filename
            else
            {
                alFiles.Add(stArg);
            }
        } else {
        // @todo - we're just ignoring the others, is that ok?
        }
    }

    //-------------------------------------------------------------------------    
    // Options.ProcessCommandLine
    //
    // ProcessCommandLine() process the given command-line parameters, calling
    // registered OptionHandlers for given compiler options and building a list
    // of source files to process.    
    //
    // Return false if an option did useful work (and so the driver can exit)
    // Return true if the options just set properties and so we want to go
    //     ahead and compile.
    //-------------------------------------------------------------------------

    internal bool
    ProcessCommandLine(
        string[] arstArgs,                  // Command-line arguments
        out string[] arstSourceFiles)       // Input files to process
    {
        
        int cArgs           = arstArgs.Length;
        ArrayList alFiles   = new ArrayList();
        arstSourceFiles     = null;

        // Once we process the command line, we're locked and we shouldn't add
        // any new handlers.
        Debug.Assert(!m_fIsLocked, "Only call ProcessCommandLine once");
        m_fIsLocked =true;

        bool fSuccess = false;
                        
        // Check all of the arguments, notifying components as appropriate.        
        // The help handler (/?, /Help) is just a normal registered handler 
        // that can be invoked here.
        for (int idx = 0; idx < cArgs; idx++)
        {
            string stArg = arstArgs[idx];
            DispatchOption(stArg, alFiles);
        }

        // If one of the handlers did useful work already, then we don't need to
        // invoke the compiler.
        if (m_fDidUsefulWork)
            return false;

        //
        // Return the list of files to process.
        //

        if (alFiles.Count > 0)
        {
            arstSourceFiles = (string[]) alFiles.ToArray(typeof(string));
            Debug.Assert(arstSourceFiles != null);
        }

        fSuccess = true;
        
        

        return fSuccess;
    }

    //-----------------------------------------------------------------------------
    // If stOption is a valid command, Provide detailed help.
    // If stOption = "*" then show details on all commands
    // Else print the summary.
    //-----------------------------------------------------------------------------
    private void Option_Help(string stOption)
    {
        // The help command is considered 'useful work'.
        // That means that we may invoke the compiler just using the help command,
        // and we won't get an error for not specifying source files.
        m_fDidUsefulWork = true;
        
        if (stOption == "")
        {
            DisplayHelpSummary();
            return;
        }
        
        Console.WriteLine("Help on help:");
        
        // Print on all commands
        if (stOption == "*")
        {
            foreach(DictionaryEntry x in m_tblOptions)
            {
                OptionInfo info = (OptionInfo) x.Value;
                string stKey = (string) x.Key;
                if (info.Option != stKey)
                    continue; // skip over shortcuts
                PrintDetailedHelp(info);
            }
            return;
        } else {
            // Print on the specified command
            OptionInfo info = (OptionInfo) m_tblOptions[stOption];
            if (info == null)
            {
                Console.WriteLine("'" + stOption + "' is not a command.");
                DisplayHelpSummary();
                return;
            }
            
            PrintDetailedHelp(info);
        }
    }
    
    // Print detailed help on the specific option
    private void PrintDetailedHelp(OptionInfo info)
    {
        Console.WriteLine("command /{0}:", info.Option);
        if (info.Shortcut != null)
            Console.WriteLine("shortcut:/{0}", info.Shortcut);
        Console.WriteLine("short help:{0}", info.ShortHelp);
        Console.WriteLine(info.FullHelp);
        Console.WriteLine();
    }
    
    //-----------------------------------------------------------------------------
    // Display a complete list of all registered handlers.
    //-----------------------------------------------------------------------------
    private void 
    DisplayHelpSummary()
    {
        
        Console.WriteLine("BLUE COMPILER OPTIONS");
        Console.WriteLine();
                
        foreach(DictionaryEntry x in m_tblOptions)
        {
            OptionInfo info = (OptionInfo) x.Value;
            string stKey = (string) x.Key;
            if (info.Option != stKey)
                continue; // skip over shortcuts
            
            string stShortcut = "";
            if (info.Shortcut != null)
            {
                stShortcut = "(/" + info.Shortcut + ")";
            }
            Console.WriteLine("/{0,-10}{1} {2}", info.Option, info.ShortHelp, stShortcut);
        }
        
        // also print help for response files
        Console.WriteLine("{0, -10} specify a response file", "@<file>");
        
        // Print some other general tips
        Console.WriteLine("Use /help:help for more details.");
    }

#endregion Implementation

   
#region Data

    private Hashtable   m_tblOptions;
    private bool        m_fDidUsefulWork;
    
    // For debugging use. Make sure we don't add options after we start processing.
    private bool        m_fIsLocked;
#endregion Data

} // class Options

} // namespace Blue.Util

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -