9 } COMMAND_CALLBACK_REC;
14 int protocol; /* chat protocol required for this command */
22 char **options; /* combined from modules[..]->options */
26 CMDERR_OPTION_UNKNOWN = -3, /* unknown -option */
27 CMDERR_OPTION_AMBIGUOUS = -2, /* ambiguous -option */
28 CMDERR_OPTION_ARG_MISSING = -1, /* argument missing for -option */
30 CMDERR_UNKNOWN, /* unknown command */
31 CMDERR_AMBIGUOUS, /* ambiguous command */
33 CMDERR_ERRNO, /* get the error from errno */
34 CMDERR_NOT_ENOUGH_PARAMS, /* not enough parameters given */
35 CMDERR_NOT_CONNECTED, /* not connected to server */
36 CMDERR_NOT_JOINED, /* not joined to any channels in this window */
37 CMDERR_CHAN_NOT_FOUND, /* channel not found */
38 CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */
39 CMDERR_ILLEGAL_PROTO, /* requires different chat protocol than the active server */
40 CMDERR_NOT_GOOD_IDEA /* not good idea to do, -yes overrides this */
43 /* Return the full command for `alias' */
44 #define alias_find(alias) \
45 iconfig_get_str("aliases", alias, NULL)
47 /* Returning from command function with error */
48 #define cmd_return_error(a) \
50 signal_emit("error command", 1, GINT_TO_POINTER(a)); \
55 #define cmd_param_error(a) \
57 cmd_params_free(free_arg); \
58 cmd_return_error(a); \
61 extern GSList *commands;
62 extern char *current_command; /* the command we're right now. */
64 /* Bind command to specified function. */
65 void command_bind_full(const char *module, int priority, const char *cmd,
66 int protocol, const char *category, SIGNAL_FUNC func,
68 #define command_bind(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, -1, b, c, NULL)
69 #define command_bind_first(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, -1, b, c, NULL)
70 #define command_bind_last(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, -1, b, c, NULL)
72 #define command_bind_data(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, -1, b, c, d)
73 #define command_bind_data_first(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, -1, b, c, d)
74 #define command_bind_data_last(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, -1, b, c, d)
76 #define command_bind_proto(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, b, c, d, NULL)
77 #define command_bind_proto_first(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, b, c, d, NULL)
78 #define command_bind_proto_last(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, b, c, d, NULL)
80 void command_unbind_full(const char *cmd, SIGNAL_FUNC func, void *user_data);
81 #define command_unbind(cmd, func) command_unbind_full(cmd, func, NULL)
83 /* Run subcommand, `cmd' contains the base command, first word in `data'
84 contains the subcommand */
85 void command_runsub(const char *cmd, const char *data,
86 void *server, void *item);
88 COMMAND_REC *command_find(const char *cmd);
89 int command_have_sub(const char *command);
91 /* Specify options that command can accept. `options' contains list of
92 options separated with space, each option can contain a special
95 '!': no argument (default)
96 '-': optional argument
97 '+': argument required
98 '@': optional numeric argument
100 for example if options = "save -file +nick", you can use
101 /command -save -file [<filename>] -nick <nickname>
103 You can call this command multiple times for same command, options
104 will be merged. If there's any conflicts with option types, the last
105 call will override the previous */
106 #define iscmdtype(c) \
107 ((c) == '!' || (c) == '-' || (c) == '+' || (c) == '@')
108 void command_set_options_module(const char *module,
109 const char *cmd, const char *options);
110 #define command_set_options(cmd, options) \
111 command_set_options_module(MODULE_NAME, cmd, options)
113 /* Returns TRUE if command has specified option. */
114 int command_have_option(const char *cmd, const char *option);
116 /* count can have these flags: */
117 #define PARAM_WITHOUT_FLAGS(a) ((a) & 0x00000fff)
118 /* don't check for quotes - "arg1 arg2" is NOT treated as one argument */
119 #define PARAM_FLAG_NOQUOTES 0x00001000
120 /* final argument gets all the rest of the arguments */
121 #define PARAM_FLAG_GETREST 0x00002000
122 /* command contains options - first you need to specify them with
123 command_set_options() function. Example:
125 -cmd requiredarg -noargcmd -cmd2 "another arg" -optnumarg rest of text
127 You would call this with:
130 command_set_options("mycmd", "+cmd noargcmd -cmd2 @optnumarg");
134 cmd_get_params(data, &free_me, 1 | PARAM_FLAG_OPTIONS |
135 PARAM_FLAG_GETREST, "mycmd", &optlist, &rest);
137 The optlist hash table is filled:
139 "cmd" = "requiredarg"
141 "cmd2" = "another arg"
142 "optnumarg" = "" - this is because "rest" isn't a numeric value
144 #define PARAM_FLAG_OPTIONS 0x00004000
145 /* don't complain about unknown options */
146 #define PARAM_FLAG_UNKNOWN_OPTIONS 0x00008000
147 /* optional channel in first argument */
148 #define PARAM_FLAG_OPTCHAN 0x00010000
149 /* optional channel in first argument, but don't treat "*" as current channel */
150 #define PARAM_FLAG_OPTCHAN_NAME (0x00020000|PARAM_FLAG_OPTCHAN)
152 char *cmd_get_param(char **data);
153 /* get parameters from command - you should point free_me somewhere and
154 cmd_params_free() it after you don't use any of the parameters anymore.
156 Returns TRUE if all ok, FALSE if error occured. */
157 int cmd_get_params(const char *data, gpointer *free_me, int count, ...);
159 void cmd_params_free(void *free_me);
161 void commands_remove_module(const char *module);
163 void commands_init(void);
164 void commands_deinit(void);