diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-01-04 13:09:07 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-01-04 13:09:07 +0100 | 
| commit | 7e563ed9a130cce070753f011158ef0714c58d46 (patch) | |
| tree | c0a30a50d6cd9f09ddc4e02b38cb72a966136540 | |
| parent | 0196c47511000b3ee2060af6e7fd600b23876010 (diff) | |
Moved root_command functions to commands.c
| -rw-r--r-- | bitlbee.c | 59 | ||||
| -rw-r--r-- | commands.c | 61 | ||||
| -rw-r--r-- | commands.h | 6 | 
3 files changed, 61 insertions, 65 deletions
| @@ -286,62 +286,3 @@ void bitlbee_shutdown( gpointer data )  	/* We'll only reach this point when not running in inetd mode: */  	g_main_quit( global.loop );  } - -int root_command_string( irc_t *irc, user_t *u, char *command, int flags ) -{ -	char *cmd[IRC_MAX_ARGS]; -	char *s; -	int k; -	char q = 0; -	 -	memset( cmd, 0, sizeof( cmd ) ); -	cmd[0] = command; -	k = 1; -	for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) -		if( *s == ' ' && !q ) -		{ -			*s = 0; -			while( *++s == ' ' ); -			if( *s == '"' || *s == '\'' ) -			{ -				q = *s; -				s ++; -			} -			if( *s ) -			{ -				cmd[k++] = s; -				s --; -			} -		} -		else if( *s == q ) -		{ -			q = *s = 0; -		} -	cmd[k] = NULL; -	 -	return( root_command( irc, cmd ) ); -} - -int root_command( irc_t *irc, char *cmd[] ) -{	 -	int i; -	 -	if( !cmd[0] ) -		return( 0 ); -	 -	for( i = 0; commands[i].command; i++ ) -		if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) -		{ -			if( !cmd[commands[i].required_parameters] ) -			{ -				irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters ); -				return( 0 ); -			} -			commands[i].execute( irc, cmd ); -			return( 1 ); -		} -	 -	irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); -	 -	return( 1 ); -} @@ -31,7 +31,7 @@  #include <string.h> -command_t commands[] = { +const command_t commands[] = {  	{ "help",           0, cmd_help },   	{ "identify",       1, cmd_identify },  	{ "register",       1, cmd_register }, @@ -54,6 +54,65 @@ command_t commands[] = {  	{ NULL }  }; +int root_command_string( irc_t *irc, user_t *u, char *command, int flags ) +{ +	char *cmd[IRC_MAX_ARGS]; +	char *s; +	int k; +	char q = 0; +	 +	memset( cmd, 0, sizeof( cmd ) ); +	cmd[0] = command; +	k = 1; +	for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) +		if( *s == ' ' && !q ) +		{ +			*s = 0; +			while( *++s == ' ' ); +			if( *s == '"' || *s == '\'' ) +			{ +				q = *s; +				s ++; +			} +			if( *s ) +			{ +				cmd[k++] = s; +				s --; +			} +		} +		else if( *s == q ) +		{ +			q = *s = 0; +		} +	cmd[k] = NULL; +	 +	return( root_command( irc, cmd ) ); +} + +int root_command( irc_t *irc, char *cmd[] ) +{	 +	int i; +	 +	if( !cmd[0] ) +		return( 0 ); +	 +	for( i = 0; commands[i].command; i++ ) +		if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) +		{ +			if( !cmd[commands[i].required_parameters] ) +			{ +				irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters ); +				return( 0 ); +			} +			commands[i].execute( irc, cmd ); +			return( 1 ); +		} +	 +	irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); +	 +	return( 1 ); +} +  int cmd_help( irc_t *irc, char **cmd )  {  	char param[80]; @@ -28,8 +28,6 @@  #include "bitlbee.h" -/* Hmm... Linked list? Plleeeeaaase?? ;-) */ -  typedef struct command_t  {  	char *command; @@ -57,8 +55,6 @@ int cmd_qlist( irc_t *irc, char **cmd );  int cmd_import_buddies( irc_t *irc, char **cmd );  int cmd_dump( irc_t *irc, char **cmd ); - - -extern command_t commands[]; +extern const command_t commands[];  #endif | 
