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