2000-04-26 04:03:38 -04:00
|
|
|
#ifndef __COMMANDS_H
|
|
|
|
#define __COMMANDS_H
|
|
|
|
|
|
|
|
#include "signals.h"
|
|
|
|
|
2002-04-16 14:11:06 -04:00
|
|
|
typedef struct {
|
|
|
|
SIGNAL_FUNC func;
|
|
|
|
void *user_data;
|
|
|
|
} COMMAND_CALLBACK_REC;
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
typedef struct {
|
2000-12-16 23:14:47 -05:00
|
|
|
char *name;
|
|
|
|
char *options;
|
2001-11-01 20:05:14 -05:00
|
|
|
int protocol; /* chat protocol required for this command */
|
2002-04-16 14:11:06 -04:00
|
|
|
GSList *callbacks;
|
2000-12-16 23:14:47 -05:00
|
|
|
} COMMAND_MODULE_REC;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GSList *modules;
|
2000-04-26 04:03:38 -04:00
|
|
|
char *category;
|
|
|
|
char *cmd;
|
2000-12-16 23:14:47 -05:00
|
|
|
char **options; /* combined from modules[..]->options */
|
2000-06-17 21:18:12 -04:00
|
|
|
} COMMAND_REC;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
enum {
|
2000-06-28 11:36:57 -04:00
|
|
|
CMDERR_OPTION_UNKNOWN = -3, /* unknown -option */
|
|
|
|
CMDERR_OPTION_AMBIGUOUS = -2, /* ambiguous -option */
|
2000-06-17 21:18:12 -04:00
|
|
|
CMDERR_OPTION_ARG_MISSING = -1, /* argument missing for -option */
|
|
|
|
|
2000-06-28 13:15:37 -04:00
|
|
|
CMDERR_UNKNOWN, /* unknown command */
|
|
|
|
CMDERR_AMBIGUOUS, /* ambiguous command */
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
CMDERR_ERRNO, /* get the error from errno */
|
2000-04-26 04:03:38 -04:00
|
|
|
CMDERR_NOT_ENOUGH_PARAMS, /* not enough parameters given */
|
2001-11-01 20:05:14 -05:00
|
|
|
CMDERR_NOT_CONNECTED, /* not connected to server */
|
2000-04-26 04:03:38 -04:00
|
|
|
CMDERR_NOT_JOINED, /* not joined to any channels in this window */
|
|
|
|
CMDERR_CHAN_NOT_FOUND, /* channel not found */
|
|
|
|
CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */
|
2001-11-01 20:05:14 -05:00
|
|
|
CMDERR_ILLEGAL_PROTO, /* requires different chat protocol than the active server */
|
2000-04-26 04:03:38 -04:00
|
|
|
CMDERR_NOT_GOOD_IDEA /* not good idea to do, -yes overrides this */
|
|
|
|
};
|
|
|
|
|
2000-06-28 11:36:57 -04:00
|
|
|
/* Return the full command for `alias' */
|
2000-06-25 18:59:49 -04:00
|
|
|
#define alias_find(alias) \
|
|
|
|
iconfig_get_str("aliases", alias, NULL)
|
|
|
|
|
2000-06-28 11:36:57 -04:00
|
|
|
/* Returning from command function with error */
|
|
|
|
#define cmd_return_error(a) \
|
2000-07-16 16:18:05 -04:00
|
|
|
G_STMT_START { \
|
|
|
|
signal_emit("error command", 1, GINT_TO_POINTER(a)); \
|
|
|
|
signal_stop(); \
|
|
|
|
return; \
|
|
|
|
} G_STMT_END
|
|
|
|
|
2000-06-28 11:36:57 -04:00
|
|
|
#define cmd_param_error(a) \
|
2000-07-16 16:18:05 -04:00
|
|
|
G_STMT_START { \
|
|
|
|
cmd_params_free(free_arg); \
|
|
|
|
cmd_return_error(a); \
|
|
|
|
} G_STMT_END
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
extern GSList *commands;
|
2000-06-28 11:36:57 -04:00
|
|
|
extern char *current_command; /* the command we're right now. */
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-28 11:36:57 -04:00
|
|
|
/* Bind command to specified function. */
|
2002-04-16 14:11:06 -04:00
|
|
|
void command_bind_full(const char *module, int priority, const char *cmd,
|
|
|
|
int protocol, const char *category, SIGNAL_FUNC func,
|
|
|
|
void *user_data);
|
|
|
|
#define command_bind(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, -1, b, c, NULL)
|
|
|
|
#define command_bind_first(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, -1, b, c, NULL)
|
|
|
|
#define command_bind_last(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, -1, b, c, NULL)
|
|
|
|
|
|
|
|
#define command_bind_data(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, -1, b, c, d)
|
|
|
|
#define command_bind_data_first(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, -1, b, c, d)
|
|
|
|
#define command_bind_data_last(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, -1, b, c, d)
|
|
|
|
|
|
|
|
#define command_bind_proto(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, b, c, d, NULL)
|
|
|
|
#define command_bind_proto_first(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, b, c, d, NULL)
|
|
|
|
#define command_bind_proto_last(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, b, c, d, NULL)
|
|
|
|
|
|
|
|
void command_unbind_full(const char *cmd, SIGNAL_FUNC func, void *user_data);
|
|
|
|
#define command_unbind(cmd, func) command_unbind_full(cmd, func, NULL)
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
/* Run subcommand, `cmd' contains the base command, first word in `data'
|
|
|
|
contains the subcommand */
|
2000-07-16 16:18:05 -04:00
|
|
|
void command_runsub(const char *cmd, const char *data,
|
|
|
|
void *server, void *item);
|
2000-06-17 21:18:12 -04:00
|
|
|
|
|
|
|
COMMAND_REC *command_find(const char *cmd);
|
2000-07-08 20:03:46 -04:00
|
|
|
int command_have_sub(const char *command);
|
2000-06-17 21:18:12 -04:00
|
|
|
|
|
|
|
/* Specify options that command can accept. `options' contains list of
|
|
|
|
options separated with space, each option can contain a special
|
|
|
|
char in front of it:
|
|
|
|
|
2000-08-15 20:48:29 -04:00
|
|
|
'!': no argument (default)
|
2000-06-17 21:18:12 -04:00
|
|
|
'-': optional argument
|
|
|
|
'+': argument required
|
|
|
|
'@': optional numeric argument
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
for example if options = "save -file +nick", you can use
|
|
|
|
/command -save -file [<filename>] -nick <nickname>
|
|
|
|
|
|
|
|
You can call this command multiple times for same command, options
|
|
|
|
will be merged. If there's any conflicts with option types, the last
|
|
|
|
call will override the previous */
|
2000-06-28 11:36:57 -04:00
|
|
|
#define iscmdtype(c) \
|
2000-08-15 20:48:29 -04:00
|
|
|
((c) == '!' || (c) == '-' || (c) == '+' || (c) == '@')
|
2000-12-16 23:14:47 -05:00
|
|
|
void command_set_options_module(const char *module,
|
|
|
|
const char *cmd, const char *options);
|
|
|
|
#define command_set_options(cmd, options) \
|
|
|
|
command_set_options_module(MODULE_NAME, cmd, options)
|
2000-06-17 11:58:40 -04:00
|
|
|
|
2000-08-11 22:16:52 -04:00
|
|
|
/* Returns TRUE if command has specified option. */
|
|
|
|
int command_have_option(const char *cmd, const char *option);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
/* count can have these flags: */
|
2001-05-11 11:48:09 -04:00
|
|
|
#define PARAM_WITHOUT_FLAGS(a) ((a) & 0x00000fff)
|
2000-06-04 10:52:47 -04:00
|
|
|
/* don't check for quotes - "arg1 arg2" is NOT treated as one argument */
|
2001-05-11 11:48:09 -04:00
|
|
|
#define PARAM_FLAG_NOQUOTES 0x00001000
|
2000-06-04 10:52:47 -04:00
|
|
|
/* final argument gets all the rest of the arguments */
|
2001-05-11 11:48:09 -04:00
|
|
|
#define PARAM_FLAG_GETREST 0x00002000
|
2000-06-17 21:18:12 -04:00
|
|
|
/* command contains options - first you need to specify them with
|
|
|
|
command_set_options() function. Example:
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
-cmd requiredarg -noargcmd -cmd2 "another arg" -optnumarg rest of text
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
You would call this with:
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
// only once in init
|
|
|
|
command_set_options("mycmd", "+cmd noargcmd -cmd2 @optnumarg");
|
|
|
|
|
|
|
|
GHashTable *optlist;
|
|
|
|
|
|
|
|
cmd_get_params(data, &free_me, 1 | PARAM_FLAG_OPTIONS |
|
|
|
|
PARAM_FLAG_GETREST, "mycmd", &optlist, &rest);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
The optlist hash table is filled:
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
"cmd" = "requiredarg"
|
|
|
|
"noargcmd" = ""
|
|
|
|
"cmd2" = "another arg"
|
|
|
|
"optnumarg" = "" - this is because "rest" isn't a numeric value
|
2000-04-26 04:03:38 -04:00
|
|
|
*/
|
2001-05-11 11:48:09 -04:00
|
|
|
#define PARAM_FLAG_OPTIONS 0x00004000
|
2000-06-17 21:18:12 -04:00
|
|
|
/* don't complain about unknown options */
|
2001-05-11 11:48:09 -04:00
|
|
|
#define PARAM_FLAG_UNKNOWN_OPTIONS 0x00008000
|
|
|
|
/* optional channel in first argument */
|
|
|
|
#define PARAM_FLAG_OPTCHAN 0x00010000
|
2002-02-03 13:24:22 -05:00
|
|
|
/* optional channel in first argument, but don't treat "*" as current channel */
|
2002-02-13 09:09:21 -05:00
|
|
|
#define PARAM_FLAG_OPTCHAN_NAME (0x00020000|PARAM_FLAG_OPTCHAN)
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
char *cmd_get_param(char **data);
|
2000-06-17 21:18:12 -04:00
|
|
|
/* get parameters from command - you should point free_me somewhere and
|
|
|
|
cmd_params_free() it after you don't use any of the parameters anymore.
|
|
|
|
|
|
|
|
Returns TRUE if all ok, FALSE if error occured. */
|
|
|
|
int cmd_get_params(const char *data, gpointer *free_me, int count, ...);
|
|
|
|
|
|
|
|
void cmd_params_free(void *free_me);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-12-16 23:14:47 -05:00
|
|
|
void commands_remove_module(const char *module);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
void commands_init(void);
|
|
|
|
void commands_deinit(void);
|
|
|
|
|
|
|
|
#endif
|