AddHandler( string stOption, // Unique flag for Option string stShortcut, // Optional shortcut (can be null); Blue.Public.OptionHandler ha, // Option Handler string stDescription, // short 1-line description string stFullHelp // long description ) { Debug.Assert(!m_fIsLocked, "Can't add new optionhandler after we've locked:" + stDescription); OptionInfo info = new OptionInfo(stOption, stShortcut, ha, stDescription, stFullHelp); if (m_tblOptions[stOption] == null) { if (stShortcut != null) { Debug.Assert(m_tblOptions[stShortcut] == null); m_tblOptions[stShortcut] = info; } m_tblOptions[stOption] = info; } else { // Since end users can't define option handlers, we should know about // any collisions during the debug phase. Debug.Assert(false, "Handler already defined"); } }
//------------------------------------------------------------------------- // 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? } }
// Constructor public OptionInfo( string stOption, string stShortcut, Blue.Public.OptionHandler ha, string stDescription, string stFullHelp ) { Debug.Assert(stOption != null, "Must specify option"); Debug.Assert(ha != null, "Must have valid handler"); Debug.Assert(stDescription != null, "Must have valid description"); m_stOption = stOption; m_stShortcut = stShortcut; // can be null m_ha = ha; m_stDescription = stDescription; m_stFullHelp = (stFullHelp == null) ? stDescription : stFullHelp; }