Cmd_AddCommand ("condump", Con_ConDump_f, "output console history to a file (see also log_file)");
con_initialized = true;
- Con_Print("Console initialized.\n");
+ Con_DPrint("Console initialized.\n");
}
// text[key_linepos + 1] = 0;
- x = vid_conwidth.value * 0.95 - DrawQ_TextWidth_Font(text, key_linepos, con_textsize.value, con_textsize.value, false, FONT_CONSOLE);
+ x = vid_conwidth.value * 0.95 - DrawQ_TextWidth_Font(text, key_linepos, false, FONT_CONSOLE) * con_textsize.value;
if(x >= 0)
x = 0;
ti->colorindex = -1;
return ti->fontsize * ti->font->width_of[0];
}
- return DrawQ_TextWidth_Font_UntilWidth(w, length, ti->fontsize, ti->fontsize, false, ti->font, maxWidth);
+ if(maxWidth >= 0)
+ return DrawQ_TextWidth_Font_UntilWidth(w, length, false, ti->font, maxWidth / ti->fontsize) * ti->fontsize;
+ else if(maxWidth == -1)
+ return DrawQ_TextWidth_Font(w, *length, false, ti->font) * ti->fontsize;
+ else
+ {
+ printf("Con_WordWidthFunc: can't get here (maxWidth should never be %f)\n", maxWidth);
+ // Note: this is NOT a Con_Printf, as it could print recursively
+ return 0;
+ }
}
int Con_CountLineFunc(void *passthrough, const char *line, size_t length, float width, qboolean isContinuation)
// FIXME word wrap
inputsize = (numChatlines ? con_chatsize : con_notifysize).value;
- x = vid_conwidth.value - DrawQ_TextWidth_Font(temptext, 0, inputsize, inputsize, false, FONT_CHAT);
+ x = vid_conwidth.value - DrawQ_TextWidth_Font(temptext, 0, false, FONT_CHAT) * inputsize;
if(x > 0)
x = 0;
DrawQ_String_Font(x, v, temptext, 0, inputsize, inputsize, 1.0, 1.0, 1.0, 1.0, 0, &colorindex, false, FONT_CHAT);
con_vislines = lines;
// draw the background
- DrawQ_Pic(0, lines - vid_conheight.integer, scr_conbrightness.value >= 0.01f ? Draw_CachePic("gfx/conback", true) : NULL, vid_conwidth.integer, vid_conheight.integer, scr_conbrightness.value, scr_conbrightness.value, scr_conbrightness.value, cls.signon == SIGNONS ? scr_conalpha.value : 1.0, 0); // always full alpha when not in game
- DrawQ_String_Font(vid_conwidth.integer - DrawQ_TextWidth_Font(engineversion, 0, con_textsize.value, con_textsize.value, false, FONT_CONSOLE), lines - con_textsize.value, engineversion, 0, con_textsize.value, con_textsize.value, 1, 0, 0, 1, 0, NULL, true, FONT_CONSOLE);
+ DrawQ_Pic(0, lines - vid_conheight.integer, scr_conbrightness.value >= 0.01f ? Draw_CachePic ("gfx/conback") : NULL, vid_conwidth.integer, vid_conheight.integer, scr_conbrightness.value, scr_conbrightness.value, scr_conbrightness.value, cls.signon == SIGNONS ? scr_conalpha.value : 1.0, 0); // always full alpha when not in game
+ DrawQ_String_Font(vid_conwidth.integer - DrawQ_TextWidth_Font(engineversion, 0, false, FONT_CONSOLE) * con_textsize.value, lines - con_textsize.value, engineversion, 0, con_textsize.value, con_textsize.value, 1, 0, 0, 1, 0, NULL, true, FONT_CONSOLE);
// draw the text
if(con_lines_count > 0)
its format (q1/q2/q3/hl) and even its message
*/
//[515]: here is an ugly hack.. two gotos... oh my... *but it works*
-//LordHavoc: rewrote bsp type detection, added mcbsp support and rewrote message extraction to do proper worldspawn parsing
+//LordHavoc: rewrote bsp type detection, rewrote message extraction to do proper worldspawn parsing
//LordHavoc: added .ent file loading, and redesigned error handling to still try the .ent file even if the map format is not recognized, this also eliminated one goto
//LordHavoc: FIXME: man this GetMapList is STILL ugly code even after my cleanups...
qboolean GetMapList (const char *s, char *completedname, int completednamebufferlength)
lumplen = LittleLong(header->lumps[Q2LUMP_ENTITIES].filelen);
}
}
- else if (!memcmp(buf, "MCBSPpad", 8))
- {
- p = LittleLong(((int *)buf)[2]);
- if (p == MCBSPVERSION)
- {
- int numhulls = LittleLong(((int *)buf)[3]);
- lumpofs = LittleLong(((int *)buf)[3 + numhulls + LUMP_ENTITIES*2+0]);
- lumplen = LittleLong(((int *)buf)[3 + numhulls + LUMP_ENTITIES*2+1]);
- }
- }
else if((p = LittleLong(((int *)buf)[0])) == BSPVERSION || p == 30)
{
dheader_t *header = (dheader_t *)buf;
case Q3BSPVERSION: strlcpy((char *)buf, "Q3", sizeof(buf));break;
case Q2BSPVERSION: strlcpy((char *)buf, "Q2", sizeof(buf));break;
case BSPVERSION: strlcpy((char *)buf, "Q1", sizeof(buf));break;
- case MCBSPVERSION: strlcpy((char *)buf, "MC", sizeof(buf));break;
case 30: strlcpy((char *)buf, "HL", sizeof(buf));break;
default: strlcpy((char *)buf, "??", sizeof(buf));break;
}
}
*out = 0;
}
-int Sbar_GetPlayer (int index); // <- safety?
// Now it becomes TRICKY :D --blub
static char Nicks_list[MAX_SCOREBOARD][MAX_SCOREBOARDNAME]; // contains the nicks with colors and all that
return Nicks_strncasecmp_nospaces(a, b, a_len);
return strncasecmp(a, b, a_len);
}
-
+
space_char = (con_nickcompletion_flags.integer & NICKS_NO_SPACES) ? 'a' : ' ';
-
+
// ignore non alphanumerics of B
// if A contains a non-alphanumeric, B must contain it as well though!
while(a_len)
{
qboolean alnum_a, alnum_b;
-
+
if(tolower(*a) == tolower(*b))
{
if(*a == 0) // end of both strings, they're equal
int match;
int spos;
int count = 0;
-
+
if(!con_nickcompletion.integer)
return 0;
// changed that to 1
if(!line[0])// || !line[1]) // we want at least... 2 written characters
return 0;
-
+
for(i = 0; i < cl.maxclients; ++i)
{
- /*p = Sbar_GetPlayer(i);
- if(p < 0)
- break;*/
p = i;
if(!cl.scores[p].name[0])
continue;
SanitizeString(cl.scores[p].name, name);
//Con_Printf("Sanitized: %s^7 -> %s", cl.scores[p].name, name);
-
+
if(!name[0])
continue;
-
+
length = strlen(name);
match = -1;
spos = pos - 1; // no need for a minimum of characters :)
-
+
while(spos >= 0 && (spos - pos) < length) // search-string-length < name length
{
if(spos > 0 && line[spos-1] != ' ' && line[spos-1] != ';' && line[spos-1] != '\"' && line[spos-1] != '\'')
{
Nicks_matchpos = match;
}
-
+
Nicks_offset[count] = s - (&line[match]);
//Con_Printf("offset for %s: %i\n", name, Nicks_offset[count]);
l = strlen(Nicks_sanlist[i]) - 1;
if(l < c)
c = l;
-
+
for(l = 0; l <= c; ++l)
if(tolower(Nicks_sanlist[0][l]) != tolower(Nicks_sanlist[i][l]))
{
char tempstr[sizeof(Nicks_sanlist[0])];
char *a, *b;
char space_char = (con_nickcompletion_flags.integer & NICKS_NO_SPACES) ? 'a' : ' '; // yes this is correct, we want NO spaces when no spaces
-
+
c = strlen(Nicks_sanlist[0]);
for(i = 0, l = 0; i < (int)c; ++i)
{
}
}
tempstr[l] = 0;
-
+
for(i = 1; i < count; ++i)
{
a = tempstr;
unsigned int c, l;
char tempstr[sizeof(Nicks_sanlist[0])];
char *a, *b;
-
+
c = strlen(Nicks_sanlist[0]);
for(i = 0, l = 0; i < (int)c; ++i)
{
}
}
tempstr[l] = 0;
-
+
for(i = 1; i < count; ++i)
{
a = tempstr;
buf[bpos] = Nicks_sanlist[bpos] + Nicks_offset[bpos];
Nicks_CutMatches(count);
-
+
buf[bpos] = NULL;
return buf;
}
qboolean quote_added = false;
int match;
char color = '7';
-
+
if(con_nickcompletion_flags.integer & NICKS_ADD_QUOTE && buffer[Nicks_matchpos-1] == '\"')
{
// we'll have to add a quote :)
buffer[pos++] = '\"';
quote_added = true;
}
-
+
if((!quote_added && con_nickcompletion_flags.integer & NICKS_ADD_COLOR) || con_nickcompletion_flags.integer & NICKS_FORCE_COLOR)
{
// add color when no quote was added, or when flags &4?
{
size_t len;
char *msg;
-
+
msg = Nicks_list[0];
len = min(size - Nicks_matchpos - 3, strlen(msg));
memcpy(&buffer[Nicks_matchpos], msg, len);
char *s;
const char **list[4] = {0, 0, 0, 0};
char s2[512];
+ char command[512];
int c, v, a, i, cmd_len, pos, k;
int n; // nicks --blub
-
+ const char *space, *patterns;
+
//find what we want to complete
pos = key_linepos;
while(--pos)
strlcpy(s2, key_lines[edit_line] + key_linepos, sizeof(s2)); //save chars after cursor
key_lines[edit_line][key_linepos] = 0; //hide them
- //maps search
- for(k=pos-1;k>2;k--)
- if(key_lines[edit_line][k] != ' ')
+ space = strchr(key_lines[edit_line] + 1, ' ');
+ if(space && pos == (space - key_lines[edit_line]) + 1)
+ {
+ strlcpy(command, key_lines[edit_line] + 1, min(sizeof(command), (unsigned int)(space - key_lines[edit_line])));
+
+ patterns = Cvar_VariableString(va("con_completion_%s", command)); // TODO maybe use a better place for this?
+ if(patterns && !*patterns)
+ patterns = NULL; // get rid of the empty string
+
+ if(!strcmp(command, "map") || !strcmp(command, "changelevel") || (patterns && !strcmp(patterns, "map")))
{
- if(key_lines[edit_line][k] == '\"' || key_lines[edit_line][k] == ';' || key_lines[edit_line][k] == '\'')
- break;
- if ((pos+k > 2 && !strncmp(key_lines[edit_line]+k-2, "map", 3))
- || (pos+k > 10 && !strncmp(key_lines[edit_line]+k-10, "changelevel", 11)))
+ //maps search
+ char t[MAX_QPATH];
+ if (GetMapList(s, t, sizeof(t)))
+ {
+ // first move the cursor
+ key_linepos += (int)strlen(t) - (int)strlen(s);
+
+ // and now do the actual work
+ *s = 0;
+ strlcat(key_lines[edit_line], t, MAX_INPUTLINE);
+ strlcat(key_lines[edit_line], s2, MAX_INPUTLINE); //add back chars after cursor
+
+ // and fix the cursor
+ if(key_linepos > (int) strlen(key_lines[edit_line]))
+ key_linepos = (int) strlen(key_lines[edit_line]);
+ }
+ return;
+ }
+ else
+ {
+ if(patterns)
{
char t[MAX_QPATH];
- if (GetMapList(s, t, sizeof(t)))
+ stringlist_t resultbuf, dirbuf;
+
+ // Usage:
+ // // store completion patterns (space separated) for command foo in con_completion_foo
+ // set con_completion_foo "foodata/*.foodefault *.foo"
+ // foo <TAB>
+ //
+ // Note: patterns with slash are always treated as absolute
+ // patterns; patterns without slash search in the innermost
+ // directory the user specified. There is no way to "complete into"
+ // a directory as of now, as directories seem to be unknown to the
+ // FS subsystem.
+ //
+ // Examples:
+ // set con_completion_playermodel "models/player/*.zym models/player/*.md3 models/player/*.psk models/player/*.dpm"
+ // set con_completion_playdemo "*.dem"
+ // set con_completion_play "*.wav *.ogg"
+ //
+ // TODO somehow add support for directories; these shall complete
+ // to their name + an appended slash.
+
+ stringlistinit(&resultbuf);
+ stringlistinit(&dirbuf);
+ while(COM_ParseToken_Simple(&patterns, false, false))
+ {
+ fssearch_t *search;
+ if(strchr(com_token, '/'))
+ {
+ search = FS_Search(com_token, true, true);
+ }
+ else
+ {
+ const char *slash = strrchr(s, '/');
+ if(slash)
+ {
+ strlcpy(t, s, min(sizeof(t), (unsigned int)(slash - s + 2))); // + 2, because I want to include the slash
+ strlcat(t, com_token, sizeof(t));
+ search = FS_Search(t, true, true);
+ }
+ else
+ search = FS_Search(com_token, true, true);
+ }
+ if(search)
+ {
+ for(i = 0; i < search->numfilenames; ++i)
+ if(!strncmp(search->filenames[i], s, strlen(s)))
+ if(FS_FileType(search->filenames[i]) == FS_FILETYPE_FILE)
+ stringlistappend(&resultbuf, search->filenames[i]);
+ FS_FreeSearch(search);
+ }
+ }
+
+ // In any case, add directory names
{
+ fssearch_t *search;
+ const char *slash = strrchr(s, '/');
+ if(slash)
+ {
+ strlcpy(t, s, min(sizeof(t), (unsigned int)(slash - s + 2))); // + 2, because I want to include the slash
+ strlcat(t, "*", sizeof(t));
+ search = FS_Search(t, true, true);
+ }
+ else
+ search = FS_Search("*", true, true);
+ if(search)
+ {
+ for(i = 0; i < search->numfilenames; ++i)
+ if(!strncmp(search->filenames[i], s, strlen(s)))
+ if(FS_FileType(search->filenames[i]) == FS_FILETYPE_DIRECTORY)
+ stringlistappend(&dirbuf, search->filenames[i]);
+ FS_FreeSearch(search);
+ }
+ }
+
+ if(resultbuf.numstrings > 0 || dirbuf.numstrings > 0)
+ {
+ const char *p, *q;
+ unsigned int matchchars;
+ if(resultbuf.numstrings == 0 && dirbuf.numstrings == 1)
+ {
+ dpsnprintf(t, sizeof(t), "%s/", dirbuf.strings[0]);
+ }
+ else
+ if(resultbuf.numstrings == 1 && dirbuf.numstrings == 0)
+ {
+ dpsnprintf(t, sizeof(t), "%s ", resultbuf.strings[0]);
+ }
+ else
+ {
+ stringlistsort(&resultbuf); // dirbuf is already sorted
+ Con_Printf("\n%i possible filenames\n", resultbuf.numstrings + dirbuf.numstrings);
+ for(i = 0; i < dirbuf.numstrings; ++i)
+ {
+ Con_Printf("%s/\n", dirbuf.strings[i]);
+ }
+ for(i = 0; i < resultbuf.numstrings; ++i)
+ {
+ Con_Printf("%s\n", resultbuf.strings[i]);
+ }
+ matchchars = sizeof(t) - 1;
+ if(resultbuf.numstrings > 0)
+ {
+ p = resultbuf.strings[0];
+ q = resultbuf.strings[resultbuf.numstrings - 1];
+ for(; *p && *p == *q; ++p, ++q);
+ matchchars = (unsigned int)(p - resultbuf.strings[0]);
+ }
+ if(dirbuf.numstrings > 0)
+ {
+ p = dirbuf.strings[0];
+ q = dirbuf.strings[dirbuf.numstrings - 1];
+ for(; *p && *p == *q; ++p, ++q);
+ matchchars = min(matchchars, (unsigned int)(p - dirbuf.strings[0]));
+ }
+ // now p points to the first non-equal character, or to the end
+ // of resultbuf.strings[0]. We want to append the characters
+ // from resultbuf.strings[0] to (not including) p as these are
+ // the unique prefix
+ strlcpy(t, (resultbuf.numstrings > 0 ? resultbuf : dirbuf).strings[0], min(matchchars + 1, sizeof(t)));
+ }
+
// first move the cursor
key_linepos += (int)strlen(t) - (int)strlen(s);
if(key_linepos > (int) strlen(key_lines[edit_line]))
key_linepos = (int) strlen(key_lines[edit_line]);
}
- return;
+ stringlistfreecontents(&resultbuf);
+ stringlistfreecontents(&dirbuf);
+
+ return; // bail out, when we complete for a command that wants a file name
}
}
+ }
// Count number of possible matches and print them
c = Cmd_CompleteCountPossible(s);
}
if (!(c + v + a + n)) // No possible matches
- {
+ {
if(s2[0])
strlcpy(&key_lines[edit_line][key_linepos], s2, sizeof(key_lines[edit_line]) - key_linepos);
return;
cmd = *(list[2] = Cmd_CompleteAliasBuildList(s));
if (n)
cmd = *(list[3] = Nicks_CompleteBuildList(n));
-
+
for (cmd_len = (int)strlen(s);;cmd_len++)
{
const char **l;