Changeset 7e563ed


Ignore:
Timestamp:
2006-01-04T12:09:07Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
08995b0
Parents:
0196c47
Message:

Moved root_command functions to commands.c

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.c

    r0196c47 r7e563ed  
    287287        g_main_quit( global.loop );
    288288}
    289 
    290 int root_command_string( irc_t *irc, user_t *u, char *command, int flags )
    291 {
    292         char *cmd[IRC_MAX_ARGS];
    293         char *s;
    294         int k;
    295         char q = 0;
    296        
    297         memset( cmd, 0, sizeof( cmd ) );
    298         cmd[0] = command;
    299         k = 1;
    300         for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
    301                 if( *s == ' ' && !q )
    302                 {
    303                         *s = 0;
    304                         while( *++s == ' ' );
    305                         if( *s == '"' || *s == '\'' )
    306                         {
    307                                 q = *s;
    308                                 s ++;
    309                         }
    310                         if( *s )
    311                         {
    312                                 cmd[k++] = s;
    313                                 s --;
    314                         }
    315                 }
    316                 else if( *s == q )
    317                 {
    318                         q = *s = 0;
    319                 }
    320         cmd[k] = NULL;
    321        
    322         return( root_command( irc, cmd ) );
    323 }
    324 
    325 int root_command( irc_t *irc, char *cmd[] )
    326 {       
    327         int i;
    328        
    329         if( !cmd[0] )
    330                 return( 0 );
    331        
    332         for( i = 0; commands[i].command; i++ )
    333                 if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
    334                 {
    335                         if( !cmd[commands[i].required_parameters] )
    336                         {
    337                                 irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters );
    338                                 return( 0 );
    339                         }
    340                         commands[i].execute( irc, cmd );
    341                         return( 1 );
    342                 }
    343        
    344         irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] );
    345        
    346         return( 1 );
    347 }
  • commands.c

    r0196c47 r7e563ed  
    3232#include <string.h>
    3333
    34 command_t commands[] = {
     34const command_t commands[] = {
    3535        { "help",           0, cmd_help },
    3636        { "identify",       1, cmd_identify },
     
    5555};
    5656
     57int root_command_string( irc_t *irc, user_t *u, char *command, int flags )
     58{
     59        char *cmd[IRC_MAX_ARGS];
     60        char *s;
     61        int k;
     62        char q = 0;
     63       
     64        memset( cmd, 0, sizeof( cmd ) );
     65        cmd[0] = command;
     66        k = 1;
     67        for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
     68                if( *s == ' ' && !q )
     69                {
     70                        *s = 0;
     71                        while( *++s == ' ' );
     72                        if( *s == '"' || *s == '\'' )
     73                        {
     74                                q = *s;
     75                                s ++;
     76                        }
     77                        if( *s )
     78                        {
     79                                cmd[k++] = s;
     80                                s --;
     81                        }
     82                }
     83                else if( *s == q )
     84                {
     85                        q = *s = 0;
     86                }
     87        cmd[k] = NULL;
     88       
     89        return( root_command( irc, cmd ) );
     90}
     91
     92int root_command( irc_t *irc, char *cmd[] )
     93{       
     94        int i;
     95       
     96        if( !cmd[0] )
     97                return( 0 );
     98       
     99        for( i = 0; commands[i].command; i++ )
     100                if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
     101                {
     102                        if( !cmd[commands[i].required_parameters] )
     103                        {
     104                                irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters );
     105                                return( 0 );
     106                        }
     107                        commands[i].execute( irc, cmd );
     108                        return( 1 );
     109                }
     110       
     111        irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] );
     112       
     113        return( 1 );
     114}
     115
    57116int cmd_help( irc_t *irc, char **cmd )
    58117{
  • commands.h

    r0196c47 r7e563ed  
    2929#include "bitlbee.h"
    3030
    31 /* Hmm... Linked list? Plleeeeaaase?? ;-) */
    32 
    3331typedef struct command_t
    3432{
     
    5856int cmd_dump( irc_t *irc, char **cmd );
    5957
    60 
    61 
    62 extern command_t commands[];
     58extern const command_t commands[];
    6359
    6460#endif
Note: See TracChangeset for help on using the changeset viewer.