From afbd6cc123b935c0b7a71855d3336d9b4a187a36 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Fri, 10 Aug 2007 23:43:16 +0000 Subject: [PATCH] Reformatted output of meta list command --HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40420 --- sourcemm/CPlugin.cpp | 31 ++++++++ sourcemm/CPlugin.h | 3 + sourcemm/changelog.txt | 2 + sourcemm/concommands.cpp | 161 ++++++++++++++++++++------------------- sourcemm/util.h | 5 ++ 5 files changed, 124 insertions(+), 78 deletions(-) diff --git a/sourcemm/CPlugin.cpp b/sourcemm/CPlugin.cpp index 4f5d104..256bfc3 100644 --- a/sourcemm/CPlugin.cpp +++ b/sourcemm/CPlugin.cpp @@ -302,6 +302,37 @@ CPluginManager::CPlugin *CPluginManager::FindByAPI(ISmmPlugin *api) return NULL; } +int CPluginManager::GetPluginCount() +{ + return (int)m_Plugins.size(); +} + +const char *CPluginManager::GetStatusText(CPlugin *pl) +{ + switch (pl->m_Status) + { + case Pl_NotFound: + return "NOFILE"; + case Pl_Error: + return "ERROR"; + case Pl_Refused: + return "FAILED"; + case Pl_Paused: + return "PAUSED"; + case Pl_Running: + { + if (pl->m_API && pl->m_API->QueryRunning(NULL, 0)) + { + return "STOPPED"; + } else { + return "RUNNING"; + } + } + default: + return "-"; + } +} + CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source, char *error, size_t maxlen) { FILE *fp; diff --git a/sourcemm/CPlugin.h b/sourcemm/CPlugin.h index 8a55daf..6caa2f7 100644 --- a/sourcemm/CPlugin.h +++ b/sourcemm/CPlugin.h @@ -116,6 +116,9 @@ namespace SourceMM */ bool Retry(PluginId id, char *error, size_t len); + int GetPluginCount(); + const char *GetStatusText(CPlugin *pl); + //get alias info const char *LookupAlias(const char *alias); SourceHook::List::iterator _alias_begin(); diff --git a/sourcemm/changelog.txt b/sourcemm/changelog.txt index 2374fee..88b6145 100644 --- a/sourcemm/changelog.txt +++ b/sourcemm/changelog.txt @@ -10,6 +10,8 @@ version. - Added OnUnlinkConCommandBase to IMetamodListner to notify when Metamod:Source is about to remove a concommand or convar. + - The output of the "meta list" command has been reformatted in order to allow + more space for plugins' name, version, and author fields. 2007/06/26 1.4.2: - Fixed a bug where unloading all plugins could crash if one plugin had child diff --git a/sourcemm/concommands.cpp b/sourcemm/concommands.cpp index fd62f58..ae9b693 100644 --- a/sourcemm/concommands.cpp +++ b/sourcemm/concommands.cpp @@ -15,6 +15,9 @@ #include "sh_string.h" #include "sh_list.h" +using namespace SourceMM; +using namespace SourceHook; + /** * @brief Console Command Implementations * @file concommands.cpp @@ -50,7 +53,7 @@ bool SMConVarAccessor::Register(ConCommandBase *pCommand) void SMConVarAccessor::MarkCommandsAsGameDLL() { - for (SourceHook::List::iterator iter = m_RegisteredCommands.begin(); + for (List::iterator iter = m_RegisteredCommands.begin(); iter != m_RegisteredCommands.end(); ++iter) { (*iter)->AddFlags(FCVAR_GAMEDLL); @@ -61,8 +64,8 @@ void SMConVarAccessor::Unregister(PluginId id, ConCommandBase *pCommand) { /* Notify via IMetamodListener */ PluginIter iter; - SourceMM::CPluginManager::CPlugin *pPlugin; - SourceHook::List::iterator event; + CPluginManager::CPlugin *pPlugin; + List::iterator event; IMetamodListener *pML; for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++) { @@ -217,65 +220,63 @@ CON_COMMAND(meta, "Metamod:Source Menu") return; } else if (strcmp(command, "list") == 0) { - SourceMM::CPluginManager::CPlugin *pl; + CPluginManager::CPlugin *pl; + ISmmPlugin *plapi; + const char *plname; PluginIter i; - const char *status=""; - const char *version=NULL; - const char *name=NULL; - const char *author=NULL; + char buffer[256]; + int len; + int plnum = g_PluginMngr.GetPluginCount(); - CONMSG("-Id- %-20.19s %-10.9s %-20.19s %-8.7s\n", "Name", "Version", "Author", "Status"); - for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++) + if (!plnum) + { + CONMSG("No plugins loaded.\n"); + return; + } else { + CONMSG("Listing %d plugin%s:\n", plnum, (plnum > 1) ? "s" : ""); + } + + for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++) { pl = (*i); if (!pl) + { break; - if (pl->m_Status == Pl_Paused) - { - status = "PAUSE"; - } else if (pl->m_Status == Pl_Running) { - if (pl->m_API && pl->m_API->QueryRunning(NULL, 0)) - status = "RUN"; - else - status = "STOPPED"; - } else if (pl->m_Status == Pl_Refused) { - status = "FAIL"; - } else if (pl->m_Status == Pl_Error) { - status = "ERROR"; - } else if (pl->m_Status == Pl_NotFound) { - status = "NOFILE"; } - if (pl->m_API) + len = 0; + + if (pl->m_Status != Pl_Running) { - version = pl->m_API->GetVersion(); - author = pl->m_API->GetAuthor(); - name = pl->m_API->GetName(); + len += UTIL_Format(buffer, sizeof(buffer), " [%02d] <%s>", pl->m_Id, g_PluginMngr.GetStatusText(pl)); } else { - version = "-"; - author = "-"; - name = "-"; + len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", pl->m_Id); } - if (!version) - version = "-"; - if (!author) - author = "-"; - if (!name) - name = pl->m_File.c_str(); + if ((plapi = pl->m_API)) + { + plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str(); + len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname); + if (IS_STR_FILLED(plapi->GetVersion())) + { + len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion()); + } + if (IS_STR_FILLED(plapi->GetAuthor())) + { + UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor()); + } + } - CONMSG("[%02d] %-20.19s %-10.9s %-20.19s %-8.7s\n", pl->m_Id, name, version, author, status); + CONMSG("%s\n", buffer); } - //CONMSG("\n"); - return; } else if (strcmp(command, "cmds") == 0) { if (args >= 3) { int id = atoi(e->Cmd_Argv(2)); - SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id); + CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id); if (!pl) { @@ -288,7 +289,7 @@ CON_COMMAND(meta, "Metamod:Source Menu") CONMSG("Plugin %d is not loaded.\n", id); } else { CONMSG("Console commands for %s:\n", pl->m_API->GetName()); - SourceHook::List::iterator ci; + List::iterator ci; size_t count = 0; for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++) @@ -306,7 +307,7 @@ CON_COMMAND(meta, "Metamod:Source Menu") if (args >= 3) { int id = atoi(e->Cmd_Argv(2)); - SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id); + CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id); if (!pl) { @@ -319,7 +320,7 @@ CON_COMMAND(meta, "Metamod:Source Menu") CONMSG("Plugin %d is not loaded.\n", id); } else { CONMSG("Registered cvars for %s:\n", pl->m_API->GetName()); - SourceHook::List::iterator ci; + List::iterator ci; size_t count = 0; for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++) @@ -337,7 +338,7 @@ CON_COMMAND(meta, "Metamod:Source Menu") if (args >= 3) { int id = atoi(e->Cmd_Argv(2)); - SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id); + CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id); if (!pl) { CONMSG("Plugin %d not found.\n", id); @@ -446,7 +447,7 @@ CON_COMMAND(meta, "Metamod:Source Menu") char error[255]={0}; bool already; - SourceMM::CPluginManager::CPlugin *pl; + CPluginManager::CPlugin *pl; PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error)); pl = g_PluginMngr.FindById(id); @@ -493,8 +494,8 @@ CON_COMMAND(meta, "Metamod:Source Menu") CONMSG("Alias \"%s\" was not found.\n", alias); } } else { - SourceHook::List::iterator iter, end; - SourceMM::CNameAlias *p; + List::iterator iter, end; + CNameAlias *p; iter = g_PluginMngr._alias_begin(); end = g_PluginMngr._alias_end(); @@ -547,8 +548,8 @@ CON_COMMAND(meta, "Metamod:Source Menu") g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s%s", g_ModPath.c_str(), file, ext); } - SourceHook::List::iterator iter, end; - SourceMM::CPluginManager::CPlugin *pl; + List::iterator iter, end; + CPluginManager::CPlugin *pl; iter = g_PluginMngr._begin(); end = g_PluginMngr._end(); for (; iter!=end; iter++) @@ -729,45 +730,49 @@ void ClientCommand_handler(edict_t *client) RETURN_META(MRES_SUPERCEDE); } else if(strcmp(subcmd, "list") == 0) { - SourceMM::CPluginManager::CPlugin *pl; - Pl_Status st; + CPluginManager::CPlugin *pl; + ISmmPlugin *plapi; + const char *plname; PluginIter i; - const char *version = NULL; - const char *name = NULL; - const char *author = NULL; - const char *status = NULL; + char buffer[256]; + int len = 0; + int plnum = 0; - CLIENT_CONMSG(client, "-Id- %-20.19s %-10.9s %-20.19s %6s\n", "Name", "Version", "Author", "Status"); - - for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++) + for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++, len=0) { pl = (*i); - if (!pl) - break; - - st = pl->m_Status; - - /* Only show plugins that are running or paused */ - if (pl->m_API && (st == Pl_Running || st == Pl_Paused)) + if (pl && pl->m_Status == Pl_Running) { - version = pl->m_API->GetVersion(); - author = pl->m_API->GetAuthor(); - name = pl->m_API->GetName(); - - if (st == Pl_Running && pl->m_API->QueryRunning(NULL, 0)) + plapi = pl->m_API; + if (!plapi || !plapi->QueryRunning(NULL, 0)) { - status = "RUN"; - } else { - status = "PAUSE"; + continue; + } + plnum++; + + len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", plnum); + + plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str(); + len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname); + + if (IS_STR_FILLED(plapi->GetVersion())) + { + len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion()); + } + if (IS_STR_FILLED(plapi->GetAuthor())) + { + UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor()); } - if (!version || !author || !name) - break; - - CLIENT_CONMSG(client, "[%02d] %-20.19s %-10.9s %-20.19s %6s\n", pl->m_Id, name, version, author, status); + CLIENT_CONMSG(client, "%s\n", buffer); } } + if (!plnum) + { + CLIENT_CONMSG(client, "No active plugins loaded.\n"); + } + RETURN_META(MRES_SUPERCEDE); } } diff --git a/sourcemm/util.h b/sourcemm/util.h index ed053bd..d02dd40 100644 --- a/sourcemm/util.h +++ b/sourcemm/util.h @@ -18,6 +18,11 @@ * @file util.h */ +/** + * @brief Returns true is string is not blank, false otherwise. + */ +#define IS_STR_FILLED(var) (var != NULL && var[0] != '\0') + /** * @brief Returns a pointer to the extension in a file name. */