diff options
Diffstat (limited to 'root_commands.c')
-rw-r--r-- | root_commands.c | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/root_commands.c b/root_commands.c index 94d22933..ba018937 100644 --- a/root_commands.c +++ b/root_commands.c @@ -54,17 +54,17 @@ void root_command( irc_t *irc, char *cmd[] ) return; len = strlen( cmd[0] ); - for( i = 0; commands[i].command; i++ ) - if( g_strncasecmp( commands[i].command, cmd[0], len ) == 0 ) + for( i = 0; root_commands[i].command; i++ ) + if( g_strncasecmp( root_commands[i].command, cmd[0], len ) == 0 ) { - if( commands[i+1].command && - g_strncasecmp( commands[i+1].command, cmd[0], len ) == 0 ) + if( root_commands[i+1].command && + g_strncasecmp( root_commands[i+1].command, cmd[0], len ) == 0 ) /* Only match on the first letters if the match is unique. */ break; - MIN_ARGS( commands[i].required_parameters ); + MIN_ARGS( root_commands[i].required_parameters ); - commands[i].execute( irc, cmd ); + root_commands[i].execute( irc, cmd ); return; } @@ -1328,7 +1328,7 @@ static void bitlbee_whatsnew( irc_t *irc ) } /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ -const command_t commands[] = { +command_t root_commands[] = { { "account", 1, cmd_account, 0 }, { "add", 2, cmd_add, 0 }, { "allow", 1, cmd_allow, 0 }, @@ -1352,5 +1352,42 @@ const command_t commands[] = { { "set", 0, cmd_set, 0 }, { "transfer", 0, cmd_transfer, 0 }, { "yes", 0, cmd_yesno, 0 }, - { NULL } + /* Not expecting too many plugins adding root commands so just make a + dumb array with some empty entried at the end. */ + { NULL }, + { NULL }, + { NULL }, + { NULL }, + { NULL }, + { NULL }, + { NULL }, + { NULL }, + { NULL }, }; +static const int num_root_commands = sizeof( root_commands ) / sizeof( command_t ); + +gboolean root_command_add( const char *command, int params, void (*func)(irc_t *, char **args), int flags ) +{ + int i; + + if( root_commands[num_root_commands-2].command ) + /* Planning fail! List is full. */ + return FALSE; + + for( i = 0; root_commands[i].command; i++ ) + { + if( g_strcasecmp( root_commands[i].command, command ) == 0 ) + return FALSE; + else if( g_strcasecmp( root_commands[i].command, command ) > 0 ) + break; + } + memmove( root_commands + i + 1, root_commands + i, + sizeof( command_t ) * ( num_root_commands - i - 1 ) ); + + root_commands[i].command = g_strdup( command ); + root_commands[i].required_parameters = params; + root_commands[i].execute = func; + root_commands[i].flags = flags; + + return TRUE; +} |