Changeset 6197702 for root_commands.c


Ignore:
Timestamp:
2010-10-09T18:41:19Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
d150a9d
Parents:
23b29c6 (diff), 27b407f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging OTR branch. It's more or less a plugin if you enable it, and
otherwise a no-op. DO NOT INSTALL THIS ON PUBLIC SERVERS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • root_commands.c

    r23b29c6 r6197702  
    5555       
    5656        len = strlen( cmd[0] );
    57         for( i = 0; commands[i].command; i++ )
    58                 if( g_strncasecmp( commands[i].command, cmd[0], len ) == 0 )
    59                 {
    60                         if( commands[i+1].command &&
    61                             g_strncasecmp( commands[i+1].command, cmd[0], len ) == 0 )
     57        for( i = 0; root_commands[i].command; i++ )
     58                if( g_strncasecmp( root_commands[i].command, cmd[0], len ) == 0 )
     59                {
     60                        if( root_commands[i+1].command &&
     61                            g_strncasecmp( root_commands[i+1].command, cmd[0], len ) == 0 )
    6262                                /* Only match on the first letters if the match is unique. */
    6363                                break;
    6464                       
    65                         MIN_ARGS( commands[i].required_parameters );
     65                        MIN_ARGS( root_commands[i].required_parameters );
    6666                       
    67                         commands[i].execute( irc, cmd );
     67                        root_commands[i].execute( irc, cmd );
    6868                        return;
    6969                }
     
    13131313
    13141314/* IMPORTANT: Keep this list sorted! The short command logic needs that. */
    1315 const command_t commands[] = {
     1315command_t root_commands[] = {
    13161316        { "account",        1, cmd_account,        0 },
    13171317        { "add",            2, cmd_add,            0 },
     
    13371337        { "transfer",       0, cmd_transfer,       0 },
    13381338        { "yes",            0, cmd_yesno,          0 },
    1339         { NULL }
     1339        /* Not expecting too many plugins adding root commands so just make a
     1340           dumb array with some empty entried at the end. */
     1341        { NULL },
     1342        { NULL },
     1343        { NULL },
     1344        { NULL },
     1345        { NULL },
     1346        { NULL },
     1347        { NULL },
     1348        { NULL },
     1349        { NULL },
    13401350};
     1351static const int num_root_commands = sizeof( root_commands ) / sizeof( command_t );
     1352
     1353gboolean root_command_add( const char *command, int params, void (*func)(irc_t *, char **args), int flags )
     1354{
     1355        int i;
     1356       
     1357        if( root_commands[num_root_commands-2].command )
     1358                /* Planning fail! List is full. */
     1359                return FALSE;
     1360       
     1361        for( i = 0; root_commands[i].command; i++ )
     1362        {
     1363                if( g_strcasecmp( root_commands[i].command, command ) == 0 )
     1364                        return FALSE;
     1365                else if( g_strcasecmp( root_commands[i].command, command ) > 0 )
     1366                        break;
     1367        }
     1368        memmove( root_commands + i + 1, root_commands + i,
     1369                 sizeof( command_t ) * ( num_root_commands - i - 1 ) );
     1370       
     1371        root_commands[i].command = g_strdup( command );
     1372        root_commands[i].required_parameters = params;
     1373        root_commands[i].execute = func;
     1374        root_commands[i].flags = flags;
     1375       
     1376        return TRUE;
     1377}
Note: See TracChangeset for help on using the changeset viewer.