mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2024-11-10 06:31:48 +00:00
using the registered cvar/cmd names in the help panel instead of argument 0
cleaned up cmd.cpp with Cmd_FindCommand
This commit is contained in:
parent
005dd46e08
commit
7bfc5d9487
4 changed files with 68 additions and 45 deletions
|
@ -589,57 +589,55 @@ void Cmd_RemoveCommand( const char* cmd_name )
|
|||
}
|
||||
|
||||
|
||||
void Cmd_SetHelp( const char* cmd_name, const char* cmd_help )
|
||||
static cmd_function_t* Cmd_FindCommand( const char* cmd_name )
|
||||
{
|
||||
cmd_function_t* cmd;
|
||||
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) {
|
||||
if ( !Q_stricmp( cmd_name, cmd->name ) ) {
|
||||
Help_AllocSplitText( &cmd->desc, &cmd->help, cmd_help );
|
||||
return;
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void Cmd_SetHelp( const char* cmd_name, const char* cmd_help )
|
||||
{
|
||||
cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
|
||||
if ( cmd )
|
||||
Help_AllocSplitText( &cmd->desc, &cmd->help, cmd_help );
|
||||
}
|
||||
|
||||
|
||||
qbool Cmd_GetHelp( const char** desc, const char** help, const char* cmd_name )
|
||||
{
|
||||
cmd_function_t* cmd;
|
||||
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) {
|
||||
if ( !Q_stricmp( cmd_name, cmd->name ) ) {
|
||||
*desc = cmd->desc;
|
||||
*help = cmd->help;
|
||||
return qtrue;
|
||||
}
|
||||
cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
|
||||
if ( !cmd ) {
|
||||
*desc = NULL;
|
||||
*help = NULL;
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
*desc = NULL;
|
||||
*help = NULL;
|
||||
return qfalse;
|
||||
*desc = cmd->desc;
|
||||
*help = cmd->help;
|
||||
return qtrue;
|
||||
}
|
||||
|
||||
|
||||
void Cmd_SetAutoCompletion( const char* cmd_name, xcommandCompletion_t completion )
|
||||
{
|
||||
cmd_function_t* cmd;
|
||||
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) {
|
||||
if ( !Q_stricmp( cmd_name, cmd->name ) ) {
|
||||
cmd->completion = completion;
|
||||
return;
|
||||
}
|
||||
}
|
||||
cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
|
||||
if ( cmd )
|
||||
cmd->completion = completion;
|
||||
}
|
||||
|
||||
|
||||
void Cmd_AutoCompleteArgument( const char* cmd_name, int startArg, int compArg )
|
||||
{
|
||||
const cmd_function_t* cmd;
|
||||
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) {
|
||||
if ( !Q_stricmp( cmd_name, cmd->name ) ) {
|
||||
if ( cmd->completion )
|
||||
cmd->completion( startArg, compArg );
|
||||
return;
|
||||
}
|
||||
}
|
||||
cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
|
||||
if ( cmd && cmd->completion )
|
||||
cmd->completion( startArg, compArg );
|
||||
}
|
||||
|
||||
|
||||
|
@ -783,15 +781,13 @@ void Cmd_UnregisterTable( const cmdTableItem_t* cmds, int count )
|
|||
|
||||
void Cmd_SetModule( const char* cmd_name, module_t module )
|
||||
{
|
||||
cmd_function_t* cmd;
|
||||
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) {
|
||||
if ( !Q_stricmp( cmd_name, cmd->name ) ) {
|
||||
cmd->moduleMask |= 1 << (int)module;
|
||||
if ( cmd->firstModule == MODULE_NONE )
|
||||
cmd->firstModule = module;
|
||||
return;
|
||||
}
|
||||
}
|
||||
cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
|
||||
if ( !cmd )
|
||||
return;
|
||||
|
||||
cmd->moduleMask |= 1 << (int)module;
|
||||
if ( cmd->firstModule == MODULE_NONE )
|
||||
cmd->firstModule = module;
|
||||
}
|
||||
|
||||
|
||||
|
@ -816,13 +812,20 @@ void Cmd_UnregisterModule( module_t module )
|
|||
|
||||
void Cmd_GetModuleInfo( module_t* firstModule, int* moduleMask, const char* cmd_name )
|
||||
{
|
||||
cmd_function_t* cmd;
|
||||
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) {
|
||||
if ( !Q_stricmp( cmd_name, cmd->name ) ) {
|
||||
*firstModule = cmd->firstModule;
|
||||
*moduleMask = cmd->moduleMask;
|
||||
return;
|
||||
}
|
||||
}
|
||||
cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
|
||||
if ( !cmd )
|
||||
return;
|
||||
|
||||
*firstModule = cmd->firstModule;
|
||||
*moduleMask = cmd->moduleMask;
|
||||
}
|
||||
|
||||
|
||||
const char* Cmd_GetRegisteredName( const char* cmd_name )
|
||||
{
|
||||
cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
|
||||
if ( !cmd )
|
||||
return NULL;
|
||||
|
||||
return cmd->name;
|
||||
}
|
||||
|
|
|
@ -3423,19 +3423,25 @@ printHelpResult_t Com_PrintHelp( const char* name, printf_t print, qbool printNo
|
|||
qbool isCvar = qfalse;
|
||||
const char *desc;
|
||||
const char *help;
|
||||
const char* registeredName;
|
||||
module_t firstModule;
|
||||
int moduleMask;
|
||||
if ( Cvar_GetHelp( &desc, &help, name ) ) {
|
||||
isCvar = qtrue;
|
||||
Cvar_GetModuleInfo( &firstModule, &moduleMask, name );
|
||||
registeredName = Cvar_GetRegisteredName( name );
|
||||
} else if ( Cmd_GetHelp( &desc, &help, name ) ) {
|
||||
Cmd_GetModuleInfo( &firstModule, &moduleMask, name );
|
||||
registeredName = Cmd_GetRegisteredName( name );
|
||||
} else {
|
||||
if ( printNotFound )
|
||||
print( "found no cvar/command with the name '%s'\n", name );
|
||||
return PHR_NOTFOUND;
|
||||
}
|
||||
|
||||
if ( registeredName )
|
||||
name = registeredName;
|
||||
|
||||
if ( isCvar )
|
||||
Cvar_PrintFirstHelpLine( name, print );
|
||||
else
|
||||
|
|
|
@ -633,6 +633,16 @@ void Cvar_GetModuleInfo( module_t *firstModule, int *moduleMask, const char *var
|
|||
}
|
||||
|
||||
|
||||
const char* Cvar_GetRegisteredName( const char *var_name )
|
||||
{
|
||||
cvar_t* var = Cvar_FindVar( var_name );
|
||||
if ( !var )
|
||||
return NULL;
|
||||
|
||||
return var->name;
|
||||
}
|
||||
|
||||
|
||||
static const char* Cvar_FormatRangeFloat( float vf )
|
||||
{
|
||||
const int vi = (int)vf;
|
||||
|
|
|
@ -400,6 +400,8 @@ void Cmd_UnregisterModule( module_t module );
|
|||
|
||||
void Cmd_GetModuleInfo( module_t* firstModule, int* moduleMask, const char* cmd_name );
|
||||
|
||||
const char* Cmd_GetRegisteredName( const char* cmd_name );
|
||||
|
||||
// auto-completion of command arguments
|
||||
void Cmd_SetAutoCompletion( const char* cmd_name, xcommandCompletion_t complete );
|
||||
void Cmd_AutoCompleteArgument( const char* cmd_name, int startArg, int compArg );
|
||||
|
@ -527,6 +529,8 @@ void Cvar_RegisterTable( const cvarTableItem_t* cvars, int count, module_t modul
|
|||
void Cvar_SetModule( const char *var_name, module_t module );
|
||||
void Cvar_GetModuleInfo( module_t *firstModule, int *moduleMask, const char *var_name );
|
||||
|
||||
const char* Cvar_GetRegisteredName( const char *var_name );
|
||||
|
||||
void Cvar_PrintTypeAndRange( const char *var_name, printf_t print );
|
||||
void Cvar_PrintFirstHelpLine( const char *var_name, printf_t print );
|
||||
void Cvar_PrintFlags( const char *var_name, printf_t print );
|
||||
|
|
Loading…
Reference in a new issue