16 char **options; /* combined from modules[..]->options */
20 CMDERR_OPTION_UNKNOWN = -3, /* unknown -option */
21 CMDERR_OPTION_AMBIGUOUS = -2, /* ambiguous -option */
22 CMDERR_OPTION_ARG_MISSING = -1, /* argument missing for -option */
24 CMDERR_UNKNOWN, /* unknown command */
25 CMDERR_AMBIGUOUS, /* ambiguous command */
27 CMDERR_ERRNO, /* get the error from errno */
28 CMDERR_NOT_ENOUGH_PARAMS, /* not enough parameters given */
29 CMDERR_NOT_CONNECTED, /* not connected to IRC server */
30 CMDERR_NOT_JOINED, /* not joined to any channels in this window */
31 CMDERR_CHAN_NOT_FOUND, /* channel not found */
32 CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */
33 CMDERR_NOT_GOOD_IDEA /* not good idea to do, -yes overrides this */
36 /* Return the full command for `alias' */
37 #define alias_find(alias) \
38 iconfig_get_str("aliases", alias, NULL)
40 /* Returning from command function with error */
41 #define cmd_return_error(a) \
43 signal_emit("error command", 1, GINT_TO_POINTER(a)); \
48 #define cmd_param_error(a) \
50 cmd_params_free(free_arg); \
51 cmd_return_error(a); \
54 extern GSList *commands;
55 extern char *current_command; /* the command we're right now. */
57 /* Bind command to specified function. */
58 void command_bind_to(const char *module, int pos, const char *cmd,
59 const char *category, SIGNAL_FUNC func);
60 #define command_bind(a, b, c) command_bind_to(MODULE_NAME, 1, a, b, c)
61 #define command_bind_first(a, b, c) command_bind_to(MODULE_NAME, 0, a, b, c)
62 #define command_bind_last(a, b, c) command_bind_to(MODULE_NAME, 2, a, b, c)
64 void command_unbind(const char *cmd, SIGNAL_FUNC func);
66 /* Run subcommand, `cmd' contains the base command, first word in `data'
67 contains the subcommand */
68 void command_runsub(const char *cmd, const char *data,
69 void *server, void *item);
71 COMMAND_REC *command_find(const char *cmd);
72 int command_have_sub(const char *command);
74 /* Specify options that command can accept. `options' contains list of
75 options separated with space, each option can contain a special
78 '!': no argument (default)
79 '-': optional argument
80 '+': argument required
81 '@': optional numeric argument
83 for example if options = "save -file +nick", you can use
84 /command -save -file [<filename>] -nick <nickname>
86 You can call this command multiple times for same command, options
87 will be merged. If there's any conflicts with option types, the last
88 call will override the previous */
89 #define iscmdtype(c) \
90 ((c) == '!' || (c) == '-' || (c) == '+' || (c) == '@')
91 void command_set_options_module(const char *module,
92 const char *cmd, const char *options);
93 #define command_set_options(cmd, options) \
94 command_set_options_module(MODULE_NAME, cmd, options)
96 /* Returns TRUE if command has specified option. */
97 int command_have_option(const char *cmd, const char *option);
99 /* count can have these flags: */
100 #define PARAM_WITHOUT_FLAGS(a) ((a) & 0x00000fff)
101 /* don't check for quotes - "arg1 arg2" is NOT treated as one argument */
102 #define PARAM_FLAG_NOQUOTES 0x00001000
103 /* final argument gets all the rest of the arguments */
104 #define PARAM_FLAG_GETREST 0x00002000
105 /* command contains options - first you need to specify them with
106 command_set_options() function. Example:
108 -cmd requiredarg -noargcmd -cmd2 "another arg" -optnumarg rest of text
110 You would call this with:
113 command_set_options("mycmd", "+cmd noargcmd -cmd2 @optnumarg");
117 cmd_get_params(data, &free_me, 1 | PARAM_FLAG_OPTIONS |
118 PARAM_FLAG_GETREST, "mycmd", &optlist, &rest);
120 The optlist hash table is filled:
122 "cmd" = "requiredarg"
124 "cmd2" = "another arg"
125 "optnumarg" = "" - this is because "rest" isn't a numeric value
127 #define PARAM_FLAG_OPTIONS 0x00004000
128 /* don't complain about unknown options */
129 #define PARAM_FLAG_UNKNOWN_OPTIONS 0x00008000
130 /* optional channel in first argument */
131 #define PARAM_FLAG_OPTCHAN 0x00010000
133 char *cmd_get_param(char **data);
134 /* get parameters from command - you should point free_me somewhere and
135 cmd_params_free() it after you don't use any of the parameters anymore.
137 Returns TRUE if all ok, FALSE if error occured. */
138 int cmd_get_params(const char *data, gpointer *free_me, int count, ...);
140 void cmd_params_free(void *free_me);
142 void commands_remove_module(const char *module);
144 void commands_init(void);
145 void commands_deinit(void);