2001-07-16 21:39:50 +00:00
|
|
|
/*
|
|
|
|
complete.c
|
|
|
|
|
|
|
|
command completion
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-07-16 21:39:50 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-09-10 12:56:23 +00:00
|
|
|
|
2001-07-16 21:39:50 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2007-03-20 21:31:07 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
2007-03-20 21:31:07 +00:00
|
|
|
#include "QF/plugin.h"
|
|
|
|
#include "QF/va.h"
|
|
|
|
#include "compat.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2001-09-10 12:56:23 +00:00
|
|
|
/*
|
|
|
|
Con_BasicCompleteCommandLine
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2001-09-10 12:56:23 +00:00
|
|
|
New function for tab-completion system
|
|
|
|
Added by EvilTypeGuy
|
|
|
|
Thanks to Fett erich@heintz.com
|
|
|
|
Thanks to taniwha
|
2001-07-16 21:39:50 +00:00
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
__attribute__((visibility ("default")))
|
2001-07-16 21:39:50 +00:00
|
|
|
void
|
2001-07-18 18:29:38 +00:00
|
|
|
Con_BasicCompleteCommandLine (inputline_t *il)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
char *s;
|
|
|
|
const char *cmd = "", **list[3] = {0, 0, 0};
|
2007-03-20 21:31:07 +00:00
|
|
|
int cmd_len, c, i, v, o;
|
2007-03-22 23:20:57 +00:00
|
|
|
cbuf_t *cbuf;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2001-07-18 18:29:38 +00:00
|
|
|
s = il->lines[il->edit_line] + 1;
|
2007-03-20 21:31:07 +00:00
|
|
|
|
2001-07-16 21:39:50 +00:00
|
|
|
if (*s == '\\' || *s == '/')
|
|
|
|
s++;
|
|
|
|
|
2007-03-20 21:31:07 +00:00
|
|
|
s = strdup(s);
|
|
|
|
|
2007-03-22 23:20:57 +00:00
|
|
|
cbuf = con_module->data->console->cbuf;
|
2007-03-20 21:31:07 +00:00
|
|
|
|
|
|
|
if (cbuf->interpreter->complete)
|
|
|
|
{
|
|
|
|
const char** completions = cbuf->interpreter->complete(cbuf, s);
|
|
|
|
const char** com;
|
|
|
|
|
|
|
|
for (o = 0, com = completions; *com; com++, o++)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
c = v = 0;
|
|
|
|
|
|
|
|
list[2] = completions;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Count number of possible matches
|
|
|
|
c = Cmd_CompleteCountPossible(s);
|
|
|
|
v = Cvar_CompleteCountPossible(s);
|
|
|
|
o = 0;
|
|
|
|
}
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2007-03-20 21:31:07 +00:00
|
|
|
if (!(c + v + o)) // No possible matches
|
2001-07-16 21:39:50 +00:00
|
|
|
return;
|
|
|
|
|
2007-03-20 21:31:07 +00:00
|
|
|
if (c + v + o == 1) {
|
2001-07-16 21:39:50 +00:00
|
|
|
if (c)
|
2007-03-20 21:31:07 +00:00
|
|
|
{
|
2001-07-16 21:39:50 +00:00
|
|
|
list[0] = Cmd_CompleteBuildList(s);
|
2007-03-20 21:31:07 +00:00
|
|
|
cmd = *list[0];
|
|
|
|
}
|
|
|
|
else if (v)
|
|
|
|
{
|
2002-06-01 22:13:14 +00:00
|
|
|
list[0] = Cvar_CompleteBuildList(s);
|
2007-03-20 21:31:07 +00:00
|
|
|
cmd = *list[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmd = *list[2];
|
|
|
|
}
|
2001-07-16 21:39:50 +00:00
|
|
|
cmd_len = strlen (cmd);
|
|
|
|
} else {
|
|
|
|
if (c)
|
|
|
|
cmd = *(list[0] = Cmd_CompleteBuildList(s));
|
|
|
|
if (v)
|
|
|
|
cmd = *(list[1] = Cvar_CompleteBuildList(s));
|
2007-03-20 21:31:07 +00:00
|
|
|
if (o)
|
|
|
|
cmd = *(list[2]);
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2007-03-20 21:31:07 +00:00
|
|
|
cmd_len = 0;
|
2001-07-16 21:39:50 +00:00
|
|
|
do {
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
char ch = cmd[cmd_len];
|
|
|
|
const char **l = list[i];
|
|
|
|
if (l) {
|
|
|
|
while (*l && (*l)[cmd_len] == ch)
|
|
|
|
l++;
|
|
|
|
if (*l)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == 3)
|
|
|
|
cmd_len++;
|
|
|
|
} while (i == 3);
|
|
|
|
// 'quakebar'
|
|
|
|
Con_Printf("\n\35");
|
|
|
|
for (i = 0; i < con_linewidth - 4; i++)
|
|
|
|
Con_Printf("\36");
|
|
|
|
Con_Printf("\37\n");
|
|
|
|
|
|
|
|
// Print Possible Commands
|
|
|
|
if (c) {
|
|
|
|
Con_Printf("%i possible command%s\n", c, (c > 1) ? "s: " : ":");
|
|
|
|
Con_DisplayList(list[0], con_linewidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v) {
|
|
|
|
Con_Printf("%i possible variable%s\n", v, (v > 1) ? "s: " : ":");
|
|
|
|
Con_DisplayList(list[1], con_linewidth);
|
|
|
|
}
|
2007-03-20 21:31:07 +00:00
|
|
|
if (o) {
|
|
|
|
Con_Printf("%i possible matche%s\n", o, (o > 1) ? "s: " : ":");
|
|
|
|
Con_DisplayList(list[2], con_linewidth);
|
|
|
|
}
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd) {
|
2007-03-21 01:41:15 +00:00
|
|
|
unsigned int bound = max(0, (int) strlen(s) - (int) cmd_len);
|
2007-03-22 23:20:57 +00:00
|
|
|
const char* overwrite;
|
2007-03-20 21:31:07 +00:00
|
|
|
|
2007-03-21 01:41:15 +00:00
|
|
|
if (cmd_len > 0) while (bound < strlen(s) && strncmp(s+bound, cmd, strlen(s+bound))) bound++;
|
2007-03-20 21:31:07 +00:00
|
|
|
|
2007-03-22 23:20:57 +00:00
|
|
|
overwrite = va("%.*s%.*s", bound, s, cmd_len, cmd);
|
2007-03-20 21:31:07 +00:00
|
|
|
|
2001-07-18 18:29:38 +00:00
|
|
|
il->lines[il->edit_line][1] = '/';
|
2007-03-20 21:31:07 +00:00
|
|
|
strncpy(il->lines[il->edit_line] + 2, overwrite, strlen(overwrite));
|
|
|
|
il->linepos = strlen(overwrite) + 2;
|
2007-03-27 09:41:04 +00:00
|
|
|
if (c + v == 1 && !o) {
|
2001-07-18 18:29:38 +00:00
|
|
|
il->lines[il->edit_line][il->linepos] = ' ';
|
|
|
|
il->linepos++;
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
2001-07-18 18:29:38 +00:00
|
|
|
il->lines[il->edit_line][il->linepos] = 0;
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
if (list[i])
|
2007-03-22 23:20:57 +00:00
|
|
|
free ((void*)list[i]);
|
2007-03-20 21:31:07 +00:00
|
|
|
|
|
|
|
free(s);
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|