#define NICKS_ALPHANUMERICS_ONLY 8
#define NICKS_NO_SPACES 16
+cvar_t con_completion_playdemo = {CVAR_SAVE, "con_completion_playdemo", "*.dem"};
+cvar_t con_completion_timedemo = {CVAR_SAVE, "con_completion_timedemo", "*.dem"};
+cvar_t con_completion_exec = {CVAR_SAVE, "con_completion_exec", "*.cfg"};
+
int con_linewidth;
int con_vislines;
qboolean con_initialized;
// used for server replies to rcon command
-qboolean rcon_redirect = false;
+lhnetsocket_t *rcon_redirect_sock = NULL;
+lhnetaddress_t *rcon_redirect_dest = NULL;
int rcon_redirect_bufferpos = 0;
char rcon_redirect_buffer[1400];
{
static char timestamp [128];
time_t crt_time;
- const struct tm *crt_tm;
+#if _MSC_VER >= 1400
+ struct tm crt_tm;
+#else
+ struct tm *crt_tm;
+#endif
char timestring [64];
// Build the time stamp (ex: "Wed Jun 30 21:49:08 1993");
time (&crt_time);
+#if _MSC_VER >= 1400
+ localtime_s (&crt_tm, &crt_time);
+ strftime (timestring, sizeof (timestring), "%a %b %d %H:%M:%S %Y", &crt_tm);
+#else
crt_tm = localtime (&crt_time);
strftime (timestring, sizeof (timestring), "%a %b %d %H:%M:%S %Y", crt_tm);
+#endif
if (desc != NULL)
dpsnprintf (timestamp, sizeof (timestamp), "====== %s (%s) ======\n", desc, timestring);
if (logfile != NULL || log_file.string[0] == '\0')
return;
- logfile = FS_Open (log_file.string, "ab", false, false);
+ logfile = FS_OpenRealFile(log_file.string, "a", false);
if (logfile != NULL)
{
strlcpy (crt_log_file, log_file.string, sizeof (crt_log_file));
{
qfile_t *file;
- file = FS_Open (logfilename, "ab", true, false);
+ file = FS_OpenRealFile(logfilename, "a", true);
if (file != NULL)
{
va_list argptr;
void Con_MessageMode_f (void)
{
key_dest = key_message;
- chat_team = false;
+ chat_mode = 0; // "say"
}
void Con_MessageMode2_f (void)
{
key_dest = key_message;
- chat_team = true;
+ chat_mode = 1; // "say_team"
}
+/*
+================
+Con_CommandMode_f
+================
+*/
+void Con_CommandMode_f (void)
+{
+ key_dest = key_message;
+ if(Cmd_Argc() > 1)
+ {
+ dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args());
+ chat_bufferlen = strlen(chat_buffer);
+ }
+ chat_mode = -1; // command
+}
/*
================
Con_Printf("usage: condump <filename>\n");
return;
}
- file = FS_Open(Cmd_Argv(1), "wb", false, false);
+ file = FS_OpenRealFile(Cmd_Argv(1), "w", false);
if (!file)
{
Con_Printf("condump: unable to write file \"%s\"\n", Cmd_Argv(1));
Cvar_RegisterVariable (&con_nickcompletion);
Cvar_RegisterVariable (&con_nickcompletion_flags);
+ Cvar_RegisterVariable (&con_completion_playdemo); // *.dem
+ Cvar_RegisterVariable (&con_completion_timedemo); // *.dem
+ Cvar_RegisterVariable (&con_completion_exec); // *.cfg
+
// register our commands
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f, "opens or closes the console");
Cmd_AddCommand ("messagemode", Con_MessageMode_f, "input a chat message to say to everyone");
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f, "input a chat message to say to only your team");
+ Cmd_AddCommand ("commandmode", Con_CommandMode_f, "input a console command");
Cmd_AddCommand ("clear", Con_Clear_f, "clear console history");
Cmd_AddCommand ("maps", Con_Maps_f, "list information about available maps");
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");
}
'x', 'y', 'z', '{', '|', '}', '~', '<'
};
+void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest)
+{
+ rcon_redirect_sock = sock;
+ rcon_redirect_dest = dest;
+ memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print
+ rcon_redirect_bufferpos = 5;
+}
+
+void Con_Rcon_Redirect_Flush()
+{
+ rcon_redirect_buffer[rcon_redirect_bufferpos] = 0;
+ NetConn_WriteString(rcon_redirect_sock, rcon_redirect_buffer, rcon_redirect_dest);
+ memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print
+ rcon_redirect_bufferpos = 5;
+}
+
+void Con_Rcon_Redirect_End()
+{
+ Con_Rcon_Redirect_Flush();
+ rcon_redirect_dest = NULL;
+ rcon_redirect_sock = NULL;
+}
+
+void Con_Rcon_Redirect_Abort()
+{
+ rcon_redirect_dest = NULL;
+ rcon_redirect_sock = NULL;
+}
+
/*
================
Con_Rcon_AddChar
// if this print is in response to an rcon command, add the character
// to the rcon redirect buffer
- if (rcon_redirect && rcon_redirect_bufferpos < (int)sizeof(rcon_redirect_buffer) - 1)
+ if (rcon_redirect_dest)
+ {
rcon_redirect_buffer[rcon_redirect_bufferpos++] = c;
+ if(rcon_redirect_bufferpos >= (int)sizeof(rcon_redirect_buffer) - 1)
+ Con_Rcon_Redirect_Flush();
+ }
else if(*log_dest_udp.string) // don't duplicate rcon command responses here, these are sent another way
{
if(log_dest_buffer_pos == 0)
--log_dest_buffer_appending;
}
+/**
+ * Convert an RGB color to its nearest quake color.
+ * I'll cheat on this a bit by translating the colors to HSV first,
+ * S and V decide if it's black or white, otherwise, H will decide the
+ * actual color.
+ * @param _r Red (0-255)
+ * @param _g Green (0-255)
+ * @param _b Blue (0-255)
+ * @return A quake color character.
+ */
+static char Sys_Con_NearestColor(const unsigned char _r, const unsigned char _g, const unsigned char _b)
+{
+ float r = ((float)_r)/255.0;
+ float g = ((float)_g)/255.0;
+ float b = ((float)_b)/255.0;
+ float min = min(r, min(g, b));
+ float max = max(r, max(g, b));
+
+ int h; ///< Hue angle [0,360]
+ float s; ///< Saturation [0,1]
+ float v = max; ///< In HSV v == max [0,1]
+
+ if(max == min)
+ s = 0;
+ else
+ s = 1.0 - (min/max);
+
+ // Saturation threshold. We now say 0.2 is the minimum value for a color!
+ if(s < 0.2)
+ {
+ // If the value is less than half, return a black color code.
+ // Otherwise return a white one.
+ if(v < 0.5)
+ return '0';
+ return '7';
+ }
+
+ // Let's get the hue angle to define some colors:
+ if(max == min)
+ h = 0;
+ else if(max == r)
+ h = (int)(60.0 * (g-b)/(max-min))%360;
+ else if(max == g)
+ h = (int)(60.0 * (b-r)/(max-min) + 120);
+ else // if(max == b) redundant check
+ h = (int)(60.0 * (r-g)/(max-min) + 240);
+
+ if(h < 36) // *red* to orange
+ return '1';
+ else if(h < 80) // orange over *yellow* to evilish-bright-green
+ return '3';
+ else if(h < 150) // evilish-bright-green over *green* to ugly bright blue
+ return '2';
+ else if(h < 200) // ugly bright blue over *bright blue* to darkish blue
+ return '5';
+ else if(h < 270) // darkish blue over *dark blue* to cool purple
+ return '4';
+ else if(h < 330) // cool purple over *purple* to ugly swiny red
+ return '6';
+ else // ugly red to red closes the circly
+ return '1';
+}
+
/*
================
Con_Print
int lastcolor = 0;
const char *in;
char *out;
+ char color;
for(in = line, out = printline; *in; ++in)
{
switch(*in)
{
case STRING_COLOR_TAG:
- switch(in[1])
+ if( in[1] == STRING_COLOR_RGB_DEFAULT && isxdigit(in[2]) && isxdigit(in[3]) && isxdigit(in[4]) )
{
+ char r = tolower(in[2]);
+ char g = tolower(in[3]);
+ char b = tolower(in[4]);
+ // it's a hex digit already, so the else part needs no check --blub
+ if(isdigit(r)) r -= '0';
+ else r -= 87;
+ if(isdigit(g)) g -= '0';
+ else g -= 87;
+ if(isdigit(b)) b -= '0';
+ else b -= 87;
+
+ color = Sys_Con_NearestColor(r * 17, g * 17, b * 17);
+ in += 3; // 3 only, the switch down there does the fourth
+ }
+ else
+ color = in[1];
+
+ switch(color)
+ {
+ /*case 'a':
+ if ( isxdigit(in[2]) || in[2] == '+' || in[2] == '-' )
+ {
+ in+=2;
+ break;
+ }*/
case STRING_COLOR_TAG:
++in;
*out++ = STRING_COLOR_TAG;
case STRING_COLOR_TAG:
switch(in[1])
{
+ case STRING_COLOR_RGB_DEFAULT:
+ if ( isxdigit(in[2]) && isxdigit(in[3]) && isxdigit(in[4]) )
+ {
+ in+=4;
+ break;
+ }
+ *out++ = STRING_COLOR_TAG;
+ *out++ = STRING_COLOR_RGB_DEFAULT;
+ ++in;
+ break;
+ /*case 'a':
+ if ( isxdigit(in[2]) || in[2] == '+' || in[2] == '-' )
+ {
+ in+=2;
+ break;
+ }*/
case STRING_COLOR_TAG:
++in;
*out++ = STRING_COLOR_TAG;
if(w == NULL)
{
ti->colorindex = -1;
- return ti->fontsize * ti->font->width_of[0];
+ return ti->fontsize * ti->font->maxwidth;
}
if(maxWidth >= 0)
return DrawQ_TextWidth_Font_UntilWidth(w, length, false, ti->font, maxWidth / ti->fontsize) * ti->fontsize;
if(numChatlines)
{
v = chatstart + numChatlines * con_chatsize.value;
- Con_DrawNotifyRect(CON_MASK_CHAT, 0, con_chattime.value, 0, chatstart, vid_conwidth.value * con_chatwidth.value, v - chatstart, con_chatsize.value, 0.0, 1.0, "^3\014\014\014 "); // 015 is ·> character in conchars.tga
+ Con_DrawNotifyRect(CON_MASK_CHAT, 0, con_chattime.value, 0, chatstart, vid_conwidth.value * con_chatwidth.value, v - chatstart, con_chatsize.value, 0.0, 1.0, "^3\014\014\014 "); // 015 is ·> character in conchars.tga
}
if (key_dest == key_message)
int colorindex = -1;
// LordHavoc: speedup, and other improvements
- if (chat_team)
- sprintf(temptext, "say_team:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
+ if (chat_mode < 0)
+ dpsnprintf(temptext, sizeof(temptext), "]%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
+ else if(chat_mode)
+ dpsnprintf(temptext, sizeof(temptext), "say_team:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
else
- sprintf(temptext, "say:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
+ dpsnprintf(temptext, sizeof(temptext), "say:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
// FIXME word wrap
inputsize = (numChatlines ? con_chatsize : con_notifysize).value;
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_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
qboolean GetMapList (const char *s, char *completedname, int completednamebufferlength)
{
fssearch_t *t;
- char message[64];
+ char message[1024];
int i, k, max, p, o, min;
unsigned char *len;
qfile_t *f;
unsigned char buf[1024];
- sprintf(message, "maps/%s*.bsp", s);
+ dpsnprintf(message, sizeof(message), "maps/%s*.bsp", s);
t = FS_Search(message, 1, true);
if(!t)
return false;
char entfilename[MAX_QPATH];
strlcpy(message, "^1**ERROR**^7", sizeof(message));
p = 0;
- f = FS_Open(t->filenames[i], "rb", true, false);
+ f = FS_OpenVirtualFile(t->filenames[i], true);
if(f)
{
memset(buf, 0, 1024);
if (com_token[0] == '}')
break;
// skip leading whitespace
- for (k = 0;com_token[k] && com_token[k] <= ' ';k++);
- for (l = 0;l < (int)sizeof(keyname) - 1 && com_token[k+l] && com_token[k+l] > ' ';l++)
+ for (k = 0;com_token[k] && ISWHITESPACE(com_token[k]);k++);
+ for (l = 0;l < (int)sizeof(keyname) - 1 && com_token[k+l] && !ISWHITESPACE(com_token[k+l]);l++)
keyname[l] = com_token[k+l];
keyname[l] = 0;
if (!COM_ParseToken_Simple(&data, false, false))
Con_Print("\n\n");
}
-/* Nicks_CompleteCountPossible
-
- Count the number of possible nicks to complete
- */
-//qboolean COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out, qboolean escape_carets);
+/*
+ SanitizeString strips color tags from the string in
+ and writes the result on string out
+*/
void SanitizeString(char *in, char *out)
{
while(*in)
out[0] = STRING_COLOR_TAG;
out[1] = 0;
return;
- } else if(*in >= '0' && *in <= '9')
+ }
+ else if (*in >= '0' && *in <= '9') // ^[0-9] found
{
++in;
- if(!*in) // end
+ if(!*in)
{
*out = 0;
return;
- } else if (*in == STRING_COLOR_TAG)
+ } else if (*in == STRING_COLOR_TAG) // ^[0-9]^ found, don't print ^[0-9]
continue;
- } else if (*in != STRING_COLOR_TAG) {
- --in;
}
+ else if (*in == STRING_COLOR_RGB_DEFAULT) // ^x found
+ {
+ if ( isxdigit(in[1]) && isxdigit(in[2]) && isxdigit(in[3]) )
+ {
+ in+=4;
+ if (!*in)
+ {
+ *out = 0;
+ return;
+ } else if (*in == STRING_COLOR_TAG) // ^xrgb^ found, don't print ^xrgb
+ continue;
+ }
+ else in--;
+ }
+ /*else if (*in == 'a') // ^a found
+ {
+ if ( isxdigit(in[1]) || isxdigit(in[1]) == '+' || isxdigit(in[1]) == '-')
+ {
+ in+=2;
+ if (!*in)
+ {
+ *out = 0;
+ return;
+ } else if (*in == STRING_COLOR_TAG) // ^ax^ found, don't print ^ax
+ continue;
+ }
+ else in = in--;
+ }*/
+ else if (*in != STRING_COLOR_TAG)
+ --in;
}
*out = qfont_table[*(unsigned char*)in];
++in;
}
*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
return 0;
}
+
+/* Nicks_CompleteCountPossible
+
+ Count the number of possible nicks to complete
+ */
int Nicks_CompleteCountPossible(char *line, int pos, char *s, qboolean isCon)
{
char name[128];
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);
-
+ //Con_Printf(" ^2Sanitized: ^7%s -> %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;
}
+/*
+ Nicks_AddLastColor
+ Restores the previous used color, after the autocompleted name.
+*/
int Nicks_AddLastColor(char *buffer, int pos)
{
qboolean quote_added = false;
int match;
- char color = '7';
-
+ char color = STRING_COLOR_DEFAULT + '0';
+ char r = 0, g = 0, b = 0;
+
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?
// find last color
for(match = Nicks_matchpos-1; match >= 0; --match)
{
- if(buffer[match] == STRING_COLOR_TAG && buffer[match+1] >= '0' && buffer[match+1] <= '9')
+ if(buffer[match] == STRING_COLOR_TAG)
{
- color = buffer[match+1];
- break;
+ if( isdigit(buffer[match+1]) )
+ {
+ color = buffer[match+1];
+ break;
+ }
+ else if(buffer[match+1] == STRING_COLOR_RGB_DEFAULT)
+ {
+ if ( isxdigit(buffer[match+2]) && isxdigit(buffer[match+3]) && isxdigit(buffer[match+4]) )
+ {
+ r = buffer[match+2];
+ g = buffer[match+3];
+ b = buffer[match+4];
+ color = -1;
+ break;
+ }
+ }
+ }
+ }
+ if(!quote_added)
+ {
+ if( buffer[pos-2] == STRING_COLOR_TAG && isdigit(buffer[pos-1]) ) // when thes use &4
+ {
+ pos -= 2;
+ }
+ else if( pos >= 5 && buffer[pos-5] == STRING_COLOR_TAG && buffer[pos-4] == STRING_COLOR_RGB_DEFAULT)
+ {
+ if ( isxdigit(buffer[pos-3]) && isxdigit(buffer[pos-2]) && isxdigit(buffer[pos-1]) )
+ {
+ pos -= 5;
+ color = -1;
+ }
}
}
- if(!quote_added && buffer[pos-2] == STRING_COLOR_TAG && buffer[pos-1] >= '0' && buffer[pos-1] <= '9') // when thes use &4
- pos -= 2;
- buffer[pos++] = STRING_COLOR_TAG;
- buffer[pos++] = color;
+ if (color == -1)
+ {
+ buffer[pos++] = STRING_COLOR_TAG;
+ buffer[pos++] = STRING_COLOR_RGB_DEFAULT;
+ buffer[pos++] = r;
+ buffer[pos++] = g;
+ buffer[pos++] = b;
+ }
+ /*else if (color == -2)
+ {
+ buffer[pos++] = STRING_COLOR_TAG;
+ buffer[pos++] = 'a';
+ buffer[pos++] = a;
+ }*/
+ else
+ {
+ buffer[pos++] = STRING_COLOR_TAG;
+ buffer[pos++] = color;
+ }
}
return pos;
}
{
size_t len;
char *msg;
-
+
msg = Nicks_list[0];
len = min(size - Nicks_matchpos - 3, strlen(msg));
memcpy(&buffer[Nicks_matchpos], msg, len);
- if( len < (size - 4) ) // space for color and space and \0
+ if( len < (size - 7) ) // space for color (^[0-9] or ^xrgb) and space and \0
len = Nicks_AddLastColor(buffer, Nicks_matchpos+len);
buffer[len++] = ' ';
buffer[len] = 0;
char command[512];
int c, v, a, i, cmd_len, pos, k;
int n; // nicks --blub
- const char *space;
-
+ const char *space, *patterns;
+
//find what we want to complete
pos = key_linepos;
while(--pos)
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])));
- if(!strcmp(command, "map") || !strcmp(command, "changelevel"))
+
+ 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")))
{
//maps search
char t[MAX_QPATH];
}
else
{
- const char *patterns = Cvar_VariableString(va("con_completion_%s", command)); // TODO maybe use a better place for this?
- char t[MAX_QPATH];
- stringlist_t resultbuf;
-
- // 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);
- while(COM_ParseToken_Simple(&patterns, false, false))
+ if(patterns)
{
- fssearch_t *search;
- if(strchr(com_token, '/'))
+ char t[MAX_QPATH];
+ 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))
{
- search = FS_Search(com_token, true, true);
+ 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);
+ }
}
- else
+
+ // 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, com_token, sizeof(t));
+ strlcat(t, "*", 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)))
- stringlistappend(&resultbuf, search->filenames[i]);
- FS_FreeSearch(search);
- }
- }
-
- if(resultbuf.numstrings > 0)
- {
- const char *p, *q;
- if(resultbuf.numstrings == 1)
- {
- dpsnprintf(t, sizeof(t), "%s ", resultbuf.strings[0]);
+ 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);
+ }
}
- else
+
+ if(resultbuf.numstrings > 0 || dirbuf.numstrings > 0)
{
- stringlistsort(&resultbuf);
- Con_Printf("\n%i possible filenames\n", resultbuf.numstrings);
- for(i = 0; i < resultbuf.numstrings; ++i)
+ const char *p, *q;
+ unsigned int matchchars;
+ if(resultbuf.numstrings == 0 && dirbuf.numstrings == 1)
{
- Con_Printf("%s\n", resultbuf.strings[i]);
+ 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)));
}
- p = resultbuf.strings[0];
- q = resultbuf.strings[resultbuf.numstrings - 1];
- for(; *p && *p == *q; ++p, ++q);
- // 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.strings[0], min((unsigned int)(p - resultbuf.strings[0] + 1), sizeof(t)));
- }
- // first move the cursor
- key_linepos += (int)strlen(t) - (int)strlen(s);
+ // 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 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]);
+ // and fix the cursor
+ if(key_linepos > (int) strlen(key_lines[edit_line]))
+ key_linepos = (int) strlen(key_lines[edit_line]);
+ }
+ stringlistfreecontents(&resultbuf);
+ stringlistfreecontents(&dirbuf);
+
+ return; // bail out, when we complete for a command that wants a file name
}
- stringlistfreecontents(&resultbuf);
}
}
}
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;