console.c: Steven's patch adding argument completion to map and changelevel

commands.  this is not a true argument completion, only a tiny hack for the
two aforementioned commands.


git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@65 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2010-02-19 16:35:13 +00:00
parent ebb08e594b
commit 11614c482b
1 changed files with 85 additions and 0 deletions

View File

@ -754,6 +754,7 @@ tablist is a doubly-linked loop, alphabetized by name
// aka Linux Bash shell. -- S.A.
static char bash_partial[80];
static qboolean bash_singlematch;
static qboolean map_singlematch;
void AddToTabList (char *name, char *type)
{
@ -814,6 +815,70 @@ void AddToTabList (char *name, char *type)
}
}
// This is redefined from host_cmd.c
typedef struct extralevel_s
{
char name[32];
struct extralevel_s *next;
} extralevel_t;
extern extralevel_t *extralevels;
/*
============
BuildMap -- stevenaaus
============
*/
char *BuildMapList (char *partial)
{
int i , match, plen;
static char matched[80];
char *i_matched, *i_name;
extralevel_t *level;
memset(matched, 0, 80);
plen = strlen(partial);
match = 0;
for (level = extralevels, i = 0; level; level = level->next, i++)
{
if (!strncmp(level->name, partial, plen))
{
if (!*matched)
{
strncpy (matched, level->name, 79);
matched[79] = '\0';
}
else
{ // find max common
i_matched = matched;
i_name = level->name;
while (*i_matched && (*i_matched == *i_name))
{
i_matched++;
i_name++;
}
*i_matched = 0;
}
match++;
}
}
map_singlematch = (match == 1);
if (match > 1)
{
for (level = extralevels, i = 0; level; level = level->next, i++)
{
if (!strncmp(level->name, partial, plen))
Con_SafePrintf (" %s\n", level->name);
}
Con_SafePrintf ("\n");
}
return matched;
}
/*
============
BuildTabList -- johnfitz
@ -875,6 +940,26 @@ void Con_TabComplete (void)
partial[i] = c[i];
partial[i] = 0;
// Map autocomplete function -- S.A
// Since we don't have argument completion, this hack will do for now...
if (!strncmp (key_lines[edit_line] + 1, "map ",4) ||
!strncmp (key_lines[edit_line] + 1, "changelevel ", 12))
{
char *matched_map = BuildMapList(partial);
if (!*matched_map)
return;
Q_strcpy (partial, matched_map);
Q_strcpy (c, partial);
key_linepos = c - key_lines[edit_line] + Q_strlen(matched_map); //set new cursor position
if ((key_lines[edit_line][key_linepos] == 0) && map_singlematch)
{
key_lines[edit_line][key_linepos] = ' ';
key_linepos++;
key_lines[edit_line][key_linepos] = 0;
}
return;
}
//if partial is empty, return
if (partial[0] == 0)
return;