mirror of
https://github.com/rehlds/metamod-r.git
synced 2025-02-04 17:50:52 +03:00
Implemented a dynamic indent in the output meta list for avoid truncation of field to desc, vers, file.
This commit is contained in:
parent
14c3001b3a
commit
c0155f8f1d
@ -145,9 +145,12 @@ inline char *_strlwr(char *start)
|
|||||||
#endif // #if defined(ASMLIB_H) && defined(HAVE_OPT_STRTOOLS)
|
#endif // #if defined(ASMLIB_H) && defined(HAVE_OPT_STRTOOLS)
|
||||||
|
|
||||||
// a safe variant of strcpy that truncates the result to fit in the destination buffer
|
// a safe variant of strcpy that truncates the result to fit in the destination buffer
|
||||||
template <size_t size>
|
template <typename T, size_t size>
|
||||||
char *Q_strlcpy(char (&dest)[size], const char *src) {
|
T *Q_strlcpy(T (&dest)[size], const char *src)
|
||||||
Q_strncpy(dest, src, size - 1);
|
{
|
||||||
|
static_assert(sizeof(T) == sizeof(char), "invalid size of type != sizeof(char)");
|
||||||
|
|
||||||
|
Q_strncpy((char *)dest, src, size - 1);
|
||||||
dest[size - 1] = '\0';
|
dest[size - 1] = '\0';
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
@ -160,9 +163,11 @@ inline char *Q_strnlcpy(char *dest, const char *src, size_t n) {
|
|||||||
|
|
||||||
// safely concatenate two strings.
|
// safely concatenate two strings.
|
||||||
// a variant of strcat that truncates the result to fit in the destination buffer
|
// a variant of strcat that truncates the result to fit in the destination buffer
|
||||||
template <size_t size>
|
template <typename T, size_t size>
|
||||||
size_t Q_strlcat(char (&dest)[size], const char *src)
|
size_t Q_strlcat(T (&dest)[size], const char *src)
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof(T) == sizeof(char), "invalid size of type != sizeof(char)");
|
||||||
|
|
||||||
size_t srclen; // Length of source string
|
size_t srclen; // Length of source string
|
||||||
size_t dstlen; // Length of destination string
|
size_t dstlen; // Length of destination string
|
||||||
|
|
||||||
|
@ -577,20 +577,59 @@ void MPluginList::retry_all(PLUG_LOADTIME now)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MPluginList::getWidthFields(int source_index, size_t &widthDescBest, size_t &widthFileBest, size_t &widthVersBest)
|
||||||
|
{
|
||||||
|
for (auto p : m_plugins)
|
||||||
|
{
|
||||||
|
if (p->m_status < PL_VALID)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// List plugins and information about them in a formatted table.
|
// List plugins and information about them in a formatted table.
|
||||||
void MPluginList::show(int source_index)
|
void MPluginList::show(int source_index)
|
||||||
{
|
{
|
||||||
int n = 0, r = 0;
|
|
||||||
char desc[15 + 1], file[16 + 1], vers[7 + 1]; // plus 1 for term null
|
|
||||||
|
|
||||||
if (source_index <= 0)
|
if (source_index <= 0)
|
||||||
META_CONS("Currently loaded plugins:");
|
META_CONS("Currently loaded plugins:");
|
||||||
else
|
else
|
||||||
META_CONS("Child plugins:");
|
META_CONS("Child plugins:");
|
||||||
|
|
||||||
META_CONS(" %*s %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, "", sizeof desc - 1, "description", "stat", "pend",
|
size_t nWidthDesc = 0, nWidthFile = 0, nWidthVers = 0;
|
||||||
sizeof file - 1, "file", sizeof vers - 1, "ers", 2 + WIDTH_MAX_PLUGINS, "src", "load ", "unlod");
|
getWidthFields(source_index, nWidthDesc, nWidthFile, nWidthVers);
|
||||||
|
|
||||||
|
char *desc = new char[nWidthDesc + 1]; // + 1 for term null
|
||||||
|
char *file = new char[nWidthFile + 1];
|
||||||
|
char *vers = new char[nWidthVers + 1];
|
||||||
|
|
||||||
|
META_CONS(" %*s %-*s %-4s %-4s %-*s v%-*s %-3s %-5s %-5s",
|
||||||
|
WIDTH_MAX_PLUGINS, "", nWidthDesc, "description", "stat", "pend", nWidthFile, "file", nWidthVers, "ers", "src", "load ", "unload");
|
||||||
|
|
||||||
|
int nPlugins = 0, nRunPlugins = 0;
|
||||||
for (auto p : m_plugins) {
|
for (auto p : m_plugins) {
|
||||||
if (p->m_status < PL_VALID)
|
if (p->m_status < PL_VALID)
|
||||||
continue;
|
continue;
|
||||||
@ -598,31 +637,31 @@ void MPluginList::show(int source_index)
|
|||||||
if (source_index > 0 && p->m_source_plugin_index != source_index)
|
if (source_index > 0 && p->m_source_plugin_index != source_index)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Q_strncpy(desc, p->m_desc, sizeof desc - 1);
|
Q_strcpy(desc, p->m_desc);
|
||||||
desc[sizeof desc - 1] = '\0';
|
Q_strcpy(file, p->m_file);
|
||||||
|
|
||||||
Q_strncpy(file, p->m_file, sizeof file - 1);
|
|
||||||
file[sizeof file - 1] = '\0';
|
|
||||||
|
|
||||||
if (p->info() && p->info()->version) {
|
if (p->info() && p->info()->version) {
|
||||||
Q_strncpy(vers, p->info()->version, sizeof vers - 1);
|
Q_strcpy(vers, p->info()->version);
|
||||||
vers[sizeof vers - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Q_strncpy(vers, " -", sizeof vers - 1);
|
Q_strcpy(vers, " -");
|
||||||
vers[sizeof vers - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, p->m_index,
|
META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-3s %-5s %-5s", WIDTH_MAX_PLUGINS, p->m_index,
|
||||||
sizeof desc - 1, desc, p->str_status(ST_SHOW), p->str_action(SA_SHOW), sizeof file - 1, file, sizeof vers - 1, vers,
|
nWidthDesc, desc, p->str_status(ST_SHOW), p->str_action(SA_SHOW), nWidthFile, file, nWidthVers, vers,
|
||||||
2 + WIDTH_MAX_PLUGINS, p->str_source(SO_SHOW), p->str_loadable(SL_SHOW), p->str_unloadable(SL_SHOW));
|
p->str_source(SO_SHOW), p->str_loadable(SL_SHOW), p->str_unloadable(SL_SHOW));
|
||||||
|
|
||||||
if (p->m_status == PL_RUNNING)
|
if (p->m_status == PL_RUNNING)
|
||||||
r++;
|
nRunPlugins++;
|
||||||
n++;
|
|
||||||
|
nPlugins++;
|
||||||
}
|
}
|
||||||
|
|
||||||
META_CONS("%d plugins, %d running", n, r);
|
META_CONS("%d plugins, %d running", nPlugins, nRunPlugins);
|
||||||
|
|
||||||
|
delete [] desc;
|
||||||
|
delete [] file;
|
||||||
|
delete [] vers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List plugins and information to Player/client entity. Differs from the
|
// List plugins and information to Player/client entity. Differs from the
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
void show(int source_index = 0); // list plugins to console
|
void show(int source_index = 0); // list plugins to console
|
||||||
void show_client(edict_t* pEntity); // list plugins to player client
|
void show_client(edict_t* pEntity); // list plugins to player client
|
||||||
void clear_source_plugin_index(int source_index);
|
void clear_source_plugin_index(int source_index);
|
||||||
|
void getWidthFields(int source_index, size_t &widthDescBest, size_t &widthFileBest, size_t &widthVersBest);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_last_index;
|
size_t m_last_index;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user