From 168458ae8f51f072c62dda2b8b160d8819aa5504 Mon Sep 17 00:00:00 2001 From: Nick Gammon Date: Fri, 6 Aug 2010 20:17:49 +1000 Subject: [PATCH] Enhancements to Debug 'summary' to add hyperlinks --- doc.h | 3 + mushview.cpp | 63 ++++---- world_debug.cpp | 423 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 456 insertions(+), 33 deletions(-) diff --git a/doc.h b/doc.h index a9b0876e..4187209a 100644 --- a/doc.h +++ b/doc.h @@ -2001,6 +2001,9 @@ class CMUSHclientDoc : public CDocument void DeleteConfigurationArrays (void); void ResetConfigurationArrays (void); + + void DebugHelper (const CString strAction, const CString strArgument); + // helper routines to get the appropriate map CTriggerMap & GetTriggerMap (void) { diff --git a/mushview.cpp b/mushview.cpp index 0abb35f7..8b313757 100644 --- a/mushview.cpp +++ b/mushview.cpp @@ -2033,37 +2033,42 @@ int line, strScriptName.TrimRight (); CString strArg = strAction.Mid (iBracket + 1); strArg = strArg.Left (strArg.GetLength () - 1); // drop trailing ) - long iResult = pDoc->CallPlugin (strPluginID, strScriptName, strArg); - CString strName = strPluginID; // default to ID - if (iResult != eOK) + if (strPluginID == "138a692642ab4f9e7a1af63b") // just made that up ;) + pDoc->DebugHelper (strScriptName, strArg); + else { - CPlugin * pPlugin = pDoc->GetPlugin (strPluginID); - if (pPlugin) - strName = pPlugin->m_strName; - } // end of finding plugin's name - switch (iResult) - { - case eNoSuchPlugin: - pDoc->ColourNote ("white", "red", - TFormat ("Plugin \"%s\" is not installed", - (LPCTSTR) strName)); - break; - case eNoSuchRoutine: - pDoc->ColourNote ("white", "red", - TFormat ("Script routine \"%s\" is not in plugin %s", - (LPCTSTR) strScriptName, - (LPCTSTR) strName)); - break; - - case eErrorCallingPluginRoutine: - pDoc->ColourNote ("white", "red", - TFormat ("An error occurred calling plugin %s", - (LPCTSTR) strName)); - break; - - } // end of switch on errors + long iResult = pDoc->CallPlugin (strPluginID, strScriptName, strArg); + CString strName = strPluginID; // default to ID + if (iResult != eOK) + { + CPlugin * pPlugin = pDoc->GetPlugin (strPluginID); + if (pPlugin) + strName = pPlugin->m_strName; + } // end of finding plugin's name + switch (iResult) + { + case eNoSuchPlugin: + pDoc->ColourNote ("white", "red", + TFormat ("Plugin \"%s\" is not installed", + (LPCTSTR) strName)); + break; + case eNoSuchRoutine: + pDoc->ColourNote ("white", "red", + TFormat ("Script routine \"%s\" is not in plugin %s", + (LPCTSTR) strScriptName, + (LPCTSTR) strName)); + break; + + case eErrorCallingPluginRoutine: + pDoc->ColourNote ("white", "red", + TFormat ("An error occurred calling plugin %s", + (LPCTSTR) strName)); + break; + + } // end of switch on errors + } // end of not debug helper ID } // end of ( found (this should occur, really) - } // end of plugin existing + } // end of passing special syntax test else { // plugin does not exist - just execute it pDoc->m_iExecutionDepth = 0; diff --git a/world_debug.cpp b/world_debug.cpp index 49b6ee76..278aef8f 100644 --- a/world_debug.cpp +++ b/world_debug.cpp @@ -1079,13 +1079,18 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command) else elapsed_time = 0; - Note (TFormat ("** Triggers: %ld in world file, triggers enabled: %s.", + Tell (TFormat ("** Triggers: %ld in world file, triggers enabled: %s. ", nTotal, SHOW_TRUE (m_enable_triggers))); + Hyperlink ("!!138a692642ab4f9e7a1af63b:triggerlist()", "Trigger list", "Click to list triggers", "cyan", "", 0); + Note (""); + + Note (TFormat (" %ld enabled, %ld regexp, %I64d attempts, %I64d matched, %1.6f seconds.", nEnabled, nRegexp, nTotalMatchAttempts, nTotalMatches, elapsed_time)); + nTotalMatches = 0; nTotalMatchAttempts = 0; nTotal = 0; @@ -1123,9 +1128,12 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command) else elapsed_time = 0; - Note (TFormat ("** Aliases: %ld in world file, aliases enabled: %s.", + Tell (TFormat ("** Aliases: %ld in world file, aliases enabled: %s. ", nTotal, SHOW_TRUE (m_enable_aliases))); + Hyperlink ("!!138a692642ab4f9e7a1af63b:aliaslist()", "Alias list", "Click to list aliases", "cyan", "", 0); + Note (""); + Note (TFormat (" %ld enabled, %ld regexp, %I64d attempts, %I64d matched, %1.6f seconds.", nEnabled, nRegexp, nTotalMatchAttempts, nTotalMatches, elapsed_time)); @@ -1146,9 +1154,13 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command) } - Note (TFormat ("** Timers: %ld in world file, timers enabled: %s.", + Tell (TFormat ("** Timers: %ld in world file, timers enabled: %s. ", nTotal, SHOW_TRUE (m_bEnableTimers))); + + Hyperlink ("!!138a692642ab4f9e7a1af63b:timerlist()", "Timer list", "Click to list timers", "cyan", "", 0); + Note (""); + Note (TFormat (" %ld enabled, %I64d fired.", nEnabled, nTotalMatches)); if (App.m_nTimerInterval > 0) @@ -1179,7 +1191,10 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command) GetVariableMap ().GetNextAssoc (pos, strVariableName, variable_item); } - Note (TFormat ("** Variables: %ld.", nTotal)); + Tell (TFormat ("** Variables: %ld. ", nTotal)); + + Hyperlink ("!!138a692642ab4f9e7a1af63b:variablelist()", "Variable list", "Click to list variables", "cyan", "", 0); + Note (""); ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, "", "-- MCCP --"); @@ -1527,3 +1542,403 @@ void CMUSHclientDoc::ShowAlphaOptions (void) (LPCTSTR) AlphaOptionsTable [i].pName, (LPCTSTR) GetAlphaOptionItem (i))); } // end of CMUSHclientDoc::ShowAlphaOptions + + +//----------------------------------------------------------------------- +// This is called in response to hyperlinks generated by Debug 'summary' +// above. (eg. you can get a list of triggers, or info on one trigger) +//----------------------------------------------------------------------- + +void CMUSHclientDoc::DebugHelper (const CString strAction, const CString strArgument) + { + CString enabledFore = "#0080FF"; + CString disabledFore = "gray"; + + if (m_iNoteTextColour >= 0 && m_iNoteTextColour < MAX_CUSTOM) + enabledFore = ColourToName (m_customtext [m_iNoteTextColour]); + + POSITION pos; + +//----------------------------------------------------------------------- +// triggerlist +//----------------------------------------------------------------------- + + if (strAction == "triggerlist") + { + + Note (""); + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, "", "------ Trigger List (evaluation order) ------"); + Note (""); + + for (int iTrigger = 0; iTrigger < m_TriggerArray.GetSize (); iTrigger++) + { + CTrigger * pTrigger = m_TriggerArray [iTrigger]; + + // get unlabelled trigger's internal name + const char * pLabel = pTrigger->strLabel; + if (pLabel [0] == 0) + pLabel = GetTriggerRevMap () [pTrigger].c_str (); + + + const char * pType = "Normal"; + if (pTrigger->bRegexp) + pType = "Regexp"; + + CString strColour = enabledFore; + + const char * pActive = "Enabled"; + if (!pTrigger->bEnabled) + { + pActive = "DISABLED"; + strColour = disabledFore; + } + + CString strMatch = pTrigger->trigger; + if (strMatch.GetLength () > 38) + { + strMatch = strMatch.Left (35); + strMatch = strMatch + "..."; + } + + int iSpaces = 14 - strlen (pLabel); + if (iSpaces < 0) + iSpaces = 0; + + ColourTell (strColour, "", CFormat ("%3i. ", iTrigger + 1)); + ColourTell (strColour, "", CFormat ("%6s, %8s : ", pType, pActive)); + Hyperlink (CFormat ("!!138a692642ab4f9e7a1af63b:showtrigger(%s)", pLabel), + pLabel, "Click to view this trigger", "cyan", "", 0); + + ColourNote (strColour, "", CFormat ("%*s %s", iSpaces, "", (LPCTSTR) strMatch)); + + } // end of for loop + + return; + } // end of triggerlist + + +//----------------------------------------------------------------------- +// aliaslist +//----------------------------------------------------------------------- + + if (strAction == "aliaslist") + { + + Note (""); + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, "", "------ Alias List (evaluation order) ------"); + Note (""); + + for (int iAlias = 0; iAlias < m_AliasArray.GetSize (); iAlias++) + { + CAlias * pAlias = m_AliasArray [iAlias]; + + // get unlabelled alias's internal name + const char * pLabel = pAlias->strLabel; + if (pLabel [0] == 0) + pLabel = GetAliasRevMap () [pAlias].c_str (); + + + const char * pType = "Normal"; + if (pAlias->bRegexp) + pType = "Regexp"; + + CString strColour = enabledFore; + + const char * pActive = "Enabled"; + if (!pAlias->bEnabled) + { + pActive = "DISABLED"; + strColour = disabledFore; + } + + CString strMatch = pAlias->name; + if (strMatch.GetLength () > 38) + { + strMatch = strMatch.Left (35); + strMatch = strMatch + "..."; + } + + int iSpaces = 14 - strlen (pLabel); + if (iSpaces < 0) + iSpaces = 0; + + ColourTell (strColour, "", CFormat ("%3i. ", iAlias + 1)); + ColourTell (strColour, "", CFormat ("%6s, %8s : ", pType, pActive)); + + Hyperlink (CFormat ("!!138a692642ab4f9e7a1af63b:showalias(%s)", pLabel), + pLabel, "Click to view this alias", "cyan", "", 0); + + + ColourNote (strColour, "", CFormat ("%*s %s", iSpaces, "", (LPCTSTR) strMatch)); + + } // end of for loop + + return; + } // end of aliaslist + +//----------------------------------------------------------------------- +// timerlist +//----------------------------------------------------------------------- + + if (strAction == "timerlist") + { + + Note (""); + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, "", "------ Timer List ------"); + Note (""); + int iCount = 1; + + for (pos = m_TimerMap.GetStartPosition(); pos; iCount++) + { + CTimer * pTimer; + CString strName; + + m_TimerMap.GetNextAssoc (pos, strName, pTimer); + + + // get unlabelled timer's internal name + const char * pLabel = pTimer->strLabel; + if (pLabel [0] == 0) + pLabel = GetTimerRevMap () [pTimer].c_str (); + + + CString strColour = enabledFore; + + const char * pActive = "Enabled"; + if (!pTimer->bEnabled) + { + pActive = "DISABLED"; + strColour = disabledFore; + } + + + const char * pType = "At"; + if (pTimer->iType == CTimer::eInterval) + pType = "Every"; + + ColourTell (strColour, "", CFormat ("%3i. ", iCount)); + ColourTell (strColour, "", CFormat ("%8s : ", pActive)); + + Hyperlink (CFormat ("!!138a692642ab4f9e7a1af63b:showtimer(%s)", pLabel), + pLabel, "Click to view this timer", "cyan", "", 0); + + + + ColourNote (strColour, "", TFormat (" %5s %02i:%02i:%04.2f", + pType, + pTimer->iAtHour + pTimer->iEveryHour, + pTimer->iAtMinute + pTimer->iEveryMinute, + pTimer->fAtSecond + pTimer->fEverySecond)); + + + } // end of for loop + + return; + } // end of timerlist + + +//----------------------------------------------------------------------- +// variablelist +//----------------------------------------------------------------------- + + if (strAction == "variablelist") + { + + Note (""); + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, "", "------ Variable List (alphabetic order) ------"); + Note (""); + map sortedVariables; + + for (POSITION pos = GetVariableMap ().GetStartPosition(); pos; ) + { + CString strVariableName; + CVariable * pVariable; + + GetVariableMap ().GetNextAssoc (pos, strVariableName, pVariable); + + CString strContents = Replace (pVariable->strContents, ENDLINE, "\\n", true); + + if (strContents.GetLength () > 46) + { + strContents = strContents.Left (43); + strContents = strContents + "..."; + } + + sortedVariables [(LPCTSTR) strVariableName] = strContents; + + } // end of for loop + + + // this will get them into alphabetic order + + for (map::const_iterator it = sortedVariables.begin (); + it != sortedVariables.end (); + it++) + + Note ( CFormat ("%-30s = %s", + it->first.c_str (), + it->second.c_str ())); + + return; + } // end of variablelist + + +//----------------------------------------------------------------------- +// showtrigger +//----------------------------------------------------------------------- + + if (strAction == "showtrigger") + { + + CTrigger * pTrigger; + + if (!GetTriggerMap ().Lookup (strArgument, pTrigger)) + { + Note (TFormat ("Trigger %s does not exist.", (LPCTSTR) strArgument)); + return; + } // if not found + + char * p = NULL; + + try + { + CMemFile f; // open memory file for writing + CArchive ar(&f, CArchive::store); + Save_One_Trigger_XML (ar, pTrigger); + ar.Close(); + + int nLength = f.GetLength (); + p = (char *) f.Detach (); + + CString strXML (p, nLength); + + free (p); // remove memory allocated in CMemFile + p = NULL; + + Note (""); + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, "", CFormat ("------ Trigger: %s ------",(LPCTSTR) strArgument) ); + Note (""); + Note (strXML); + Note (""); + + } // end of try block + + catch (CException* e) + { + if (p) + free (p); // remove memory allocated in CMemFile + e->ReportError(); + e->Delete(); + } + + return; + } // end of showtrigger + +//----------------------------------------------------------------------- +// showalias +//----------------------------------------------------------------------- + + + if (strAction == "showalias") + { + + CAlias * pAlias; + + if (!GetAliasMap ().Lookup (strArgument, pAlias)) + { + Note (TFormat ("Alias %s does not exist.", (LPCTSTR) strArgument)); + return; + } // if not found + + char * p = NULL; + + try + { + CMemFile f; // open memory file for writing + CArchive ar(&f, CArchive::store); + Save_One_Alias_XML (ar, pAlias); + ar.Close(); + + int nLength = f.GetLength (); + p = (char *) f.Detach (); + + CString strXML (p, nLength); + + free (p); // remove memory allocated in CMemFile + p = NULL; + + Note (""); + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, "", CFormat ("------ Alias: %s ------",(LPCTSTR) strArgument) ); + Note (""); + Note (strXML); + Note (""); + + } // end of try block + + catch (CException* e) + { + if (p) + free (p); // remove memory allocated in CMemFile + e->ReportError(); + e->Delete(); + } + + return; + } // end of showalias + + +//----------------------------------------------------------------------- +// showtimer +//----------------------------------------------------------------------- + + if (strAction == "showtimer") + { + + CTimer * pTimer; + + if (!GetTimerMap ().Lookup (strArgument, pTimer)) + { + Note (TFormat ("Timer %s does not exist.", (LPCTSTR) strArgument)); + return; + } // if not found + + char * p = NULL; + + try + { + CMemFile f; // open memory file for writing + CArchive ar(&f, CArchive::store); + Save_One_Timer_XML (ar, pTimer); + ar.Close(); + + int nLength = f.GetLength (); + p = (char *) f.Detach (); + + CString strXML (p, nLength); + + free (p); // remove memory allocated in CMemFile + p = NULL; + + Note (""); + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, "", CFormat ("------ Timer: %s ------",(LPCTSTR) strArgument) ); + Note (""); + Note (strXML); + Note (""); + + } // end of try block + + catch (CException* e) + { + if (p) + free (p); // remove memory allocated in CMemFile + e->ReportError(); + e->Delete(); + } + + return; + } // end of showtimer + + + Note (TFormat ("DebugHelper: %s, %s", (LPCTSTR) strAction,(LPCTSTR) strArgument)); + + } // end of CMUSHclientDoc::DebugHelper