addition of silc.css
[crypto.git] / apps / irssi / src / core / commands.h
1 #ifndef __COMMANDS_H
2 #define __COMMANDS_H
3
4 #include "signals.h"
5
6 typedef struct {
7         char *name;
8         char *options;
9         GSList *signals;
10 } COMMAND_MODULE_REC;
11
12 typedef struct {
13         GSList *modules;
14         char *category;
15         char *cmd;
16         char **options; /* combined from modules[..]->options */
17 } COMMAND_REC;
18
19 enum {
20         CMDERR_OPTION_UNKNOWN = -3, /* unknown -option */
21         CMDERR_OPTION_AMBIGUOUS = -2, /* ambiguous -option */
22         CMDERR_OPTION_ARG_MISSING = -1, /* argument missing for -option */
23
24         CMDERR_UNKNOWN, /* unknown command */
25         CMDERR_AMBIGUOUS, /* ambiguous command */
26
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 */
34 };
35
36 /* Return the full command for `alias' */
37 #define alias_find(alias) \
38         iconfig_get_str("aliases", alias, NULL)
39
40 /* Returning from command function with error */
41 #define cmd_return_error(a) \
42         G_STMT_START { \
43           signal_emit("error command", 1, GINT_TO_POINTER(a)); \
44           signal_stop(); \
45           return; \
46         } G_STMT_END
47
48 #define cmd_param_error(a) \
49         G_STMT_START { \
50           cmd_params_free(free_arg); \
51           cmd_return_error(a); \
52         } G_STMT_END
53
54 extern GSList *commands;
55 extern char *current_command; /* the command we're right now. */
56
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)
63
64 void command_unbind(const char *cmd, SIGNAL_FUNC func);
65
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);
70
71 COMMAND_REC *command_find(const char *cmd);
72 int command_have_sub(const char *command);
73
74 /* Specify options that command can accept. `options' contains list of
75    options separated with space, each option can contain a special
76    char in front of it:
77
78    '!': no argument (default)
79    '-': optional argument
80    '+': argument required
81    '@': optional numeric argument
82
83    for example if options = "save -file +nick", you can use
84    /command -save -file [<filename>] -nick <nickname>
85
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)
95
96 /* Returns TRUE if command has specified option. */
97 int command_have_option(const char *cmd, const char *option);
98
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:
107
108      -cmd requiredarg -noargcmd -cmd2 "another arg" -optnumarg rest of text
109
110    You would call this with:
111
112    // only once in init
113    command_set_options("mycmd", "+cmd noargcmd -cmd2 @optnumarg");
114
115    GHashTable *optlist;
116
117    cmd_get_params(data, &free_me, 1 | PARAM_FLAG_OPTIONS |
118                   PARAM_FLAG_GETREST, "mycmd", &optlist, &rest);
119
120    The optlist hash table is filled:
121
122    "cmd" = "requiredarg"
123    "noargcmd" = ""
124    "cmd2" = "another arg"
125    "optnumarg" = "" - this is because "rest" isn't a numeric value
126 */
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
132
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.
136
137    Returns TRUE if all ok, FALSE if error occured. */
138 int cmd_get_params(const char *data, gpointer *free_me, int count, ...);
139
140 void cmd_params_free(void *free_me);
141
142 void commands_remove_module(const char *module);
143
144 void commands_init(void);
145 void commands_deinit(void);
146
147 #endif