1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 15:03:27 +01:00

replace name_compare with lib function

This commit is contained in:
Jfreegman 2013-12-08 01:18:10 -05:00
parent b8b032e441
commit e834821348
4 changed files with 7 additions and 22 deletions

View File

@ -28,7 +28,7 @@ static int friendlist_index[MAX_FRIENDS_NUM] = {0};
static int index_name_cmp(const void *n1, const void *n2)
{
int res = name_compare(friends[*(int *) n1].name, friends[*(int *) n2].name);
int res = qsort_strcasecmp_hlpr(friends[*(int *) n1].name, friends[*(int *) n2].name);
int k = 100;
/* Use weight to make qsort always put online friends before offline */

View File

@ -190,7 +190,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
uint8_t peername[TOX_MAX_NAME_LENGTH] = {0};
memcpy(peername, &groupchats[groupnum].peer_names[peernum*TOX_MAX_NAME_LENGTH], sizeof(peername));
qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, name_compare);
qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, qsort_strcasecmp_hlpr);
ChatContext *ctx = self->chatwin;
print_time(ctx->history);

View File

@ -158,25 +158,10 @@ void alert_window(ToxWindow *self, int type, bool is_beep)
beep();
}
/* case-insensitive string compare function for use with qsort - same return logic as strcmp */
int name_compare(const void *nick1, const void *nick2)
/* case-insensitive string compare function for use with qsort */
int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2)
{
char s[TOX_MAX_NAME_LENGTH];
char t[TOX_MAX_NAME_LENGTH];
strcpy(s, (const char *) nick1);
strcpy(t, (const char *) nick2);
int i;
for (i = 0; s[i] && t[i]; ++i) {
s[i] = tolower(s[i]);
t[i] = tolower(t[i]);
if (s[i] != t[i])
break;
}
return s[i] - t[i];
return strcasecmp((const char *) nick1, (const char *) nick2);
}
/* Returns true if nick is valid. A valid toxic nick:

View File

@ -35,8 +35,8 @@ bool timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime);
/* Colours the window tab according to type. Beeps if is_beep is true */
void alert_window(ToxWindow *self, int type, bool is_beep);
/* case-insensitive string compare function for use with qsort - same return logic as strcmp */
int name_compare(const void *nick1, const void *nick2);
/* case-insensitive string compare function for use with qsort */
int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2);
/* Returns true if nick is valid. A valid toxic nick:
- cannot be empty