Mercurial > hg > nnchat
comparison util.c @ 452:aeb3171f9e28
Simplify the userhash matching code a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 May 2012 05:10:11 +0300 |
parents | 3396acd40147 |
children | d55cc0b73c62 |
comparison
equal
deleted
inserted
replaced
451:733396469e5d | 452:aeb3171f9e28 |
---|---|
499 } | 499 } |
500 | 500 |
501 | 501 |
502 static nn_user_t *nn_userhash_match_do(nn_user_t *list, const char *pattern, size_t len) | 502 static nn_user_t *nn_userhash_match_do(nn_user_t *list, const char *pattern, size_t len) |
503 { | 503 { |
504 nn_user_t *curr = list; | 504 nn_user_t *node; |
505 | 505 for (node = list; node != NULL; node = node->next) |
506 while (curr != NULL) | 506 { |
507 { | 507 if (len <= strlen(node->name) && th_strncasecmp(node->name, pattern, len) == 0) |
508 if (len <= strlen(curr->name) && th_strncasecmp(curr->name, pattern, len) == 0) | 508 return node; |
509 return curr; | |
510 curr = curr->next; | |
511 } | 509 } |
512 return NULL; | 510 return NULL; |
513 } | 511 } |
514 | 512 |
515 | 513 |
520 if (list == NULL || pattern == NULL) return NULL; | 518 if (list == NULL || pattern == NULL) return NULL; |
521 | 519 |
522 hash = nn_hash_user(pattern); | 520 hash = nn_hash_user(pattern); |
523 if (list->buckets[hash] != NULL) | 521 if (list->buckets[hash] != NULL) |
524 { | 522 { |
525 nn_user_t *curr = list->buckets[hash]; | 523 nn_user_t *node; |
526 size_t len = strlen(pattern); | 524 size_t len = strlen(pattern); |
527 | 525 |
528 if (current != NULL) | 526 if (current != NULL) |
529 { | 527 { |
530 nn_user_t *found = NULL; | 528 for (node = list->buckets[hash]; node != NULL; node = node->next) |
531 while (curr != NULL) | 529 { |
532 { | 530 if (th_strcasecmp(node->name, current) == 0) |
533 if (th_strcasecmp(curr->name, current) == 0) | |
534 { | 531 { |
532 nn_user_t *found; | |
533 | |
535 if (again) | 534 if (again) |
536 return curr; | 535 return node; |
537 found = curr->next; | 536 |
538 break; | 537 if ((found = nn_userhash_match_do(node->next, pattern, len)) != NULL) |
538 return found; | |
539 } | 539 } |
540 curr = curr->next; | 540 } |
541 } | |
542 | |
543 if (found != NULL && (found = nn_userhash_match_do(found, pattern, len)) != NULL) | |
544 return found; | |
545 } | 541 } |
546 | 542 |
547 if ((curr = nn_userhash_match_do(list->buckets[hash], pattern, len)) != NULL) | 543 if ((node = nn_userhash_match_do(list->buckets[hash], pattern, len)) != NULL) |
548 return curr; | 544 return node; |
549 } | 545 } |
550 | 546 |
551 return NULL; | 547 return NULL; |
552 } | 548 } |
553 | 549 |