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 */
41 CMDERR_INVALID_TIME, /* invalid time specification */
42 CMDERR_INVALID_CHARSET, /* invalid charset specification */
43 CMDERR_EVAL_MAX_RECURSE, /* eval hit recursion limit */
44 CMDERR_PROGRAM_NOT_FOUND /* program not found */
47 /* Return the full command for `alias' */
48 #define alias_find(alias) \
49 iconfig_get_str("aliases", alias, NULL)
51 /* Returning from command function with error */
52 #define cmd_return_error(a) \
54 signal_emit("error command", 1, GINT_TO_POINTER(a)); \
59 #define cmd_param_error(a) \
61 cmd_params_free(free_arg); \
62 cmd_return_error(a); \
65 extern GSList *commands;
66 extern char *current_command; /* the command we're right now. */
68 /* Bind command to specified function. */
69 void command_bind_full(const char *module, int priority, const char *cmd,
70 int protocol, const char *category, SIGNAL_FUNC func,
72 #define command_bind(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, -1, b, c, NULL)
73 #define command_bind_first(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, -1, b, c, NULL)
74 #define command_bind_last(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, -1, b, c, NULL)
76 #define command_bind_data(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, -1, b, c, d)
77 #define command_bind_data_first(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, -1, b, c, d)
78 #define command_bind_data_last(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, -1, b, c, d)
80 #define command_bind_proto(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, b, c, d, NULL)
81 #define command_bind_proto_first(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, b, c, d, NULL)
82 #define command_bind_proto_last(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, b, c, d, NULL)
84 void command_unbind_full(const char *cmd, SIGNAL_FUNC func, void *user_data);
85 #define command_unbind(cmd, func) command_unbind_full(cmd, func, NULL)
87 /* Run subcommand, `cmd' contains the base command, first word in `data'
88 contains the subcommand */
89 void command_runsub(const char *cmd, const char *data,
90 void *server, void *item);
92 COMMAND_REC *command_find(const char *cmd);
93 int command_have_sub(const char *command);
95 /* Specify options that command can accept. `options' contains list of
96 options separated with space, each option can contain a special
99 '!': no argument (default)
100 '-': optional argument
101 '+': argument required
102 '@': optional numeric argument
104 for example if options = "save -file +nick", you can use
105 /command -save -file [<filename>] -nick <nickname>
107 You can call this command multiple times for same command, options
108 will be merged. If there's any conflicts with option types, the last
109 call will override the previous */
110 #define iscmdtype(c) \
111 ((c) == '!' || (c) == '-' || (c) == '+' || (c) == '@')
112 void command_set_options_module(const char *module,
113 const char *cmd, const char *options);
114 #define command_set_options(cmd, options) \
115 command_set_options_module(MODULE_NAME, cmd, options)
117 /* Returns TRUE if command has specified option. */
118 int command_have_option(const char *cmd, const char *option);
120 /* count can have these flags: */
121 #define PARAM_WITHOUT_FLAGS(a) ((a) & 0x00000fff)
122 /* don't check for quotes - "arg1 arg2" is NOT treated as one argument */
123 #define PARAM_FLAG_NOQUOTES 0x00001000
124 /* final argument gets all the rest of the arguments */
125 #define PARAM_FLAG_GETREST 0x00002000
126 /* command contains options - first you need to specify them with
127 command_set_options() function. Example:
129 -cmd requiredarg -noargcmd -cmd2 "another arg" -optnumarg rest of text
131 You would call this with:
134 command_set_options("mycmd", "+cmd noargcmd -cmd2 @optnumarg");
138 cmd_get_params(data, &free_me, 1 | PARAM_FLAG_OPTIONS |
139 PARAM_FLAG_GETREST, "mycmd", &optlist, &rest);
141 The optlist hash table is filled:
143 "cmd" = "requiredarg"
145 "cmd2" = "another arg"
146 "optnumarg" = "" - this is because "rest" isn't a numeric value
148 #define PARAM_FLAG_OPTIONS 0x00004000
149 /* don't complain about unknown options */
150 #define PARAM_FLAG_UNKNOWN_OPTIONS 0x00008000
151 /* optional channel in first argument */
152 #define PARAM_FLAG_OPTCHAN 0x00010000
153 /* optional channel in first argument, but don't treat "*" as current channel */
154 #define PARAM_FLAG_OPTCHAN_NAME (0x00020000|PARAM_FLAG_OPTCHAN)
156 char *cmd_get_param(char **data);
157 char *cmd_get_quoted_param(char **data);
158 /* get parameters from command - you should point free_me somewhere and
159 cmd_params_free() it after you don't use any of the parameters anymore.
161 Returns TRUE if all ok, FALSE if error occured. */
162 int cmd_get_params(const char *data, gpointer *free_me, int count, ...);
164 void cmd_params_free(void *free_me);
166 void commands_remove_module(const char *module);
168 void commands_init(void);
169 void commands_deinit(void);