summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2012-02-27 00:30:43 +0000
committererdgeist <>2012-02-27 00:30:43 +0000
commitdc8b35add17157f49e8183765e721f3a295348a0 (patch)
tree4e4c23ad06e78ee509b6d8004d6601279ab02397
parentbbc76bdf080f17d8d55a8bfb2c8170bbcdf48739 (diff)
Make user matching sort alphabetically and obey case settings
-rwxr-xr-xvchat-user.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/vchat-user.c b/vchat-user.c
index 45b6b05..9450fbe 100755
--- a/vchat-user.c
+++ b/vchat-user.c
@@ -293,9 +293,33 @@ static int ul_compare_begin_of_line_case( const void *a, const void *b ) {
293 return 1; 293 return 1;
294} 294}
295 295
296static int ul_compare_middle( const void *a, const void *b ) { 296static int ul_compare_middle_ncase( const void *a, const void *b ) {
297 const user *_a = (const user *)a, *_b = (const user *)b; 297 const user *_a = (const user *)a, *_b = (const user *)b;
298 return strcasecmp( _b->nick, _a->nick ); 298
299 /* Ensure that own nick appears last in list */
300 if( _a->flags & UL_ME ) return 1;
301 if( _b->flags & UL_ME ) return -1;
302
303 return strcasecmp( _a->nick, _b->nick );
304}
305
306static int ul_compare_middle_case( const void *a, const void *b ) {
307 const user *_a = (const user *)a, *_b = (const user *)b;
308
309 /* Ensure that own nick appears last in list */
310 if( _a->flags & UL_ME ) return 1;
311 if( _b->flags & UL_ME ) return -1;
312
313 tmpstr_len = strlen( tmpstr );
314 a_s = strncmp( _a->nick, tmpstr, tmpstr_len );
315 b_s = strncmp( _b->nick, tmpstr, tmpstr_len );
316
317 if( !a_s && b_s ) return -1; // a matches sensitive, b doesnt
318 if( a_s && !b_s ) return 1; // b matches sensitive, a doesnt
319
320 /* From now both strings either both or both dont match
321 decide their position by case insensitive match */
322 return strcasecmp( _a->nick, _b->nick );
299} 323}
300 324
301/* Nick completion function for readline */ 325/* Nick completion function for readline */
@@ -346,7 +370,11 @@ char **ul_complete_user(char *text, int start, int end ) {
346 and thus should complete all users, sorted alphabetically without 370 and thus should complete all users, sorted alphabetically without
347 preferences. */ 371 preferences. */
348 snprintf( tmpstr, end - start + 1, "%s", text ); 372 snprintf( tmpstr, end - start + 1, "%s", text );
349 qsort( g_users, g_users_count, sizeof(user), ul_compare_middle ); 373 if( ul_case_first )
374 qsort( g_users, g_users_count, sizeof(user), ul_compare_middle_case );
375 else
376 qsort( g_users, g_users_count, sizeof(user), ul_compare_middle_ncase );
377
350 for( i=0; i<g_users_count; ++i ) 378 for( i=0; i<g_users_count; ++i )
351 if( !strncasecmp( g_users[i].nick, tmpstr, end - start ) ) 379 if( !strncasecmp( g_users[i].nick, tmpstr, end - start ) )
352 result[++result_count] = strdup(g_users[i].nick); 380 result[++result_count] = strdup(g_users[i].nick);