>From 68a6cff3e48dea9f10b2b9bc7b36193b54ae0141 Mon Sep 17 00:00:00 2001 From: "sumedh.pendurkar" Date: Fri, 28 Oct 2016 17:02:46 +0530 Subject: [PATCH 2/2] Added more comments --- src/text.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/text.c b/src/text.c index 7e92e21..e494545 100644 --- a/src/text.c +++ b/src/text.c @@ -3699,6 +3699,7 @@ char *copy_completion(char *check_line, int start) int i = start, j = 0; int len_of_word = 0; + /* Calculate the length of word by travelling till end of word*/ while (is_word_mbchar(&check_line[i++], FALSE)) len_of_word++; @@ -3706,6 +3707,7 @@ char *copy_completion(char *check_line, int start) i = start; + /* Simply copy the word */ while (is_word_mbchar(&check_line[i], FALSE)) word[j++] = check_line[i++]; @@ -3756,6 +3758,7 @@ void complete_a_word(void) } to_find_start_pos = openfile->current_x; + /* Intializing iterator some_word to the head of the list of previous searches if any */ some_word = list_of_completions; /* Find the start of the fragment that the user typed. */ @@ -3780,17 +3783,26 @@ void complete_a_word(void) /* Search the fragment in the file. */ while (pletion_line != NULL) { int line_length = strlen(pletion_line->data); - + + /* Search in the pletion_line if match exists + * This loop is used for traversing in the pletion_line */ for (i = pletion_x; i + shard_length < line_length; i++) { /* Ignore the fragment itself. */ if (pletion_line == openfile->current && i == openfile->current_x - shard_length) continue; + /* This loop traverses in shard and match it against pletion_line + * It would get out of loop if j < shard_length which suggests that match is found + * or if end of word is encountered */ for (j = 0; (i == 0 || !is_word_mbchar(&pletion_line->data[i - 1], FALSE)) && j < shard_length; j++) + + /* Also break even if a character mismatches */ if (shard[j] != pletion_line->data[i + j]) break; + /* If we have travelled whole shard and the matched word is not same as shard + * copy the word into completion */ if (j == shard_length && (i + j < line_length && is_word_mbchar(&pletion_line->data[i + j], FALSE))) { completion = copy_completion(pletion_line->data, i++); @@ -3826,6 +3838,7 @@ void complete_a_word(void) pletion_x = 0; } + /* Reached the end of the file */ if (pletion_line == NULL) { if (list_of_completions != NULL) { statusline(HUSH, "No further matches"); -- 2.7.4