diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2022-05-21 14:13:28 +0200 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2022-05-21 14:13:28 +0200 |
commit | 24effe857346411aa6b92c7d238441ce0e6cd861 (patch) | |
tree | 20abb0897453f67c53176398601a5434d6ad7efe /vchat-commands.c | |
parent | dc6e13b39ba2190d7f11378be48f8ccfe10d47f6 (diff) |
Reformatted using clang-format -format llvm
Diffstat (limited to 'vchat-commands.c')
-rwxr-xr-x | vchat-commands.c | 519 |
1 files changed, 253 insertions, 266 deletions
diff --git a/vchat-commands.c b/vchat-commands.c index 8094a7c..9aa3abd 100755 --- a/vchat-commands.c +++ b/vchat-commands.c | |||
@@ -10,27 +10,29 @@ | |||
10 | * without even the implied warranty of merchantability or fitness for a | 10 | * without even the implied warranty of merchantability or fitness for a |
11 | * particular purpose. In no event shall the copyright holder be liable for | 11 | * particular purpose. In no event shall the copyright holder be liable for |
12 | * any direct, indirect, incidental or special damages arising in any way out | 12 | * any direct, indirect, incidental or special damages arising in any way out |
13 | * of the use of this software. | 13 | * of the use of this software. |
14 | * | 14 | * |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /* general includes */ | 17 | /* general includes */ |
18 | #include <stdlib.h> | ||
19 | #include <unistd.h> | ||
20 | #include <errno.h> | 18 | #include <errno.h> |
21 | #include <stdio.h> | 19 | #include <stdio.h> |
20 | #include <stdlib.h> | ||
22 | #include <string.h> | 21 | #include <string.h> |
23 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
23 | #include <unistd.h> | ||
24 | |||
24 | #include <readline/readline.h> | 25 | #include <readline/readline.h> |
25 | 26 | ||
26 | /* local includes */ | 27 | /* local includes */ |
27 | #include "vchat.h" | ||
28 | #include "vchat-connection.h" | 28 | #include "vchat-connection.h" |
29 | #include "vchat-help.h" | 29 | #include "vchat-help.h" |
30 | #include "vchat-user.h" | 30 | #include "vchat-user.h" |
31 | #include "vchat.h" | ||
31 | 32 | ||
32 | /* version of this module */ | 33 | /* version of this module */ |
33 | const char *vchat_cm_version = "vchat-commands.c $Id$"; | 34 | const char *vchat_cm_version = |
35 | "vchat-commands.c $Id$"; | ||
34 | 36 | ||
35 | /* from vchat-client.c */ | 37 | /* from vchat-client.c */ |
36 | extern int ownquit; | 38 | extern int ownquit; |
@@ -39,45 +41,45 @@ extern int status; | |||
39 | 41 | ||
40 | /* our "/command " table */ | 42 | /* our "/command " table */ |
41 | enum { | 43 | enum { |
42 | COMMAND_VERSION, | 44 | COMMAND_VERSION, |
43 | COMMAND_FILTERS, | 45 | COMMAND_FILTERS, |
44 | COMMAND_LSFLT, | 46 | COMMAND_LSFLT, |
45 | COMMAND_RMFLT, | 47 | COMMAND_RMFLT, |
46 | COMMAND_CLFLT, | 48 | COMMAND_CLFLT, |
47 | COMMAND_HELP, | 49 | COMMAND_HELP, |
48 | COMMAND_FORMAT, | 50 | COMMAND_FORMAT, |
49 | COMMAND_KEYS, | 51 | COMMAND_KEYS, |
50 | COMMAND_QUIT, | 52 | COMMAND_QUIT, |
51 | COMMAND_USER, | 53 | COMMAND_USER, |
52 | COMMAND_DICT, | 54 | COMMAND_DICT, |
53 | COMMAND_FLT, | 55 | COMMAND_FLT, |
54 | COMMAND_PM, | 56 | COMMAND_PM, |
55 | COMMAND_ACTION, | 57 | COMMAND_ACTION, |
56 | COMMAND_PMSHORT, | 58 | COMMAND_PMSHORT, |
57 | COMMAND_QUERY, | 59 | COMMAND_QUERY, |
58 | COMMAND_QUITSHORT, | 60 | COMMAND_QUITSHORT, |
59 | COMMAND_PLAIN, | 61 | COMMAND_PLAIN, |
60 | COMMAND_RECONNECT, | 62 | COMMAND_RECONNECT, |
61 | COMMAND_NONE | 63 | COMMAND_NONE |
62 | }; | 64 | }; |
63 | 65 | ||
64 | static void command_quit ( char *tail); | 66 | static void command_quit(char *tail); |
65 | static void command_user ( char *tail); | 67 | static void command_user(char *tail); |
66 | static void command_pm ( char *tail); | 68 | static void command_pm(char *tail); |
67 | static void command_action ( char *tail); | 69 | static void command_action(char *tail); |
68 | static void command_help ( char *tail); | 70 | static void command_help(char *tail); |
69 | static void command_format ( char *tail); | 71 | static void command_format(char *tail); |
70 | static void command_flt ( char *tail); | 72 | static void command_flt(char *tail); |
71 | static void command_lsflt ( char *tail); | 73 | static void command_lsflt(char *tail); |
72 | static void command_clflt ( char *tail); | 74 | static void command_clflt(char *tail); |
73 | static void command_rmflt ( char *tail); | 75 | static void command_rmflt(char *tail); |
74 | void command_version ( char *tail); | 76 | void command_version(char *tail); |
75 | static void command_none ( char *line); | 77 | static void command_none(char *line); |
76 | static void command_query ( char *tail); | 78 | static void command_query(char *tail); |
77 | static void command_reconnect ( char *tail); | 79 | static void command_reconnect(char *tail); |
78 | static void command_dict ( char *tail); | 80 | static void command_dict(char *tail); |
79 | 81 | ||
80 | static void output_default ( char *tail); | 82 | static void output_default(char *tail); |
81 | 83 | ||
82 | /* commandentry defined in vchat.h */ | 84 | /* commandentry defined in vchat.h */ |
83 | 85 | ||
@@ -106,9 +108,7 @@ commandtable[] = { | |||
106 | }; | 108 | }; |
107 | 109 | ||
108 | /* parse "/command" */ | 110 | /* parse "/command" */ |
109 | static int | 111 | static int translatecommand(char **cmd) { |
110 | translatecommand( char **cmd) | ||
111 | { | ||
112 | int result; | 112 | int result; |
113 | int cut = 0; | 113 | int cut = 0; |
114 | int maxcut = 0; | 114 | int maxcut = 0; |
@@ -116,214 +116,215 @@ translatecommand( char **cmd) | |||
116 | /* We do only want to allow Command abbrevation to | 116 | /* We do only want to allow Command abbrevation to |
117 | the next newline, so that /VRES won't expand to /V RES */ | 117 | the next newline, so that /VRES won't expand to /V RES */ |
118 | 118 | ||
119 | while( (*cmd)[maxcut] && ((*cmd)[maxcut] != 0x20) && ((*cmd)[maxcut] != '\n')) maxcut++; | 119 | while ((*cmd)[maxcut] && ((*cmd)[maxcut] != 0x20) && ((*cmd)[maxcut] != '\n')) |
120 | if( maxcut ) maxcut--; | 120 | maxcut++; |
121 | if (maxcut) | ||
122 | maxcut--; | ||
121 | 123 | ||
122 | /* Repeatedly scan command table for command, with growing abbrevation cut off */ | 124 | /* Repeatedly scan command table for command, with growing abbrevation cut off |
125 | */ | ||
123 | do { | 126 | do { |
124 | /* Looks ugly, needs rewrite for better understanding */ | 127 | /* Looks ugly, needs rewrite for better understanding */ |
125 | for( result = 0; | 128 | for (result = 0; |
126 | (result != COMMAND_NONE) && | 129 | (result != COMMAND_NONE) && |
127 | (strncasecmp(*cmd, commandtable[result].name, commandtable[result].len - | 130 | (strncasecmp( |
128 | ((commandtable[result].len - maxcut - cut > 0) ? cut : 0))); | 131 | *cmd, commandtable[result].name, |
129 | result++); | 132 | commandtable[result].len - |
130 | } while ((cut < commandtable[0].len) && (commandtable[result].number == COMMAND_NONE) && (++cut)); | 133 | ((commandtable[result].len - maxcut - cut > 0) ? cut : 0))); |
134 | result++) | ||
135 | ; | ||
136 | } while ((cut < commandtable[0].len) && | ||
137 | (commandtable[result].number == COMMAND_NONE) && (++cut)); | ||
131 | 138 | ||
132 | /* Just leave the tail... */ | 139 | /* Just leave the tail... */ |
133 | (*cmd) += commandtable[result].len; | 140 | (*cmd) += commandtable[result].len; |
134 | 141 | ||
135 | /* ... whose start may be affected by abbrevation */ | 142 | /* ... whose start may be affected by abbrevation */ |
136 | if( commandtable[result].number != COMMAND_NONE ) | 143 | if (commandtable[result].number != COMMAND_NONE) |
137 | (*cmd) -= cut; | 144 | (*cmd) -= cut; |
138 | 145 | ||
139 | return result; | 146 | return result; |
140 | } | 147 | } |
141 | 148 | ||
142 | /* handle thought */ | 149 | /* handle thought */ |
143 | static void | 150 | static void dothink(const char *tail, const char nice) { |
144 | dothink(const char *tail, const char nice ) | 151 | while (*tail == ' ') |
145 | { | 152 | tail++; |
146 | while( *tail == ' ' ) tail++; | ||
147 | 153 | ||
148 | /* send users message to server */ | 154 | /* send users message to server */ |
149 | snprintf (tmpstr, TMPSTRSIZE, ".%c %s", nice, tail); | 155 | snprintf(tmpstr, TMPSTRSIZE, ".%c %s", nice, tail); |
150 | vc_sendmessage (tmpstr); | 156 | vc_sendmessage(tmpstr); |
151 | 157 | ||
152 | /* show action in channel window */ | 158 | /* show action in channel window */ |
153 | snprintf (tmpstr, TMPSTRSIZE, nice == 'O' ? getformatstr(FS_TXPUBNTHOUGHT) : getformatstr(FS_TXPUBTHOUGHT), tail); | 159 | snprintf(tmpstr, TMPSTRSIZE, |
154 | writechan (tmpstr); | 160 | nice == 'O' ? getformatstr(FS_TXPUBNTHOUGHT) |
161 | : getformatstr(FS_TXPUBTHOUGHT), | ||
162 | tail); | ||
163 | writechan(tmpstr); | ||
155 | } | 164 | } |
156 | 165 | ||
157 | |||
158 | /* handle action */ | 166 | /* handle action */ |
159 | static void | 167 | static void doaction(const char *tail) { |
160 | doaction(const char *tail ) | 168 | while (*tail == ' ') |
161 | { | 169 | tail++; |
162 | while( *tail == ' ' ) tail++; | 170 | |
163 | 171 | if (*tail) { | |
164 | if( *tail ) { | 172 | /* send users message to server */ |
165 | /* send users message to server */ | 173 | snprintf(tmpstr, TMPSTRSIZE, ".a %s", tail); |
166 | snprintf (tmpstr, TMPSTRSIZE, ".a %s", tail); | 174 | vc_sendmessage(tmpstr); |
167 | vc_sendmessage (tmpstr); | 175 | |
168 | 176 | /* show action in channel window */ | |
169 | /* show action in channel window */ | 177 | snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBACTION), own_nick_get(), |
170 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBACTION), own_nick_get(), tail); | 178 | tail); |
171 | writechan (tmpstr); | 179 | writechan(tmpstr); |
172 | } else { | 180 | } else { |
173 | /* missing action */ | 181 | /* missing action */ |
174 | msgout( " You do nothing. " ); | 182 | msgout(" You do nothing. "); |
175 | } | 183 | } |
176 | } | 184 | } |
177 | 185 | ||
178 | /* handle private message outgoing */ | 186 | /* handle private message outgoing */ |
179 | static void | 187 | static void privatemessagetx(char *tail) { |
180 | privatemessagetx (char *tail ) { | ||
181 | char *mesg; | 188 | char *mesg; |
182 | 189 | ||
183 | /* find nick */ | 190 | /* find nick */ |
184 | while( *tail==' ') tail++; | 191 | while (*tail == ' ') |
192 | tail++; | ||
185 | 193 | ||
186 | /* find message */ | 194 | /* find message */ |
187 | mesg = tail; | 195 | mesg = tail; |
188 | while ( *mesg && *mesg!=' ') mesg++; | 196 | while (*mesg && *mesg != ' ') |
197 | mesg++; | ||
189 | 198 | ||
190 | /* check for nick && message */ | 199 | /* check for nick && message */ |
191 | if(*tail && *mesg) { | 200 | if (*tail && *mesg) { |
192 | 201 | ||
193 | /* terminate nick, move to rel start */ | 202 | /* terminate nick, move to rel start */ |
194 | *mesg++ = '\0'; | 203 | *mesg++ = '\0'; |
195 | 204 | ||
196 | /* form message and send to server */ | 205 | /* form message and send to server */ |
197 | snprintf (tmpstr, TMPSTRSIZE, ".m %s %s", tail, mesg); | 206 | snprintf(tmpstr, TMPSTRSIZE, ".m %s %s", tail, mesg); |
198 | vc_sendmessage (tmpstr); | 207 | vc_sendmessage(tmpstr); |
199 | 208 | ||
200 | /* show message in private window */ | 209 | /* show message in private window */ |
201 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPRIVMSG), tail, mesg); | 210 | snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_TXPRIVMSG), tail, mesg); |
202 | writepriv (tmpstr, 0); | 211 | writepriv(tmpstr, 0); |
203 | 212 | ||
204 | /* note we messaged someone */ | 213 | /* note we messaged someone */ |
205 | ul_private_action(tail); | 214 | ul_private_action(tail); |
206 | 215 | ||
207 | } else { | 216 | } else { |
208 | /* Bump user to fill in missing parts */ | 217 | /* Bump user to fill in missing parts */ |
209 | msgout( *tail ? " Won't send empty message. ":" Recipient missing. " ); | 218 | msgout(*tail ? " Won't send empty message. " : " Recipient missing. "); |
210 | } | 219 | } |
211 | } | 220 | } |
212 | 221 | ||
213 | /* handle line entered by user */ | 222 | /* handle line entered by user */ |
214 | void | 223 | void handleline(char *line) { |
215 | handleline (char *line) | ||
216 | { | ||
217 | #ifdef DEBUG | 224 | #ifdef DEBUG |
218 | /* debugging? log users input! */ | 225 | /* debugging? log users input! */ |
219 | fprintf (stderr, "=| %s\n", line); | 226 | fprintf(stderr, "=| %s\n", line); |
220 | #endif | 227 | #endif |
221 | 228 | ||
222 | switch ( line[0] ) | 229 | switch (line[0]) { |
223 | { | ||
224 | case '.': | 230 | case '.': |
225 | switch ( line[1] ) { | 231 | switch (line[1]) { |
226 | case 'm': /* sending a private message? */ | 232 | case 'm': /* sending a private message? */ |
227 | privatemessagetx( line+2 ); | 233 | privatemessagetx(line + 2); |
228 | break; | 234 | break; |
229 | case 'a': /* Do an action */ | 235 | case 'a': /* Do an action */ |
230 | doaction( line+2 ); | 236 | doaction(line + 2); |
231 | break; | 237 | break; |
232 | case '.': | 238 | case '.': |
233 | /* .. on start of line is public */ | 239 | /* .. on start of line is public */ |
234 | if( line[2] != 'm' ) { | 240 | if (line[2] != 'm') { |
235 | output_default( line ); | 241 | output_default(line); |
236 | } else { | 242 | } else { |
237 | /* oopsi, "..m " detected */ | 243 | /* oopsi, "..m " detected */ |
238 | /* dunno what to do */ | 244 | /* dunno what to do */ |
239 | flushout( ); | 245 | flushout(); |
240 | writeout("? You probably misstyped ?"); | 246 | writeout("? You probably misstyped ?"); |
241 | writeout(" "); | 247 | writeout(" "); |
242 | writeout(line ); | 248 | writeout(line); |
243 | showout( ); | 249 | showout(); |
244 | } | ||
245 | break; | ||
246 | case 'o': | ||
247 | case 'O': | ||
248 | dothink( line + 2, line[1] ); | ||
249 | break; | ||
250 | case 'x': | ||
251 | /* inform vchat-client, that the following connection | ||
252 | drop was intentional */ | ||
253 | ownquit = 1; /* fallthrough intended */ | ||
254 | default: | ||
255 | /* generic server command, send to server, show to user */ | ||
256 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_COMMAND), line); | ||
257 | writechan (tmpstr); | ||
258 | vc_sendmessage (line); | ||
259 | break; | ||
260 | } | 250 | } |
261 | break; | 251 | break; |
262 | case '/': | 252 | case 'o': |
263 | line++; | 253 | case 'O': |
264 | commandtable[translatecommand(&line)].handler(line); | 254 | dothink(line + 2, line[1]); |
265 | break; | 255 | break; |
266 | default: | 256 | case 'x': |
267 | output_default( line ); | 257 | /* inform vchat-client, that the following connection |
258 | drop was intentional */ | ||
259 | ownquit = 1; /* fallthrough intended */ | ||
260 | default: | ||
261 | /* generic server command, send to server, show to user */ | ||
262 | snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_COMMAND), line); | ||
263 | writechan(tmpstr); | ||
264 | vc_sendmessage(line); | ||
268 | break; | 265 | break; |
266 | } | ||
267 | break; | ||
268 | case '/': | ||
269 | line++; | ||
270 | commandtable[translatecommand(&line)].handler(line); | ||
271 | break; | ||
272 | default: | ||
273 | output_default(line); | ||
274 | break; | ||
269 | } | 275 | } |
270 | } | 276 | } |
271 | 277 | ||
272 | static void | 278 | static void output_default(char *line) { |
273 | output_default(char *line ) { | 279 | /* prepare for output on display */ |
274 | /* prepare for output on display */ | 280 | snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBMSG), own_nick_get(), line); |
275 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBMSG), own_nick_get(), line); | ||
276 | 281 | ||
277 | /* send original line to server */ | 282 | /* send original line to server */ |
278 | vc_sendmessage (line); | 283 | vc_sendmessage(line); |
279 | 284 | ||
280 | /* output message to channel window */ | 285 | /* output message to channel window */ |
281 | writechan (tmpstr); | 286 | writechan(tmpstr); |
282 | } | 287 | } |
283 | 288 | ||
284 | /* handle a "/user " request */ | 289 | /* handle a "/user " request */ |
285 | static void | 290 | static void command_user(char *tail) { |
286 | command_user(char *tail) | 291 | while (*tail == ' ') |
287 | { | 292 | tail++; |
288 | while( *tail == ' ') tail++; | 293 | if (*tail) { |
289 | if( *tail ) { | 294 | char *out = ul_match_user(tail); |
290 | char * out = ul_match_user( tail); | 295 | if (*out) { |
291 | if( *out ) { | 296 | snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out); |
292 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out); | 297 | } else { |
293 | } else { | 298 | snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), |
294 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), " No user matched that regex. "); | 299 | " No user matched that regex. "); |
295 | } | 300 | } |
296 | } else { | 301 | } else { |
297 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), " Which user? "); | 302 | snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), " Which user? "); |
298 | } | 303 | } |
299 | msgout( tmpstr ); | 304 | msgout(tmpstr); |
300 | } | 305 | } |
301 | 306 | ||
302 | /* handle a "/msg " request */ | 307 | /* handle a "/msg " request */ |
303 | static void | 308 | static void command_pm(char *tail) { privatemessagetx(tail); } |
304 | command_pm (char *tail) | ||
305 | { | ||
306 | privatemessagetx( tail ); | ||
307 | } | ||
308 | 309 | ||
309 | static void | 310 | static void command_format(char *line) { |
310 | command_format(char *line) { | ||
311 | struct stat testexist; | 311 | struct stat testexist; |
312 | char * tildex = NULL; | 312 | char *tildex = NULL; |
313 | 313 | ||
314 | flushout(); | 314 | flushout(); |
315 | while( *line==' ') line++; | 315 | while (*line == ' ') |
316 | if(line) { | 316 | line++; |
317 | tildex = tilde_expand( line ); | 317 | if (line) { |
318 | if(tildex && !stat(tildex, &testexist )) | 318 | tildex = tilde_expand(line); |
319 | if (tildex && !stat(tildex, &testexist)) | ||
319 | loadformats(tildex); | 320 | loadformats(tildex); |
320 | else { | 321 | else { |
321 | #define BUFSIZE 4096 | 322 | #define BUFSIZE 4096 |
322 | char buf[BUFSIZE]; | 323 | char buf[BUFSIZE]; |
323 | snprintf( buf, BUFSIZE, "~/.vchat/sample-%s.fmt", line ); | 324 | snprintf(buf, BUFSIZE, "~/.vchat/sample-%s.fmt", line); |
324 | free(tildex); | 325 | free(tildex); |
325 | tildex = tilde_expand( line ); | 326 | tildex = tilde_expand(line); |
326 | if(tildex && !stat(tildex, &testexist )) | 327 | if (tildex && !stat(tildex, &testexist)) |
327 | loadformats(tildex); | 328 | loadformats(tildex); |
328 | } | 329 | } |
329 | writeout(" Sort of done. "); | 330 | writeout(" Sort of done. "); |
@@ -335,92 +336,87 @@ command_format(char *line) { | |||
335 | } | 336 | } |
336 | 337 | ||
337 | /* handle a help request */ | 338 | /* handle a help request */ |
338 | static void | 339 | static void command_help(char *line) { |
339 | command_help (char *line) { | 340 | flushout(); |
340 | flushout( ); | 341 | while (*line == ' ') |
341 | while( *line==' ') line++; | 342 | line++; |
342 | if( *line ) { /* Get help on command */ | 343 | if (*line) { /* Get help on command */ |
343 | int i; | 344 | int i; |
344 | if( ( i = translatecommand( &line ) ) != COMMAND_NONE ) { | 345 | if ((i = translatecommand(&line)) != COMMAND_NONE) { |
345 | snprintf( tmpstr, TMPSTRSIZE, "Help on command: %s", commandtable[i].name); | 346 | snprintf(tmpstr, TMPSTRSIZE, "Help on command: %s", commandtable[i].name); |
346 | writeout( tmpstr ); | 347 | writeout(tmpstr); |
347 | writeout(" "); | 348 | writeout(" "); |
348 | if( commandtable[i].short_help && !commandtable[i].help ) | 349 | if (commandtable[i].short_help && !commandtable[i].help) |
349 | writeout(commandtable[i].short_help ); | 350 | writeout(commandtable[i].short_help); |
350 | line = commandtable[i].help; | 351 | line = commandtable[i].help; |
351 | if( line ) { | 352 | if (line) { |
352 | while( *line ) { | 353 | while (*line) { |
353 | char *tmp = tmpstr; | 354 | char *tmp = tmpstr; |
354 | while( *line && (*line != '\n') ) | 355 | while (*line && (*line != '\n')) |
355 | *tmp++ = *line++; | 356 | *tmp++ = *line++; |
356 | *tmp = '\0'; if( *line == '\n') line++; | 357 | *tmp = '\0'; |
357 | writeout ( tmpstr ); | 358 | if (*line == '\n') |
358 | } | 359 | line++; |
359 | } | 360 | writeout(tmpstr); |
360 | } else { | 361 | } |
361 | command_help( " " ); | ||
362 | } | ||
363 | } else { /* Get overall help */ | ||
364 | int i; | ||
365 | for( i = 0; commandtable[i].number != COMMAND_NONE; i++ ) { | ||
366 | if( commandtable[i].short_help ) | ||
367 | writeout( commandtable[i].short_help ); | ||
368 | } | 362 | } |
363 | } else { | ||
364 | command_help(" "); | ||
365 | } | ||
366 | } else { /* Get overall help */ | ||
367 | int i; | ||
368 | for (i = 0; commandtable[i].number != COMMAND_NONE; i++) { | ||
369 | if (commandtable[i].short_help) | ||
370 | writeout(commandtable[i].short_help); | ||
371 | } | ||
369 | } | 372 | } |
370 | showout(); | 373 | showout(); |
371 | } | 374 | } |
372 | 375 | ||
373 | /* handle an unknown command */ | 376 | /* handle an unknown command */ |
374 | static void | 377 | static void command_none(char *line) { |
375 | command_none(char *line) { | 378 | snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); |
376 | snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); | 379 | msgout(tmpstr); |
377 | msgout(tmpstr); | ||
378 | } | 380 | } |
379 | 381 | ||
380 | /* handle a "/flt " request */ | 382 | /* handle a "/flt " request */ |
381 | static void | 383 | static void command_flt(char *tail) { |
382 | command_flt(char *tail){ | ||
383 | char colour; | 384 | char colour; |
384 | while(*tail==' ') tail++; | 385 | while (*tail == ' ') |
386 | tail++; | ||
385 | colour = *tail++; | 387 | colour = *tail++; |
386 | while( colour && *tail == ' ') tail++; | 388 | while (colour && *tail == ' ') |
387 | if( colour && *tail) { | 389 | tail++; |
388 | addfilter( colour, tail); | 390 | if (colour && *tail) { |
391 | addfilter(colour, tail); | ||
389 | } | 392 | } |
390 | } | 393 | } |
391 | 394 | ||
392 | /* handle a "/clflt " request */ | 395 | /* handle a "/clflt " request */ |
393 | static void | 396 | static void command_clflt(char *tail) { |
394 | command_clflt (char *tail) { | 397 | while (*tail == ' ') |
395 | while( *tail == ' ') tail++; | 398 | tail++; |
396 | clearfilters( *tail ); | 399 | clearfilters(*tail); |
397 | } | 400 | } |
398 | 401 | ||
399 | /* handle a "/rmflt " request */ | 402 | /* handle a "/rmflt " request */ |
400 | static void | 403 | static void command_rmflt(char *tail) { |
401 | command_rmflt (char *tail) { | 404 | while (*tail == ' ') |
402 | while( *tail == ' ') tail++; | 405 | tail++; |
403 | removefilter( tail ); | 406 | removefilter(tail); |
404 | } | 407 | } |
405 | 408 | ||
406 | /* list filters */ | 409 | /* list filters */ |
407 | static void | 410 | static void command_lsflt(char *tail) { |
408 | command_lsflt (char *tail) { | ||
409 | (void)tail; | 411 | (void)tail; |
410 | listfilters(); | 412 | listfilters(); |
411 | } | 413 | } |
412 | 414 | ||
413 | /* handle a "/me " action */ | 415 | /* handle a "/me " action */ |
414 | static void | 416 | static void command_action(char *tail) { doaction(tail); } |
415 | command_action(char *tail) | ||
416 | { | ||
417 | doaction(tail); | ||
418 | } | ||
419 | 417 | ||
420 | /* handle a "/reconnect" request */ | 418 | /* handle a "/reconnect" request */ |
421 | static void | 419 | static void command_reconnect(char *tail) { |
422 | command_reconnect(char *tail) | ||
423 | { | ||
424 | (void)tail; | 420 | (void)tail; |
425 | status = 0; | 421 | status = 0; |
426 | wantreconnect = 1; | 422 | wantreconnect = 1; |
@@ -428,15 +424,13 @@ command_reconnect(char *tail) | |||
428 | } | 424 | } |
429 | 425 | ||
430 | /* handle a "/quit " exit */ | 426 | /* handle a "/quit " exit */ |
431 | static void | 427 | static void command_quit(char *tail) { |
432 | command_quit(char *tail) | ||
433 | { | ||
434 | /* send users message to server */ | 428 | /* send users message to server */ |
435 | snprintf (tmpstr, TMPSTRSIZE, ".x %s", tail); | 429 | snprintf(tmpstr, TMPSTRSIZE, ".x %s", tail); |
436 | vc_sendmessage (tmpstr); | 430 | vc_sendmessage(tmpstr); |
437 | 431 | ||
438 | /* show action in channel window */ | 432 | /* show action in channel window */ |
439 | writechan (tmpstr); | 433 | writechan(tmpstr); |
440 | 434 | ||
441 | /* Inform vchat-client, that the closing connection | 435 | /* Inform vchat-client, that the closing connection |
442 | following is intended */ | 436 | following is intended */ |
@@ -445,42 +439,35 @@ command_quit(char *tail) | |||
445 | } | 439 | } |
446 | 440 | ||
447 | /* print out version */ | 441 | /* print out version */ |
448 | void | 442 | void command_version(char *tail) { |
449 | command_version(char *tail) | ||
450 | { | ||
451 | (void)tail; | 443 | (void)tail; |
452 | /* output internal versions of all modules */ | 444 | /* output internal versions of all modules */ |
453 | flushout(); | 445 | flushout(); |
454 | writeout (vchat_cl_version); | 446 | writeout(vchat_cl_version); |
455 | writeout (vchat_ui_version); | 447 | writeout(vchat_ui_version); |
456 | writeout (vchat_io_version); | 448 | writeout(vchat_io_version); |
457 | writeout (vchat_us_version); | 449 | writeout(vchat_us_version); |
458 | writeout (vchat_cm_version); | 450 | writeout(vchat_cm_version); |
459 | writeout (vchat_tls_version); | 451 | writeout(vchat_tls_version); |
460 | writeout (vchat_tls_version_external); | 452 | writeout(vchat_tls_version_external); |
461 | showout(); | 453 | showout(); |
462 | } | 454 | } |
463 | 455 | ||
464 | /* start or end a query */ | 456 | /* start or end a query */ |
465 | void | 457 | void command_query(char *tail) { |
466 | command_query(char *tail) | ||
467 | { | ||
468 | char *msg; | 458 | char *msg; |
469 | while( *tail == ' ') tail++; | 459 | while (*tail == ' ') |
460 | tail++; | ||
470 | 461 | ||
471 | // Check, if a message is to be sent in first query | 462 | // Check, if a message is to be sent in first query |
472 | // Note: this is safe, since readline chops trailing spaces | 463 | // Note: this is safe, since readline chops trailing spaces |
473 | if((msg = strchr(tail, ' '))) { | 464 | if ((msg = strchr(tail, ' '))) { |
474 | privatemessagetx( tail ); | 465 | privatemessagetx(tail); |
475 | *msg = 0; | 466 | *msg = 0; |
476 | } | 467 | } |
477 | 468 | ||
478 | // Do the ui stuff for query | 469 | // Do the ui stuff for query |
479 | handlequery( tail ); | 470 | handlequery(tail); |
480 | } | 471 | } |
481 | 472 | ||
482 | void | 473 | void command_dict(char *tail) { ul_add_to_dict(tail); } |
483 | command_dict(char *tail) | ||
484 | { | ||
485 | ul_add_to_dict(tail); | ||
486 | } | ||