mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2025-02-07 08:21:48 +00:00
* 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.)
This commit is contained in:
parent
36a43f2aa1
commit
f1faa1d12a
1 changed files with 42 additions and 61 deletions
|
@ -3131,6 +3131,37 @@ static char *Field_FindFirstSeparator( char *s )
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
===============
|
||||||
|
Field_Complete
|
||||||
|
===============
|
||||||
|
*/
|
||||||
|
static qboolean Field_Complete( void )
|
||||||
|
{
|
||||||
|
int completionOffset;
|
||||||
|
|
||||||
|
if( matchCount == 0 )
|
||||||
|
return qfalse;
|
||||||
|
|
||||||
|
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 qtrue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Com_Printf( "]%s\n", completionField->buffer );
|
||||||
|
|
||||||
|
return qfalse;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef DEDICATED
|
#ifndef DEDICATED
|
||||||
/*
|
/*
|
||||||
===============
|
===============
|
||||||
|
@ -3144,24 +3175,8 @@ static void Field_CompleteKeyname( void )
|
||||||
|
|
||||||
Key_KeynameCompletion( FindMatches );
|
Key_KeynameCompletion( FindMatches );
|
||||||
|
|
||||||
if( matchCount == 0 )
|
if( !Field_Complete( ) )
|
||||||
return;
|
Key_KeynameCompletion( PrintMatches );
|
||||||
|
|
||||||
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 );
|
|
||||||
|
|
||||||
Key_KeynameCompletion( PrintMatches );
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -3178,24 +3193,8 @@ static void Field_CompleteFilename( const char *dir,
|
||||||
|
|
||||||
FS_FilenameCompletion( dir, ext, stripExt, FindMatches );
|
FS_FilenameCompletion( dir, ext, stripExt, FindMatches );
|
||||||
|
|
||||||
if( matchCount == 0 )
|
if( !Field_Complete( ) )
|
||||||
return;
|
FS_FilenameCompletion( dir, ext, stripExt, PrintMatches );
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3346,8 +3345,6 @@ static void Field_CompleteCommand( char *cmd,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int completionOffset;
|
|
||||||
|
|
||||||
if( completionString[0] == '\\' || completionString[0] == '/' )
|
if( completionString[0] == '\\' || completionString[0] == '/' )
|
||||||
completionString++;
|
completionString++;
|
||||||
|
|
||||||
|
@ -3363,31 +3360,15 @@ static void Field_CompleteCommand( char *cmd,
|
||||||
if( doCvars )
|
if( doCvars )
|
||||||
Cvar_CommandCompletion( FindMatches );
|
Cvar_CommandCompletion( FindMatches );
|
||||||
|
|
||||||
if( matchCount == 0 )
|
if( !Field_Complete( ) )
|
||||||
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 )
|
|
||||||
{
|
{
|
||||||
Q_strcat( completionField->buffer, sizeof( completionField->buffer ), " " );
|
// run through again, printing matches
|
||||||
completionField->cursor++;
|
if( doCommands )
|
||||||
return;
|
Cmd_CommandCompletion( PrintMatches );
|
||||||
|
|
||||||
|
if( doCvars )
|
||||||
|
Cvar_CommandCompletion( PrintCvarMatches );
|
||||||
}
|
}
|
||||||
|
|
||||||
Com_Printf( "]%s\n", completionField->buffer );
|
|
||||||
|
|
||||||
// run through again, printing matches
|
|
||||||
if( doCommands )
|
|
||||||
Cmd_CommandCompletion( PrintMatches );
|
|
||||||
|
|
||||||
if( doCvars )
|
|
||||||
Cvar_CommandCompletion( PrintCvarMatches );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue