summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xvchat-commands.c29
-rwxr-xr-xvchat-help.h2
-rwxr-xr-xvchat-user.c38
-rw-r--r--vchat-user.h3
4 files changed, 59 insertions, 13 deletions
diff --git a/vchat-commands.c b/vchat-commands.c
index e4f1d99..2c3d68b 100755
--- a/vchat-commands.c
+++ b/vchat-commands.c
@@ -48,6 +48,7 @@ COMMAND_FORMAT,
48COMMAND_KEYS, 48COMMAND_KEYS,
49COMMAND_QUIT, 49COMMAND_QUIT,
50COMMAND_USER, 50COMMAND_USER,
51COMMAND_DICT,
51COMMAND_FLT, 52COMMAND_FLT,
52COMMAND_PM, 53COMMAND_PM,
53COMMAND_ACTION, 54COMMAND_ACTION,
@@ -73,6 +74,7 @@ static void command_rmflt ( char *tail);
73static void command_none ( char *line); 74static void command_none ( char *line);
74static void command_query ( char *tail); 75static void command_query ( char *tail);
75static void command_reconnect ( char *tail); 76static void command_reconnect ( char *tail);
77static void command_dict ( char *tail);
76 78
77static void output_default ( char *tail); 79static void output_default ( char *tail);
78 80
@@ -92,6 +94,7 @@ commandtable[] = {
92{ COMMAND_QUERY, "QUERY", 5, command_query, NULL, NULL }, 94{ COMMAND_QUERY, "QUERY", 5, command_query, NULL, NULL },
93{ COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT }, 95{ COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT },
94{ COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER }, 96{ COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER },
97{ COMMAND_DICT, "DICT", 4, command_dict, SHORT_HELPTEXT_DICT, LONG_HELPTEXT_DICT },
95{ COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT }, 98{ COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT },
96{ COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG }, 99{ COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG },
97{ COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME }, 100{ COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME },
@@ -131,7 +134,7 @@ translatecommand( char **cmd)
131 /* ... whose start may be affected by abbrevation */ 134 /* ... whose start may be affected by abbrevation */
132 if( commandtable[result].number != COMMAND_NONE ) 135 if( commandtable[result].number != COMMAND_NONE )
133 (*cmd) -= cut; 136 (*cmd) -= cut;
134 137
135 return result; 138 return result;
136} 139}
137 140
@@ -140,11 +143,11 @@ static void
140dothink( char *tail, char nice ) 143dothink( char *tail, char nice )
141{ 144{
142 while( *tail == ' ' ) tail++; 145 while( *tail == ' ' ) tail++;
143 146
144 /* send users message to server */ 147 /* send users message to server */
145 snprintf (tmpstr, TMPSTRSIZE, ".%c %s", nice, tail); 148 snprintf (tmpstr, TMPSTRSIZE, ".%c %s", nice, tail);
146 networkoutput (tmpstr); 149 networkoutput (tmpstr);
147 150
148 /* show action in channel window */ 151 /* show action in channel window */
149 snprintf (tmpstr, TMPSTRSIZE, nice == 'O' ? getformatstr(FS_TXPUBNTHOUGHT) : getformatstr(FS_TXPUBTHOUGHT), tail); 152 snprintf (tmpstr, TMPSTRSIZE, nice == 'O' ? getformatstr(FS_TXPUBNTHOUGHT) : getformatstr(FS_TXPUBTHOUGHT), tail);
150 writechan (tmpstr); 153 writechan (tmpstr);
@@ -261,7 +264,7 @@ handleline (char *line)
261 break; 264 break;
262 default: 265 default:
263 output_default( line ); 266 output_default( line );
264 break; 267 break;
265 } 268 }
266} 269}
267 270
@@ -276,7 +279,7 @@ output_default(char *line ) {
276 /* output message to channel window */ 279 /* output message to channel window */
277 writechan (tmpstr); 280 writechan (tmpstr);
278} 281}
279 282
280/* handle a "/user " request */ 283/* handle a "/user " request */
281static void 284static void
282command_user(char *tail) 285command_user(char *tail)
@@ -372,7 +375,7 @@ command_none(char *line) {
372 snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); 375 snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line);
373 msgout(tmpstr); 376 msgout(tmpstr);
374} 377}
375 378
376/* handle a "/flt " request */ 379/* handle a "/flt " request */
377static void 380static void
378command_flt(char *tail){ 381command_flt(char *tail){
@@ -383,7 +386,7 @@ command_flt(char *tail){
383 if( colour && *tail) { 386 if( colour && *tail) {
384 addfilter( colour, tail); 387 addfilter( colour, tail);
385 } 388 }
386} 389}
387 390
388/* handle a "/clflt " request */ 391/* handle a "/clflt " request */
389static void 392static void
@@ -391,20 +394,20 @@ command_clflt (char *tail) {
391 while( *tail == ' ') tail++; 394 while( *tail == ' ') tail++;
392 clearfilters( *tail ); 395 clearfilters( *tail );
393} 396}
394 397
395/* handle a "/rmflt " request */ 398/* handle a "/rmflt " request */
396static void 399static void
397command_rmflt (char *tail) { 400command_rmflt (char *tail) {
398 while( *tail == ' ') tail++; 401 while( *tail == ' ') tail++;
399 removefilter( tail ); 402 removefilter( tail );
400} 403}
401 404
402/* list filters */ 405/* list filters */
403static void 406static void
404command_lsflt (char *tail) { 407command_lsflt (char *tail) {
405 listfilters(); 408 listfilters();
406} 409}
407 410
408/* handle a "/me " action */ 411/* handle a "/me " action */
409static void 412static void
410command_action(char *tail) 413command_action(char *tail)
@@ -469,3 +472,9 @@ command_query(char *tail)
469 // Do the ui stuff for query 472 // Do the ui stuff for query
470 handlequery( tail ); 473 handlequery( tail );
471} 474}
475
476void
477command_dict(char *tail)
478{
479 ul_add_to_dict(tail);
480}
diff --git a/vchat-help.h b/vchat-help.h
index aec0fcf..a7964fd 100755
--- a/vchat-help.h
+++ b/vchat-help.h
@@ -55,6 +55,8 @@
55#define LONG_HELPTEXT_QUIT NULL 55#define LONG_HELPTEXT_QUIT NULL
56#define SHORT_HELPTEXT_USER "/USER REGEX Lists all users matching regex REGEX" 56#define SHORT_HELPTEXT_USER "/USER REGEX Lists all users matching regex REGEX"
57#define LONG_HELPTEXT_USER NULL 57#define LONG_HELPTEXT_USER NULL
58#define SHORT_HELPTEXT_DICT "/DICT ITEM [...] Add space separated items to the user completion dict"
59#define LONG_HELPTEXT_DICT NULL
58#define SHORT_HELPTEXT_MSG "/M[SG] USER MESSAGE Send private message to user USER" 60#define SHORT_HELPTEXT_MSG "/M[SG] USER MESSAGE Send private message to user USER"
59#define LONG_HELPTEXT_MSG NULL 61#define LONG_HELPTEXT_MSG NULL
60#define SHORT_HELPTEXT_ME "/ME ACTION Let the user do an action" 62#define SHORT_HELPTEXT_ME "/ME ACTION Let the user do an action"
diff --git a/vchat-user.c b/vchat-user.c
index ce36220..d7261d6 100755
--- a/vchat-user.c
+++ b/vchat-user.c
@@ -30,6 +30,9 @@ static char *g_nick; //< own nick
30static int g_channel; //< own channel 30static int g_channel; //< own channel
31unsigned int ul_case_first = 0; 31unsigned int ul_case_first = 0;
32 32
33static char **g_dict;
34static size_t g_dict_len;
35
33static int ul_nick_lookup( const char *nick, int *exact_match ) { 36static int ul_nick_lookup( const char *nick, int *exact_match ) {
34 int i; 37 int i;
35 38
@@ -206,6 +209,15 @@ void ul_public_action(char *name) {
206 g_users[base].last_public = ul_now(); 209 g_users[base].last_public = ul_now();
207} 210}
208 211
212void ul_add_to_dict(char *dict_items) {
213 char *i;
214 for(i=strtok(dict_items," ");i;i=strtok(0," ")) {
215 g_dict = realloc( g_dict, sizeof(char*) * ( 1 + g_dict_len ) );
216 if( !g_dict ) exit(1);
217 g_dict[g_dict_len++] = strdup(i);
218 }
219}
220
209/* Finding users ul_finduser? */ 221/* Finding users ul_finduser? */
210char * ul_match_user(char *regex) { 222char * ul_match_user(char *regex) {
211 char *dest = tmpstr; 223 char *dest = tmpstr;
@@ -327,15 +339,21 @@ static int ul_compare_middle_case( const void *a, const void *b ) {
327/* Nick completion function for readline */ 339/* Nick completion function for readline */
328char **ul_complete_user(char *text, int start, int end ) { 340char **ul_complete_user(char *text, int start, int end ) {
329 char **result = 0; 341 char **result = 0;
330 int i, result_count = 0; 342 int i, result_count = 0, dict_result_count = 0;
331 343
332 /* Never want readline to complete filenames */ 344 /* Never want readline to complete filenames */
333 rl_attempted_completion_over = 1; 345 rl_attempted_completion_over = 1;
334 346
347 /* Check for amount of custom dict matches */
348 if( end && ( start != end ) )
349 for( i=0; i<g_dict_len; ++i )
350 if( !strncasecmp( g_dict[i], text+start, end-start ) )
351 ++dict_result_count;
352
335 /* Prepare return array ... of max g_users_count (char*) 353 /* Prepare return array ... of max g_users_count (char*)
336 Plus least common prefix in [0] and null terminator 354 Plus least common prefix in [0] and null terminator
337 */ 355 */
338 result = malloc( sizeof(char*) * ( 2 + g_users_count ) ); 356 result = malloc( sizeof(char*) * ( 2 + g_users_count + dict_result_count ) );
339 if( !result ) return 0; 357 if( !result ) return 0;
340 358
341 if( start == 0 && end == 0 ) { 359 if( start == 0 && end == 0 ) {
@@ -365,6 +383,14 @@ char **ul_complete_user(char *text, int start, int end ) {
365 snprintf( tmpstr, TMPSTRSIZE, "%s:", g_users[i].nick ); 383 snprintf( tmpstr, TMPSTRSIZE, "%s:", g_users[i].nick );
366 result[++result_count] = strdup(tmpstr); 384 result[++result_count] = strdup(tmpstr);
367 } 385 }
386
387 /* Copy matches from personal dict to the end */
388 for( i=0; i<g_dict_len; ++i )
389 if( !strncasecmp( g_dict[i], tmpstr, end-start ) ) {
390 snprintf( tmpstr, TMPSTRSIZE, "%s:", g_dict[i] );
391 result[++result_count] = strdup(tmpstr);
392 }
393
368 /* Copy common prefix */ 394 /* Copy common prefix */
369 if( result_count ) result[0] = strndup(text, end); 395 if( result_count ) result[0] = strndup(text, end);
370 } else if( start != end ) { 396 } else if( start != end ) {
@@ -380,6 +406,12 @@ char **ul_complete_user(char *text, int start, int end ) {
380 for( i=0; i<g_users_count; ++i ) 406 for( i=0; i<g_users_count; ++i )
381 if( !strncasecmp( g_users[i].nick, tmpstr, end - start ) ) 407 if( !strncasecmp( g_users[i].nick, tmpstr, end - start ) )
382 result[++result_count] = strdup(g_users[i].nick); 408 result[++result_count] = strdup(g_users[i].nick);
409
410 /* Copy matches from personal dict to the end */
411 for( i=0; i<g_dict_len; ++i )
412 if( !strncasecmp( g_dict[i], tmpstr, end-start ) )
413 result[++result_count] = strdup(g_dict[i]);
414
383 /* Copy common prefix */ 415 /* Copy common prefix */
384 if( result_count ) result[0] = strndup(text, end - start); 416 if( result_count ) result[0] = strndup(text, end - start);
385 } /* else: completion of an empty word in the middle yields nothing */ 417 } /* else: completion of an empty word in the middle yields nothing */
diff --git a/vchat-user.h b/vchat-user.h
index 41b51da..7ce004e 100644
--- a/vchat-user.h
+++ b/vchat-user.h
@@ -38,4 +38,7 @@ char *ul_match_user(char *regex);
38/* Nick completion function for readline */ 38/* Nick completion function for readline */
39char **ul_complete_user(char *text, int start, int end ); 39char **ul_complete_user(char *text, int start, int end );
40 40
41/* Setting up a user dict for custum completion */
42void ul_add_to_dict(char *dict_items);
43
41#endif 44#endif