Skip to content

Commit

Permalink
rel: Add find console command
Browse files Browse the repository at this point in the history
  • Loading branch information
PistonMiner committed Mar 27, 2021
1 parent 3912d9e commit 43560d3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ttyd-tools/rel/include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ConCommand
static ConCommand *sFirst;

friend class ConsoleSystem;
friend void CC_find(const char *args);
};

class ConIntVar
Expand Down Expand Up @@ -56,6 +57,7 @@ class ConIntVar
static ConIntVar *sFirst;

friend class ConsoleSystem;
friend void CC_find(const char *args);
};


Expand Down
19 changes: 19 additions & 0 deletions ttyd-tools/rel/source/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ ConIntVar con_log_fade("con_log_fade", 1);
ConIntVar con_log_fade_start("con_log_fade_start", 3000);
ConIntVar con_log_fade_duration("con_log_fade_duration", 1000);

void CC_find(const char *args)
{
char filter[128] = "";
if (sscanf(args, "%127s", filter) > 1)
return;

for (ConCommand *cc = ConCommand::sFirst; cc; cc = cc->next)
{
if (strstr(cc->name, filter))
gConsole->logInfo("%s [cmd]\n", cc->name);
}
for (ConIntVar *cv = ConIntVar::sFirst; cv; cv = cv->next)
{
if (strstr(cv->name, filter))
gConsole->logInfo("%s [int=%d]\n", cv->name, cv->value);
}
}
ConCommand find("find", CC_find);

static void DemoFontSetColor(gc::color4 color)
{
#if TTYD_US
Expand Down
29 changes: 29 additions & 0 deletions ttyd-tools/rel/source/util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "util.h"

#include <cstring>
#include <cstdint>

// TTYD doesn't use this so we reimplement it.
// TODO: Not the greatest solution in the long run
char *strstr(const char *container, const char *pattern)
{
int pattern_len = strlen(pattern);
for (const char *start = container; *start; ++start)
{
bool mismatch = false;
for (int i = 0; i < pattern_len; ++i)
{
if (!container[i] || start[i] != pattern[i])
{
mismatch = true;
break;
}
}
if (!mismatch)
{
// Cast away the const because C demands it
return (char *)start;
}
}
return nullptr;
}

0 comments on commit 43560d3

Please sign in to comment.