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:
myT 2018-02-07 06:51:37 +01:00
parent 005dd46e08
commit 7bfc5d9487
4 changed files with 68 additions and 45 deletions

View file

@ -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; cmd_function_t* cmd;
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) { for ( cmd = cmd_functions; cmd; cmd = cmd->next ) {
if ( !Q_stricmp( cmd_name, cmd->name ) ) { if ( !Q_stricmp( cmd_name, cmd->name ) ) {
Help_AllocSplitText( &cmd->desc, &cmd->help, cmd_help ); return cmd;
return;
} }
} }
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 ) qbool Cmd_GetHelp( const char** desc, const char** help, const char* cmd_name )
{ {
cmd_function_t* cmd; cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) { if ( !cmd ) {
if ( !Q_stricmp( cmd_name, cmd->name ) ) { *desc = NULL;
*desc = cmd->desc; *help = NULL;
*help = cmd->help; return qfalse;
return qtrue;
}
} }
*desc = NULL; *desc = cmd->desc;
*help = NULL; *help = cmd->help;
return qfalse; return qtrue;
} }
void Cmd_SetAutoCompletion( const char* cmd_name, xcommandCompletion_t completion ) void Cmd_SetAutoCompletion( const char* cmd_name, xcommandCompletion_t completion )
{ {
cmd_function_t* cmd; cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) { if ( cmd )
if ( !Q_stricmp( cmd_name, cmd->name ) ) { cmd->completion = completion;
cmd->completion = completion;
return;
}
}
} }
void Cmd_AutoCompleteArgument( const char* cmd_name, int startArg, int compArg ) void Cmd_AutoCompleteArgument( const char* cmd_name, int startArg, int compArg )
{ {
const cmd_function_t* cmd; cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) { if ( cmd && cmd->completion )
if ( !Q_stricmp( cmd_name, cmd->name ) ) { cmd->completion( startArg, compArg );
if ( cmd->completion )
cmd->completion( startArg, compArg );
return;
}
}
} }
@ -783,15 +781,13 @@ void Cmd_UnregisterTable( const cmdTableItem_t* cmds, int count )
void Cmd_SetModule( const char* cmd_name, module_t module ) void Cmd_SetModule( const char* cmd_name, module_t module )
{ {
cmd_function_t* cmd; cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) { if ( !cmd )
if ( !Q_stricmp( cmd_name, cmd->name ) ) { return;
cmd->moduleMask |= 1 << (int)module;
if ( cmd->firstModule == MODULE_NONE ) cmd->moduleMask |= 1 << (int)module;
cmd->firstModule = module; if ( cmd->firstModule == MODULE_NONE )
return; 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 ) void Cmd_GetModuleInfo( module_t* firstModule, int* moduleMask, const char* cmd_name )
{ {
cmd_function_t* cmd; cmd_function_t* cmd = Cmd_FindCommand( cmd_name );
for ( cmd = cmd_functions; cmd; cmd = cmd->next ) { if ( !cmd )
if ( !Q_stricmp( cmd_name, cmd->name ) ) { return;
*firstModule = cmd->firstModule;
*moduleMask = cmd->moduleMask; *firstModule = cmd->firstModule;
return; *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;
}

View file

@ -3423,19 +3423,25 @@ printHelpResult_t Com_PrintHelp( const char* name, printf_t print, qbool printNo
qbool isCvar = qfalse; qbool isCvar = qfalse;
const char *desc; const char *desc;
const char *help; const char *help;
const char* registeredName;
module_t firstModule; module_t firstModule;
int moduleMask; int moduleMask;
if ( Cvar_GetHelp( &desc, &help, name ) ) { if ( Cvar_GetHelp( &desc, &help, name ) ) {
isCvar = qtrue; isCvar = qtrue;
Cvar_GetModuleInfo( &firstModule, &moduleMask, name ); Cvar_GetModuleInfo( &firstModule, &moduleMask, name );
registeredName = Cvar_GetRegisteredName( name );
} else if ( Cmd_GetHelp( &desc, &help, name ) ) { } else if ( Cmd_GetHelp( &desc, &help, name ) ) {
Cmd_GetModuleInfo( &firstModule, &moduleMask, name ); Cmd_GetModuleInfo( &firstModule, &moduleMask, name );
registeredName = Cmd_GetRegisteredName( name );
} else { } else {
if ( printNotFound ) if ( printNotFound )
print( "found no cvar/command with the name '%s'\n", name ); print( "found no cvar/command with the name '%s'\n", name );
return PHR_NOTFOUND; return PHR_NOTFOUND;
} }
if ( registeredName )
name = registeredName;
if ( isCvar ) if ( isCvar )
Cvar_PrintFirstHelpLine( name, print ); Cvar_PrintFirstHelpLine( name, print );
else else

View file

@ -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 ) static const char* Cvar_FormatRangeFloat( float vf )
{ {
const int vi = (int)vf; const int vi = (int)vf;

View file

@ -400,6 +400,8 @@ void Cmd_UnregisterModule( module_t module );
void Cmd_GetModuleInfo( module_t* firstModule, int* moduleMask, const char* cmd_name ); 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 // auto-completion of command arguments
void Cmd_SetAutoCompletion( const char* cmd_name, xcommandCompletion_t complete ); void Cmd_SetAutoCompletion( const char* cmd_name, xcommandCompletion_t complete );
void Cmd_AutoCompleteArgument( const char* cmd_name, int startArg, int compArg ); 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_SetModule( const char *var_name, module_t module );
void Cvar_GetModuleInfo( module_t *firstModule, int *moduleMask, const char *var_name ); 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_PrintTypeAndRange( const char *var_name, printf_t print );
void Cvar_PrintFirstHelpLine( 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 ); void Cvar_PrintFlags( const char *var_name, printf_t print );