Skip to content

Commit

Permalink
tidy up tab complete auto hints
Browse files Browse the repository at this point in the history
  • Loading branch information
timbergeron committed Sep 2, 2023
1 parent 2c87487 commit 3363030
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
51 changes: 15 additions & 36 deletions Quake/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,15 @@ void Cmd_List_f (void)
}

count=0;
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
for (cmd = cmd_functions; cmd; cmd = cmd->next)
{
if (partial && Q_strncmp (partial,cmd->name, len))
{
if (cmd->srctype == src_server)
continue;
}
Con_SafePrintf (" %s\n", cmd->name);
if (Cmd_IsReservedName(cmd->name))
continue;
if (partial && Q_strncmp(partial, cmd->name, len))
continue;
Con_SafePrintf(" %s\n", cmd->name);
count++;
}

Expand All @@ -622,21 +624,6 @@ void Cmd_List_f (void)
Con_SafePrintf ("\n");
}

static char *Cmd_TintSubstring(const char *in, const char *substr, char *out, size_t outsize)
{
int l;
char *m;
q_strlcpy(out, in, outsize);
while ((m = q_strcasestr(out, substr)))
{
l = strlen(substr);
while (l-->0)
if (*m >= ' ' && *m < 127)
*m++ |= 0x80;
}
return out;
}

/*
============
Cmd_ListAllContaining
Expand All @@ -649,38 +636,30 @@ static void Cmd_ListAllContaining(const char* substr)
{
char tmpbuf[256];
int hits = 0;
cmd_function_t *cmd;
cvar_t *var;
cmdalias_t* alias;
cmd_function_t* cmd;
cvar_t* var;
const char* plural;
const char* plural2; // woods #addaliases

for (alias = cmd_alias; alias; alias = alias->next) // woods #addaliases
{
if (q_strcasestr(alias->name, substr))
{
hits++;
Con_SafePrintf(" %s (alias)\n", Cmd_TintSubstring(alias->name, substr, tmpbuf, sizeof(tmpbuf)));
}
}

for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
for (cmd = cmd_functions; cmd; cmd = cmd->next)
{
if (q_strcasestr(cmd->name, substr) && cmd->srctype != src_server)
if (cmd->srctype != src_server && q_strcasestr(cmd->name, substr) && !Cmd_IsReservedName(cmd->name))
{
hits++;
Con_SafePrintf (" %s\n", Cmd_TintSubstring(cmd->name, substr, tmpbuf, sizeof(tmpbuf)));
Con_SafePrintf(" %s\n", COM_TintSubstring(cmd->name, substr, tmpbuf, sizeof(tmpbuf)));
}
}

for (var=Cvar_FindVarAfter("", 0) ; var ; var=var->next)
for (var = Cvar_FindVarAfter("", 0) ; var; var=var->next)
{
if (q_strcasestr(var->name, substr))
{
hits++;
Con_SafePrintf (" %s (current value: \"%s\")\n", Cmd_TintSubstring(var->name, substr, tmpbuf, sizeof(tmpbuf)), var->string);
Con_SafePrintf (" %s (current value: \"%s\")\n", COM_TintSubstring(var->name, substr, tmpbuf, sizeof(tmpbuf)), var->string);
}
}

plural = (hits == 1) ? "" : "s";
plural2 = (hits == 1) ? "" : "es"; // woods #addaliases
if (!hits)
Expand Down
23 changes: 23 additions & 0 deletions Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,29 @@ char* COM_TintSubstring(const char* in, const char* substr, char* out, size_t ou
return out;
}

/*
================
COM_TintString -- woods (ironwail)
================
*/
char* COM_TintString(const char* in, char* out, size_t outsize)
{
char* ret = out;
if (!outsize)
return "";
--outsize;
while (*in && outsize > 0)
{
char c = *in++;
if (c > ' ')
c |= 0x80;
*out++ = c;
--outsize;
}
*out++ = '\0';
return ret;
}

/*
spike -- this function simply says whether a filename is acceptable for downloading (used by both client+server)
*/
Expand Down
1 change: 1 addition & 0 deletions Quake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ char *va (const char *format, ...) FUNC_PRINTF(1,2);
// does a varargs printf into a temp buffer

char* COM_TintSubstring(const char* in, const char* substr, char* out, size_t outsize); // woods add filter (ironwail)
char* COM_TintString(const char* in, char* out, size_t outsize); // woods (ironwail)

unsigned COM_HashString (const char *str);

Expand Down
3 changes: 3 additions & 0 deletions Quake/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,9 @@ void Con_TabComplete (tabcomplete_t mode)
{
key_tabpartial[0] = '\0';

if ((key_lines[edit_line][1] == ' ')) // woods no auto hints if leading space for chatting from console
return;

// only show completion hint when the cursor is at the end of the line
if ((size_t)key_linepos >= sizeof(key_lines[edit_line]) || key_lines[edit_line][key_linepos])
return;
Expand Down
3 changes: 1 addition & 2 deletions Quake/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ void Host_Init (void)

V_Init ();
Chase_Init ();
M_Init (); // woods move this up for tab complete system #iwtabcomplete
ExtraMaps_Init (); //johnfitz
Modlist_Init (); //johnfitz
DemoList_Init (); //ericw
Expand Down Expand Up @@ -1501,8 +1502,6 @@ void Host_Init (void)
Cbuf_AddText ("alias startmap_sp \"map start\"\n");
Cbuf_AddText ("alias startmap_dm \"map start\"\n");

if (cls.state != ca_dedicated)
M_Init ();
if (setjmp (host_abortserver) )
return; // don't do the above twice if the following Cbuf_Execute does bad things.

Expand Down
1 change: 1 addition & 0 deletions Quake/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ void Key_Console (int key)
key_lines[edit_line][0] = ']';
key_lines[edit_line][1] = 0; //johnfitz -- otherwise old history items show up in the new edit line
key_linepos = 1;
key_tabhint[0] = '\0'; // woods #iwtabcomplete
if (cls.state == ca_disconnected)
SCR_UpdateScreen (); // force an update, because the command may take some time
if (cl_say.value == 2 || cl_say.value == 3) // woods #ezsay add leading space for mode 2
Expand Down

0 comments on commit 3363030

Please sign in to comment.