r1460 - trunk/code/qcommon
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Wed Aug 27 16:00:34 EDT 2008
Author: tma
Date: 2008-08-27 16:00:34 -0400 (Wed, 27 Aug 2008)
New Revision: 1460
Modified:
trunk/code/qcommon/common.c
Log:
* Collapse common command completion code into one function and fix the
incorrect buffer size parameter to strncpy (from the
how-the-fuck-did-this-ever-work dept.)
Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c 2008-08-25 21:15:25 UTC (rev 1459)
+++ trunk/code/qcommon/common.c 2008-08-27 20:00:34 UTC (rev 1460)
@@ -3131,38 +3131,53 @@
return NULL;
}
-#ifndef DEDICATED
/*
===============
-Field_CompleteKeyname
+Field_Complete
===============
*/
-static void Field_CompleteKeyname( void )
+static qboolean Field_Complete( void )
{
- matchCount = 0;
- shortestMatch[ 0 ] = 0;
+ int completionOffset;
- Key_KeynameCompletion( FindMatches );
-
if( matchCount == 0 )
- return;
+ return qfalse;
- Q_strncpyz( &completionField->buffer[ strlen( completionField->buffer ) -
- strlen( completionString ) ], shortestMatch,
- sizeof( completionField->buffer ) );
+ completionOffset = strlen( completionField->buffer ) - strlen( completionString );
+
+ Q_strncpyz( &completionField->buffer[ completionOffset ], shortestMatch,
+ sizeof( completionField->buffer ) - completionOffset );
+
completionField->cursor = strlen( completionField->buffer );
if( matchCount == 1 )
{
Q_strcat( completionField->buffer, sizeof( completionField->buffer ), " " );
completionField->cursor++;
- return;
+ return qtrue;
}
Com_Printf( "]%s\n", completionField->buffer );
-
- Key_KeynameCompletion( PrintMatches );
+
+ return qfalse;
}
+
+#ifndef DEDICATED
+/*
+===============
+Field_CompleteKeyname
+===============
+*/
+static void Field_CompleteKeyname( void )
+{
+ matchCount = 0;
+ shortestMatch[ 0 ] = 0;
+
+ Key_KeynameCompletion( FindMatches );
+
+ if( !Field_Complete( ) )
+ Key_KeynameCompletion( PrintMatches );
+}
#endif
/*
@@ -3178,24 +3193,8 @@
FS_FilenameCompletion( dir, ext, stripExt, FindMatches );
- if( matchCount == 0 )
- return;
-
- Q_strncpyz( &completionField->buffer[ strlen( completionField->buffer ) -
- strlen( completionString ) ], shortestMatch,
- sizeof( completionField->buffer ) );
- completionField->cursor = strlen( completionField->buffer );
-
- if( matchCount == 1 )
- {
- Q_strcat( completionField->buffer, sizeof( completionField->buffer ), " " );
- completionField->cursor++;
- return;
- }
-
- Com_Printf( "]%s\n", completionField->buffer );
-
- FS_FilenameCompletion( dir, ext, stripExt, PrintMatches );
+ if( !Field_Complete( ) )
+ FS_FilenameCompletion( dir, ext, stripExt, PrintMatches );
}
/*
@@ -3346,8 +3345,6 @@
}
else
{
- int completionOffset;
-
if( completionString[0] == '\\' || completionString[0] == '/' )
completionString++;
@@ -3363,31 +3360,15 @@
if( doCvars )
Cvar_CommandCompletion( FindMatches );
- if( matchCount == 0 )
- return; // no matches
-
- completionOffset = strlen( completionField->buffer ) - strlen( completionString );
-
- Q_strncpyz( &completionField->buffer[ completionOffset ], shortestMatch,
- sizeof( completionField->buffer ) - completionOffset );
-
- completionField->cursor = strlen( completionField->buffer );
-
- if( matchCount == 1 )
+ if( !Field_Complete( ) )
{
- Q_strcat( completionField->buffer, sizeof( completionField->buffer ), " " );
- completionField->cursor++;
- return;
- }
+ // run through again, printing matches
+ if( doCommands )
+ Cmd_CommandCompletion( PrintMatches );
- Com_Printf( "]%s\n", completionField->buffer );
-
- // run through again, printing matches
- if( doCommands )
- Cmd_CommandCompletion( PrintMatches );
-
- if( doCvars )
- Cvar_CommandCompletion( PrintCvarMatches );
+ if( doCvars )
+ Cvar_CommandCompletion( PrintCvarMatches );
+ }
}
}
More information about the quake3-commits
mailing list