Mercurial > hg > nnchat
diff util.c @ 446:3396acd40147
Rename and remove some functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 May 2012 03:40:57 +0300 |
parents | a9b20b31cae1 |
children | aeb3171f9e28 |
line wrap: on
line diff
--- a/util.c Fri May 25 22:42:50 2012 +0300 +++ b/util.c Sat May 26 03:40:57 2012 +0300 @@ -435,6 +435,26 @@ } +static void nn_user_free(nn_user_t *user) +{ + th_free(user->name); + th_free(user); +} + + +static void nn_user_free_list(nn_user_t *list) +{ + nn_user_t *next, *curr = list; + + while (curr != NULL) + { + next = curr->next; + nn_user_free(curr); + curr = next; + } +} + + nn_user_t *nn_userhash_foreach(const nn_userhash_t *list, int (*func)(const nn_user_t *)) { int i; @@ -457,7 +477,7 @@ } -nn_user_t *nn_user_find(const nn_userhash_t *list, const char *name) +nn_user_t *nn_userhash_find(const nn_userhash_t *list, const char *name) { uint8_t hash; @@ -479,7 +499,7 @@ } -static nn_user_t *nn_user_match_do(nn_user_t *list, const char *pattern, size_t len) +static nn_user_t *nn_userhash_match_do(nn_user_t *list, const char *pattern, size_t len) { nn_user_t *curr = list; @@ -493,7 +513,7 @@ } -nn_user_t *nn_user_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again) +nn_user_t *nn_userhash_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again) { uint8_t hash; @@ -520,11 +540,11 @@ curr = curr->next; } - if (found != NULL && (found = nn_user_match_do(found, pattern, len)) != NULL) + if (found != NULL && (found = nn_userhash_match_do(found, pattern, len)) != NULL) return found; } - if ((curr = nn_user_match_do(list->buckets[hash], pattern, len)) != NULL) + if ((curr = nn_userhash_match_do(list->buckets[hash], pattern, len)) != NULL) return curr; } @@ -548,7 +568,7 @@ return -1; // Check if username is already there - if (nn_user_find(list, name) != NULL) + if (nn_userhash_find(list, name) != NULL) return 1; // No, we'll add it @@ -606,43 +626,6 @@ } -nn_user_t *nn_user_copy(const nn_user_t *src) -{ - nn_user_t *user; - - if (src == NULL) return NULL; - - if ((user = th_calloc(1, sizeof(nn_user_t))) == NULL) - return NULL; - - // Copy relevant data - user->name = th_strdup(src->name); - user->lastspoke = src->lastspoke; - user->joined = src->joined; - - return user; -} - - -void nn_user_free(nn_user_t *user) -{ - th_free(user->name); - th_free(user); -} - - -void nn_user_free_list(nn_user_t *list) -{ - nn_user_t *next, *curr = list; - - while (curr != NULL) - { - next = curr->next; - nn_user_free(curr); - curr = next; - } -} - void nn_userhash_free(nn_userhash_t *hash) { int i;