diff options
author | erdgeist <> | 2006-01-26 18:40:30 +0000 |
---|---|---|
committer | erdgeist <> | 2006-01-26 18:40:30 +0000 |
commit | 57689e698230030803c872072a03329fdd4fecc6 (patch) | |
tree | b4f8671dbe04741be93091e99eb3c6aa81b9bebd /vchat-commands.c | |
parent | 4413fb15bec35744c06ac3cfce2ae2bfa6953ae1 (diff) |
unsigned char tidy up, query mode
Diffstat (limited to 'vchat-commands.c')
-rwxr-xr-x | vchat-commands.c | 106 |
1 files changed, 52 insertions, 54 deletions
diff --git a/vchat-commands.c b/vchat-commands.c index 5f54733..5dc7b4f 100755 --- a/vchat-commands.c +++ b/vchat-commands.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include "vchat-help.h" | 25 | #include "vchat-help.h" |
26 | 26 | ||
27 | /* version of this module */ | 27 | /* version of this module */ |
28 | unsigned char *vchat_cm_version = "$Id$"; | 28 | char *vchat_cm_version = "$Id$"; |
29 | 29 | ||
30 | /* our "/command " table */ | 30 | /* our "/command " table */ |
31 | enum { | 31 | enum { |
@@ -38,29 +38,30 @@ COMMAND_HELP, | |||
38 | COMMAND_KEYS, | 38 | COMMAND_KEYS, |
39 | COMMAND_QUIT, | 39 | COMMAND_QUIT, |
40 | COMMAND_USER, | 40 | COMMAND_USER, |
41 | COMMAND_LOG, | ||
42 | COMMAND_FLT, | 41 | COMMAND_FLT, |
43 | COMMAND_PM, | 42 | COMMAND_PM, |
44 | COMMAND_ACTION, | 43 | COMMAND_ACTION, |
45 | COMMAND_PMSHORT, | 44 | COMMAND_PMSHORT, |
45 | COMMAND_QUERY, | ||
46 | COMMAND_QUITSHORT, | ||
46 | COMMAND_PLAIN, | 47 | COMMAND_PLAIN, |
47 | COMMAND_NONE | 48 | COMMAND_NONE |
48 | }; | 49 | }; |
49 | 50 | ||
50 | static void command_quit ( unsigned char *tail); | 51 | static void command_quit ( char *tail); |
51 | static void command_user ( unsigned char *tail); | 52 | static void command_user ( char *tail); |
52 | static void command_pm ( unsigned char *tail); | 53 | static void command_pm ( char *tail); |
53 | static void command_action ( unsigned char *tail); | 54 | static void command_action ( char *tail); |
54 | static void command_help ( unsigned char *tail); | 55 | static void command_help ( char *tail); |
55 | static void command_flt ( unsigned char *tail); | 56 | static void command_flt ( char *tail); |
56 | static void command_lsflt ( unsigned char *tail); | 57 | static void command_lsflt ( char *tail); |
57 | static void command_clflt ( unsigned char *tail); | 58 | static void command_clflt ( char *tail); |
58 | static void command_rmflt ( unsigned char *tail); | 59 | static void command_rmflt ( char *tail); |
59 | void command_version ( unsigned char *tail); | 60 | void command_version ( char *tail); |
60 | static void command_none ( unsigned char *line); | 61 | static void command_none ( char *line); |
61 | static void command_log ( unsigned char *tail); | 62 | static void command_query ( char *tail); |
62 | 63 | ||
63 | static void output_default ( unsigned char *tail); | 64 | static void output_default ( char *tail); |
64 | 65 | ||
65 | /* commandentry defined in vchat.h */ | 66 | /* commandentry defined in vchat.h */ |
66 | 67 | ||
@@ -73,20 +74,21 @@ commandtable[] = { | |||
73 | { COMMAND_HELP, "HELP", 4, command_help, SHORT_HELPTEXT_HELP, LONG_HELPTEXT_HELP }, | 74 | { COMMAND_HELP, "HELP", 4, command_help, SHORT_HELPTEXT_HELP, LONG_HELPTEXT_HELP }, |
74 | { COMMAND_FILTERS, "FILTERS", 7, command_help, SHORT_HELPTEXT_FILTERS, LONG_HELPTEXT_FILTERS }, | 75 | { COMMAND_FILTERS, "FILTERS", 7, command_help, SHORT_HELPTEXT_FILTERS, LONG_HELPTEXT_FILTERS }, |
75 | { COMMAND_KEYS, "KEYS", 4, command_help, SHORT_HELPTEXT_KEYS, LONG_HELPTEXT_KEYS }, | 76 | { COMMAND_KEYS, "KEYS", 4, command_help, SHORT_HELPTEXT_KEYS, LONG_HELPTEXT_KEYS }, |
77 | { COMMAND_QUERY, "QUERY", 5, command_query, NULL, NULL }, | ||
76 | { COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT }, | 78 | { COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT }, |
77 | { COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER }, | 79 | { COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER }, |
78 | { COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT }, | 80 | { COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT }, |
79 | { COMMAND_LOG, "LOG", 3, command_log, NULL, NULL }, | ||
80 | { COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG }, | 81 | { COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG }, |
81 | { COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME }, | 82 | { COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME }, |
82 | { COMMAND_PMSHORT, "M", 1, command_pm, NULL, SHORT_HELPTEXT_MSG }, | 83 | { COMMAND_PMSHORT, "M", 1, command_pm, NULL, SHORT_HELPTEXT_MSG }, |
84 | { COMMAND_QUITSHORT,"Q", 1, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT }, | ||
83 | { COMMAND_PLAIN, "/", 1, output_default, NULL, NULL }, | 85 | { COMMAND_PLAIN, "/", 1, output_default, NULL, NULL }, |
84 | { COMMAND_NONE, "", 0, command_none, NULL, NULL } | 86 | { COMMAND_NONE, "", 0, command_none, NULL, NULL } |
85 | }; | 87 | }; |
86 | 88 | ||
87 | /* parse "/command" */ | 89 | /* parse "/command" */ |
88 | static int | 90 | static int |
89 | translatecommand( unsigned char **cmd) | 91 | translatecommand( char **cmd) |
90 | { | 92 | { |
91 | int result; | 93 | int result; |
92 | int cut = 0; | 94 | int cut = 0; |
@@ -120,7 +122,7 @@ translatecommand( unsigned char **cmd) | |||
120 | 122 | ||
121 | /* handle thought */ | 123 | /* handle thought */ |
122 | static void | 124 | static void |
123 | dothink( unsigned char *tail, char nice ) | 125 | dothink( char *tail, char nice ) |
124 | { | 126 | { |
125 | while( *tail == ' ' ) tail++; | 127 | while( *tail == ' ' ) tail++; |
126 | 128 | ||
@@ -136,7 +138,7 @@ dothink( unsigned char *tail, char nice ) | |||
136 | 138 | ||
137 | /* handle action */ | 139 | /* handle action */ |
138 | static void | 140 | static void |
139 | doaction( unsigned char *tail ) | 141 | doaction( char *tail ) |
140 | { | 142 | { |
141 | while( *tail == ' ' ) tail++; | 143 | while( *tail == ' ' ) tail++; |
142 | 144 | ||
@@ -156,8 +158,8 @@ doaction( unsigned char *tail ) | |||
156 | 158 | ||
157 | /* handle private message outgoing */ | 159 | /* handle private message outgoing */ |
158 | static void | 160 | static void |
159 | privatemessagetx ( unsigned char *tail ) { | 161 | privatemessagetx ( char *tail ) { |
160 | unsigned char *mesg; | 162 | char *mesg; |
161 | 163 | ||
162 | /* find nick */ | 164 | /* find nick */ |
163 | while( *tail==' ') tail++; | 165 | while( *tail==' ') tail++; |
@@ -191,7 +193,7 @@ privatemessagetx ( unsigned char *tail ) { | |||
191 | 193 | ||
192 | /* handle line entered by user */ | 194 | /* handle line entered by user */ |
193 | void | 195 | void |
194 | handleline (unsigned char *line) | 196 | handleline (char *line) |
195 | { | 197 | { |
196 | #ifdef DEBUG | 198 | #ifdef DEBUG |
197 | /* debugging? log users input! */ | 199 | /* debugging? log users input! */ |
@@ -245,7 +247,7 @@ handleline (unsigned char *line) | |||
245 | } | 247 | } |
246 | 248 | ||
247 | static void | 249 | static void |
248 | output_default( unsigned char *line ) { | 250 | output_default(char *line ) { |
249 | /* prepare for output on display */ | 251 | /* prepare for output on display */ |
250 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBMSG), nick, line); | 252 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBMSG), nick, line); |
251 | 253 | ||
@@ -258,11 +260,11 @@ output_default( unsigned char *line ) { | |||
258 | 260 | ||
259 | /* handle a "/user " request */ | 261 | /* handle a "/user " request */ |
260 | static void | 262 | static void |
261 | command_user( unsigned char *tail) | 263 | command_user(char *tail) |
262 | { | 264 | { |
263 | while( *tail == ' ') tail++; | 265 | while( *tail == ' ') tail++; |
264 | if( *tail ) { | 266 | if( *tail ) { |
265 | unsigned char * out = ul_matchuser( tail); | 267 | char * out = ul_matchuser( tail); |
266 | if( *out ) { | 268 | if( *out ) { |
267 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out); | 269 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out); |
268 | } else { | 270 | } else { |
@@ -276,14 +278,14 @@ command_user( unsigned char *tail) | |||
276 | 278 | ||
277 | /* handle a "/msg " request */ | 279 | /* handle a "/msg " request */ |
278 | static void | 280 | static void |
279 | command_pm (unsigned char *tail) | 281 | command_pm (char *tail) |
280 | { | 282 | { |
281 | privatemessagetx( tail ); | 283 | privatemessagetx( tail ); |
282 | } | 284 | } |
283 | 285 | ||
284 | /* handle a help request */ | 286 | /* handle a help request */ |
285 | static void | 287 | static void |
286 | command_help (unsigned char *line) { | 288 | command_help (char *line) { |
287 | flushout( ); | 289 | flushout( ); |
288 | while( *line==' ') line++; | 290 | while( *line==' ') line++; |
289 | if( *line ) { /* Get help on command */ | 291 | if( *line ) { /* Get help on command */ |
@@ -297,7 +299,7 @@ command_help (unsigned char *line) { | |||
297 | line = commandtable[i].help; | 299 | line = commandtable[i].help; |
298 | if( line ) { | 300 | if( line ) { |
299 | while( *line ) { | 301 | while( *line ) { |
300 | unsigned char *tmp = tmpstr; | 302 | char *tmp = tmpstr; |
301 | while( *line && (*line != '\n') ) | 303 | while( *line && (*line != '\n') ) |
302 | *tmp++ = *line++; | 304 | *tmp++ = *line++; |
303 | *tmp = '\0'; if( *line == '\n') line++; | 305 | *tmp = '\0'; if( *line == '\n') line++; |
@@ -319,15 +321,15 @@ command_help (unsigned char *line) { | |||
319 | 321 | ||
320 | /* handle an unknown command */ | 322 | /* handle an unknown command */ |
321 | static void | 323 | static void |
322 | command_none( unsigned char *line) { | 324 | command_none(char *line) { |
323 | snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); | 325 | snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); |
324 | msgout(tmpstr); | 326 | msgout(tmpstr); |
325 | } | 327 | } |
326 | 328 | ||
327 | /* handle a "/flt " request */ | 329 | /* handle a "/flt " request */ |
328 | static void | 330 | static void |
329 | command_flt( unsigned char *tail){ | 331 | command_flt(char *tail){ |
330 | unsigned char colour; | 332 | char colour; |
331 | while(*tail==' ') tail++; | 333 | while(*tail==' ') tail++; |
332 | colour = *tail++; | 334 | colour = *tail++; |
333 | while( colour && *tail == ' ') tail++; | 335 | while( colour && *tail == ' ') tail++; |
@@ -338,34 +340,34 @@ command_flt( unsigned char *tail){ | |||
338 | 340 | ||
339 | /* handle a "/clflt " request */ | 341 | /* handle a "/clflt " request */ |
340 | static void | 342 | static void |
341 | command_clflt ( unsigned char *tail) { | 343 | command_clflt (char *tail) { |
342 | while( *tail == ' ') tail++; | 344 | while( *tail == ' ') tail++; |
343 | clearfilters( *tail ); | 345 | clearfilters( *tail ); |
344 | } | 346 | } |
345 | 347 | ||
346 | /* handle a "/rmflt " request */ | 348 | /* handle a "/rmflt " request */ |
347 | static void | 349 | static void |
348 | command_rmflt ( unsigned char *tail) { | 350 | command_rmflt (char *tail) { |
349 | while( *tail == ' ') tail++; | 351 | while( *tail == ' ') tail++; |
350 | removefilter( tail ); | 352 | removefilter( tail ); |
351 | } | 353 | } |
352 | 354 | ||
353 | /* list filters */ | 355 | /* list filters */ |
354 | static void | 356 | static void |
355 | command_lsflt ( unsigned char *tail) { | 357 | command_lsflt (char *tail) { |
356 | listfilters(); | 358 | listfilters(); |
357 | } | 359 | } |
358 | 360 | ||
359 | /* handle a "/me " action */ | 361 | /* handle a "/me " action */ |
360 | static void | 362 | static void |
361 | command_action( unsigned char *tail) | 363 | command_action(char *tail) |
362 | { | 364 | { |
363 | doaction( tail); | 365 | doaction( tail); |
364 | } | 366 | } |
365 | 367 | ||
366 | /* handle a "/quit " exit */ | 368 | /* handle a "/quit " exit */ |
367 | static void | 369 | static void |
368 | command_quit ( unsigned char *tail) | 370 | command_quit(char *tail) |
369 | { | 371 | { |
370 | /* send users message to server */ | 372 | /* send users message to server */ |
371 | snprintf (tmpstr, TMPSTRSIZE, ".x %s", tail); | 373 | snprintf (tmpstr, TMPSTRSIZE, ".x %s", tail); |
@@ -377,7 +379,7 @@ command_quit ( unsigned char *tail) | |||
377 | 379 | ||
378 | /* print out version */ | 380 | /* print out version */ |
379 | void | 381 | void |
380 | command_version( unsigned char *tail) | 382 | command_version(char *tail) |
381 | { | 383 | { |
382 | /* output internal versions of all modules */ | 384 | /* output internal versions of all modules */ |
383 | flushout(); | 385 | flushout(); |
@@ -389,24 +391,20 @@ command_version( unsigned char *tail) | |||
389 | showout(); | 391 | showout(); |
390 | } | 392 | } |
391 | 393 | ||
392 | /* Undocumented feature */ | 394 | /* start or end a query */ |
393 | void | 395 | void |
394 | command_log ( unsigned char *tail) | 396 | command_query(char *tail) |
395 | { | 397 | { |
396 | /* log to file */ | 398 | char *msg; |
397 | FILE *logfile = NULL; | 399 | while( *tail == ' ') tail++; |
398 | while( *tail == ' ' ) | 400 | |
399 | tail++; | 401 | // Check, if a message is to be sent in first query |
400 | if( (logfile = fopen( tail, "w")) ) { | 402 | // Note: this is safe, since readline chops trailing spaces |
401 | if( *tail == '_' ) { | 403 | if((msg = strchr(tail, ' '))) { |
402 | writelog_i(logfile); | 404 | privatemessagetx( tail ); |
403 | } else { | 405 | *msg = 0; |
404 | writelog(logfile); | ||
405 | } | ||
406 | fclose( logfile ); | ||
407 | msgout(" Log written. "); | ||
408 | } else { | ||
409 | snprintf(tmpstr, TMPSTRSIZE, " Can't open file: %s ", tail); | ||
410 | msgout(tmpstr); | ||
411 | } | 406 | } |
407 | |||
408 | // Do the ui stuff for query | ||
409 | handlequery( tail ); | ||
412 | } | 410 | } |