Changeset 7e563ed
- Timestamp:
- 2006-01-04T12:09:07Z (19 years ago)
- Branches:
- master
- Children:
- 08995b0
- Parents:
- 0196c47
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
bitlbee.c
r0196c47 r7e563ed 287 287 g_main_quit( global.loop ); 288 288 } 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 32 32 #include <string.h> 33 33 34 co mmand_t commands[] = {34 const command_t commands[] = { 35 35 { "help", 0, cmd_help }, 36 36 { "identify", 1, cmd_identify }, … … 55 55 }; 56 56 57 int 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 92 int 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 57 116 int cmd_help( irc_t *irc, char **cmd ) 58 117 { -
commands.h
r0196c47 r7e563ed 29 29 #include "bitlbee.h" 30 30 31 /* Hmm... Linked list? Plleeeeaaase?? ;-) */32 33 31 typedef struct command_t 34 32 { … … 58 56 int cmd_dump( irc_t *irc, char **cmd ); 59 57 60 61 62 extern command_t commands[]; 58 extern const command_t commands[]; 63 59 64 60 #endif
Note: See TracChangeset
for help on using the changeset viewer.