summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/cli.c4
-rw-r--r--src/lib/auto_complete.c13
-rw-r--r--src/lib/auto_complete.h4
3 files changed, 10 insertions, 11 deletions
diff --git a/src/bin/cli.c b/src/bin/cli.c
index 65197ae..a5252e7 100644
--- a/src/bin/cli.c
+++ b/src/bin/cli.c
@@ -377,10 +377,10 @@ _char_consume(Lexer *l, char c)
377 { 377 {
378 if(word == l->current){/* First word */ 378 if(word == l->current){/* First word */
379 379
380 comps = ac_get_autocompletions(ac_commands_root, word, 1); 380 comps = ac_get_autocompletions(ac_commands_root, word, 100);
381 } 381 }
382 else{ 382 else{
383 comps = ac_get_autocompletions(ac_classes_root, word, 1); 383 comps = ac_get_autocompletions(ac_classes_root, word, 100);
384 } 384 }
385 } 385 }
386 386
diff --git a/src/lib/auto_complete.c b/src/lib/auto_complete.c
index 9215a64..37f2b5d 100644
--- a/src/lib/auto_complete.c
+++ b/src/lib/auto_complete.c
@@ -2,7 +2,7 @@
2#include "auto_complete.h" 2#include "auto_complete.h"
3 3
4// A utility function to create a new ternary search tree node 4// A utility function to create a new ternary search tree node
5struct Ac_Node* 5struct Ac_Node*
6ac_new_node(char data) 6ac_new_node(char data)
7{ 7{
8 struct Ac_Node* temp = (struct Ac_Node*) malloc(sizeof( struct Ac_Node )); 8 struct Ac_Node* temp = (struct Ac_Node*) malloc(sizeof( struct Ac_Node ));
@@ -13,7 +13,7 @@ ac_new_node(char data)
13} 13}
14 14
15// Function to insert a new word in a Ternary Search Tree 15// Function to insert a new word in a Ternary Search Tree
16void 16void
17ac_insert(struct Ac_Node** root, const char *word) 17ac_insert(struct Ac_Node** root, const char *word)
18{ 18{
19 // Base Case: Tree is empty 19 // Base Case: Tree is empty
@@ -44,9 +44,9 @@ ac_insert(struct Ac_Node** root, const char *word)
44 44
45// A recursive function to traverse Ternary Search Tree 45// A recursive function to traverse Ternary Search Tree
46Eina_List * 46Eina_List *
47ac_traverseTSTUtil(struct Ac_Node* root, char* buffer, int depth, Eina_List *comps, int* limit) 47ac_traverseTSTUtil(struct Ac_Node* root, char* buffer, int depth, Eina_List *comps, unsigned int limit)
48{ 48{
49 if (root && *limit > 0) 49 if (root && limit > eina_list_count(comps))
50 { 50 {
51 // First traverse the left subtree 51 // First traverse the left subtree
52 ac_traverseTSTUtil(root->left, buffer, depth, comps, limit); 52 ac_traverseTSTUtil(root->left, buffer, depth, comps, limit);
@@ -58,7 +58,6 @@ ac_traverseTSTUtil(struct Ac_Node* root, char* buffer, int depth, Eina_List *com
58 buffer[depth+1] = '\0'; 58 buffer[depth+1] = '\0';
59 char* new_ac = strdup(buffer); 59 char* new_ac = strdup(buffer);
60 comps = eina_list_append(comps, new_ac); 60 comps = eina_list_append(comps, new_ac);
61 *limit--;
62 } 61 }
63 62
64 // Traverse the subtree using equal pointer (middle subtree) 63 // Traverse the subtree using equal pointer (middle subtree)
@@ -92,7 +91,7 @@ ac_free(struct Ac_Node* root)
92// The main function to traverse a Ternary Search Tree. 91// The main function to traverse a Ternary Search Tree.
93// It mainly uses traverseTSTUtil() 92// It mainly uses traverseTSTUtil()
94Eina_List * 93Eina_List *
95ac_get_autocompletions(struct Ac_Node* root, const char* word, int ac_limit) 94ac_get_autocompletions(struct Ac_Node* root, const char* word, unsigned int ac_limit)
96{ 95{
97 char buffer[50]; 96 char buffer[50];
98 int limit = ac_limit; 97 int limit = ac_limit;
@@ -100,7 +99,7 @@ ac_get_autocompletions(struct Ac_Node* root, const char* word, int ac_limit)
100 struct Ac_Node *start_node = ac_searchTSTA(root, word); 99 struct Ac_Node *start_node = ac_searchTSTA(root, word);
101 100
102 if(start_node) 101 if(start_node)
103 comps = ac_traverseTSTUtil(start_node, buffer, 0, comps, &limit); 102 comps = ac_traverseTSTUtil(start_node, buffer, 0, comps, limit);
104 103
105 return comps; 104 return comps;
106} 105}
diff --git a/src/lib/auto_complete.h b/src/lib/auto_complete.h
index e056e4b..b9af575 100644
--- a/src/lib/auto_complete.h
+++ b/src/lib/auto_complete.h
@@ -18,11 +18,11 @@ void ac_insert(struct Ac_Node** root, const char *word);
18struct Ac_Node * ac_searchTSTA(struct Ac_Node *root, const char *word); 18struct Ac_Node * ac_searchTSTA(struct Ac_Node *root, const char *word);
19 19
20// A recursive function to traverse Ternary Search Tree 20// A recursive function to traverse Ternary Search Tree
21Eina_List* ac_traverseTSTUtil(struct Ac_Node* root, char* buffer, int depth, Eina_List *comps, int* limit); 21Eina_List* ac_traverseTSTUtil(struct Ac_Node* root, char* buffer, int depth, Eina_List *comps, unsigned int limit);
22 22
23// The main function to traverse a Ternary Search Tree. 23// The main function to traverse a Ternary Search Tree.
24// It mainly uses traverseTSTUtil() 24// It mainly uses traverseTSTUtil()
25Eina_List* ac_get_autocompletions(struct Ac_Node* root, const char* word, int ac_limit); 25Eina_List* ac_get_autocompletions(struct Ac_Node* root, const char* word, unsigned int ac_limit);
26 26
27 // Function to search a given word in TST 27 // Function to search a given word in TST
28struct Ac_Node * searchTSTA(struct Ac_Node *root, const char *word); 28struct Ac_Node * searchTSTA(struct Ac_Node *root, const char *word);