comparison libnnchat.c @ 116:741e45592522

Add simple "prediction" into tab-completion based on previously gotten last match. We assume that the last match is what the user wants, if new pattern matches previous pattern.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 24 Oct 2010 23:09:42 +0300
parents f323b137ca08
children 701c54a45466
comparison
equal deleted inserted replaced
115:300a6ea4aff3 116:741e45592522
651 651
652 return NULL; 652 return NULL;
653 } 653 }
654 654
655 655
656 nn_user_t *nn_user_match(const nn_userhash_t *list, const char *pattern, const char *current) 656 nn_user_t *nn_user_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again)
657 { 657 {
658 uint8_t hash; 658 uint8_t hash;
659 659
660 if (list == NULL || pattern == NULL) return NULL; 660 if (list == NULL || pattern == NULL) return NULL;
661 661
666 666
667 if (current != NULL) { 667 if (current != NULL) {
668 nn_user_t *found = NULL; 668 nn_user_t *found = NULL;
669 while (curr != NULL) { 669 while (curr != NULL) {
670 if (strcasecmp(curr->name, current) == 0) { 670 if (strcasecmp(curr->name, current) == 0) {
671 if (again)
672 return curr;
671 found = curr->next; 673 found = curr->next;
672 break; 674 break;
673 } 675 }
674 curr = curr->next; 676 curr = curr->next;
675 } 677 }
677 curr = found; 679 curr = found;
678 else 680 else
679 curr = list->buckets[hash]; 681 curr = list->buckets[hash];
680 } 682 }
681 683
684
682 while (curr != NULL) { 685 while (curr != NULL) {
683 if (len <= strlen(curr->name) && strncasecmp(curr->name, pattern, len) == 0) 686 if (len <= strlen(curr->name) && strncasecmp(curr->name, pattern, len) == 0)
684 return curr; 687 return curr;
685 curr = curr->next; 688 curr = curr->next;
686 } 689 }