From b6fdcbeb3ea50e0051749dc552ffb7a736d3c8e1 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 5 Jan 2014 21:23:39 +0100 Subject: Dict handling to allow custom completion from user dictionary --- vchat-user.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'vchat-user.c') 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 static int g_channel; //< own channel unsigned int ul_case_first = 0; +static char **g_dict; +static size_t g_dict_len; + static int ul_nick_lookup( const char *nick, int *exact_match ) { int i; @@ -206,6 +209,15 @@ void ul_public_action(char *name) { g_users[base].last_public = ul_now(); } +void ul_add_to_dict(char *dict_items) { + char *i; + for(i=strtok(dict_items," ");i;i=strtok(0," ")) { + g_dict = realloc( g_dict, sizeof(char*) * ( 1 + g_dict_len ) ); + if( !g_dict ) exit(1); + g_dict[g_dict_len++] = strdup(i); + } +} + /* Finding users ul_finduser? */ char * ul_match_user(char *regex) { char *dest = tmpstr; @@ -327,15 +339,21 @@ static int ul_compare_middle_case( const void *a, const void *b ) { /* Nick completion function for readline */ char **ul_complete_user(char *text, int start, int end ) { char **result = 0; - int i, result_count = 0; + int i, result_count = 0, dict_result_count = 0; /* Never want readline to complete filenames */ rl_attempted_completion_over = 1; + /* Check for amount of custom dict matches */ + if( end && ( start != end ) ) + for( i=0; i