summaryrefslogtreecommitdiff
path: root/source/cmd.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2010-08-01 18:55:40 +0000
committerAndrey Nazarov <skuller@skuller.net>2010-08-01 18:55:40 +0000
commit9a0fcb9662bbcf809318a6fcf84b4798efeeabcc (patch)
treefae02a5d86e2ce5d3e4ddbb0b060d0296aab8096 /source/cmd.c
parent4152a106576948ed9e5bcc8ccff6bc672b29e67e (diff)
Use custom macros for traversing cmd/alias lists.
Diffstat (limited to 'source/cmd.c')
-rw-r--r--source/cmd.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/source/cmd.c b/source/cmd.c
index 51f56ed..0678f76 100644
--- a/source/cmd.c
+++ b/source/cmd.c
@@ -197,6 +197,13 @@ void Cbuf_Execute( cmdbuf_t *buf ) {
==============================================================================
*/
+#define ALIAS_HASH_SIZE 64
+
+#define FOR_EACH_ALIAS_HASH( alias, hash ) \
+ LIST_FOR_EACH( cmdalias_t, alias, &cmd_aliasHash[hash], hashEntry )
+#define FOR_EACH_ALIAS( alias ) \
+ LIST_FOR_EACH( cmdalias_t, alias, &cmd_alias, listEntry )
+
typedef struct cmdalias_s {
list_t hashEntry;
list_t listEntry;
@@ -204,8 +211,6 @@ typedef struct cmdalias_s {
char name[1];
} cmdalias_t;
-#define ALIAS_HASH_SIZE 64
-
static list_t cmd_alias;
static list_t cmd_aliasHash[ALIAS_HASH_SIZE];
@@ -219,7 +224,7 @@ cmdalias_t *Cmd_AliasFind( const char *name ) {
cmdalias_t *alias;
hash = Com_HashString( name, ALIAS_HASH_SIZE );
- LIST_FOR_EACH( cmdalias_t, alias, &cmd_aliasHash[hash], hashEntry ) {
+ FOR_EACH_ALIAS_HASH( alias, hash ) {
if( !strcmp( name, alias->name ) ) {
return alias;
}
@@ -266,7 +271,7 @@ void Cmd_AliasSet( const char *name, const char *cmd ) {
void Cmd_Alias_g( genctx_t *ctx ) {
cmdalias_t *a;
- LIST_FOR_EACH( cmdalias_t, a, &cmd_alias, listEntry ) {
+ FOR_EACH_ALIAS( a ) {
if( !Prompt_AddMatch( ctx, a->name ) ) {
break;
}
@@ -291,7 +296,7 @@ void Cmd_Alias_f( void ) {
return;
}
Com_Printf( "Registered alias commands:\n" );
- LIST_FOR_EACH( cmdalias_t, a, &cmd_alias, listEntry ) {
+ FOR_EACH_ALIAS( a ) {
Com_Printf( "\"%s\" = \"%s\"\n", a->name, a->value );
}
return;
@@ -381,7 +386,7 @@ static void Cmd_UnAlias_f( void ) {
void Cmd_WriteAliases( qhandle_t f ) {
cmdalias_t *a;
- LIST_FOR_EACH( cmdalias_t, a, &cmd_alias, listEntry ) {
+ FOR_EACH_ALIAS( a ) {
FS_FPrintf( f, "alias \"%s\" \"%s\"\n", a->name, a->value );
}
}
@@ -487,6 +492,11 @@ void Cmd_AddMacro( const char *name, xmacro_t function ) {
#define CMD_HASH_SIZE 128
+#define FOR_EACH_CMD_HASH( cmd, hash ) \
+ LIST_FOR_EACH( cmd_function_t, cmd, &cmd_hash[hash], hashEntry )
+#define FOR_EACH_CMD( cmd ) \
+ LIST_FOR_EACH( cmd_function_t, cmd, &cmd_functions, listEntry )
+
typedef struct cmd_function_s {
list_t hashEntry;
list_t listEntry;
@@ -1143,7 +1153,7 @@ cmd_function_t *Cmd_Find( const char *name ) {
unsigned hash;
hash = Com_HashString( name, CMD_HASH_SIZE );
- LIST_FOR_EACH( cmd_function_t, cmd, &cmd_hash[hash], hashEntry ) {
+ FOR_EACH_CMD_HASH( cmd, hash ) {
if( !strcmp( cmd->name, name ) ) {
return cmd;
}
@@ -1261,7 +1271,7 @@ xcompleter_t Cmd_FindCompleter( const char *name ) {
void Cmd_Command_g( genctx_t *ctx ) {
cmd_function_t *cmd;
- LIST_FOR_EACH( cmd_function_t, cmd, &cmd_functions, listEntry ) {
+ FOR_EACH_CMD( cmd ) {
if( !Prompt_AddMatch( ctx, cmd->name ) ) {
break;
}
@@ -1511,7 +1521,7 @@ static void Cmd_List_f( void ) {
}
i = total = 0;
- LIST_FOR_EACH( cmd_function_t, cmd, &cmd_functions, listEntry ) {
+ FOR_EACH_CMD( cmd ) {
total++;
if( filter && !Com_WildCmp( filter, cmd->name, qfalse ) ) {
continue;