From e343dfe9058f02d7534a3eee72d92f1613fe723a Mon Sep 17 00:00:00 2001 From: s1lent Date: Sat, 18 Nov 2017 21:25:25 +0700 Subject: [PATCH] Reworked MPluginList::getWidthFields Fix typo in MPlugin::str_action --- metamod/src/mlist.cpp | 31 +++++++++---------------------- metamod/src/mplugin.cpp | 2 +- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/metamod/src/mlist.cpp b/metamod/src/mlist.cpp index 891247c..422beb7 100644 --- a/metamod/src/mlist.cpp +++ b/metamod/src/mlist.cpp @@ -579,6 +579,11 @@ void MPluginList::retry_all(PLUG_LOADTIME now) void MPluginList::getWidthFields(int source_index, size_t &widthDescBest, size_t &widthFileBest, size_t &widthVersBest) { + // width by default + widthDescBest = sizeof("description") - 1; + widthFileBest = sizeof("file") - 1; + widthVersBest = sizeof("vers") - 1; + for (auto p : m_plugins) { if (p->m_status < PL_VALID) @@ -587,27 +592,9 @@ void MPluginList::getWidthFields(int source_index, size_t &widthDescBest, size_t if (source_index > 0 && p->m_source_plugin_index != source_index) continue; - size_t nDescLen = Q_strlen(p->m_desc); - if (widthDescBest < nDescLen) { - widthDescBest = nDescLen; - } - - size_t nFileLen = Q_strlen(p->m_file); - if (widthFileBest < nFileLen) { - widthFileBest = nFileLen; - } - - size_t nVersLen; - if (p->info() && p->info()->version) { - nVersLen = Q_strlen(p->info()->version); - } - else { - nVersLen = sizeof(" -") - 1; - } - - if (widthVersBest < nVersLen) { - widthVersBest = nVersLen; - } + widthDescBest = Q_max(widthDescBest, Q_strlen(p->m_desc)); + widthFileBest = Q_max(widthFileBest, Q_strlen(p->m_file)); + widthVersBest = Q_max(widthVersBest, (p->info() && p->info()->version) ? Q_strlen(p->info()->version) : sizeof(" -") - 1); } } @@ -619,7 +606,7 @@ void MPluginList::show(int source_index) else META_CONS("Child plugins:"); - size_t nWidthDesc = 0, nWidthFile = 0, nWidthVers = 0; + size_t nWidthDesc, nWidthFile, nWidthVers; getWidthFields(source_index, nWidthDesc, nWidthFile, nWidthVers); char *desc = new char[nWidthDesc + 1]; // + 1 for term null diff --git a/metamod/src/mplugin.cpp b/metamod/src/mplugin.cpp index d072ded..0195d82 100644 --- a/metamod/src/mplugin.cpp +++ b/metamod/src/mplugin.cpp @@ -1155,7 +1155,7 @@ const char *MPlugin::str_status(STR_STATUS fmt) const // SHOW is max 4 chars, for "show" output. const char *MPlugin::str_action(STR_ACTION fmt) const { - bool show = fmt == ST_SHOW; + bool show = fmt == SA_SHOW; switch (m_action) { case PA_NULL: return "null"; case PA_NONE: return show ? " - " : "none";