comparison mcabber/src/compl.c @ 98:f20831f7d349

[/trunk] Changeset 112 by mikael * Completion system enabled for commands. It almost works! ;-)
author mikael
date Wed, 20 Apr 2005 20:35:48 +0000
parents 9e6b7897ec37
children 93dcc4e15d4a
comparison
equal deleted inserted replaced
97:191f4d00d19b 98:f20831f7d349
77 c = g_new0(compl, 1); 77 c = g_new0(compl, 1);
78 // Build the list of matches 78 // Build the list of matches
79 for (sl_cat=compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) { 79 for (sl_cat=compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) {
80 char *word = sl_cat->data; 80 char *word = sl_cat->data;
81 if (!strncmp(prefix, word, len)) { 81 if (!strncmp(prefix, word, len)) {
82 c->list = g_slist_append(c->list, g_strdup(word+len)); // TODO sort 82 if (strlen(word) != len)
83 c->list = g_slist_append(c->list, g_strdup(word+len)); // TODO sort
83 } 84 }
84 } 85 }
85 c->next = c->list; 86 c->next = c->list;
86 InputCompl = c; 87 InputCompl = c;
87 } 88 }
88 89
89 // done_completion(); 90 // done_completion();
90 void done_completion(void) 91 void done_completion(void)
91 { 92 {
93 if (!InputCompl) return;
94
92 // TODO free everything 95 // TODO free everything
93 g_slist_free(InputCompl->list); 96 g_slist_free(InputCompl->list);
94 g_free(InputCompl); 97 g_free(InputCompl);
95 InputCompl = NULL; 98 InputCompl = NULL;
96 } 99 }
98 // cancel_completion() 101 // cancel_completion()
99 // Returns the number of chars to delete to cancel the completion 102 // Returns the number of chars to delete to cancel the completion
100 //guint cancel_completion(compl *c) 103 //guint cancel_completion(compl *c)
101 guint cancel_completion(void) 104 guint cancel_completion(void)
102 { 105 {
106 if (!InputCompl) return 0;
103 return InputCompl->len_compl; 107 return InputCompl->len_compl;
104 } 108 }
105 109
106 // Returns pointer to text to insert, NULL if no completion. 110 // Returns pointer to text to insert, NULL if no completion.
107 const char *complete() 111 const char *complete()
108 { 112 {
109 compl* c = InputCompl; 113 compl* c = InputCompl;
110 char *r; 114 char *r;
115
116 if (!InputCompl) return NULL;
117
111 if (!c->next) { 118 if (!c->next) {
112 c->next = c->list; // back to the beginning 119 c->next = c->list; // back to the beginning
113 c->len_compl = 0; 120 c->len_compl = 0;
114 return NULL; 121 return NULL;
115 } 122 }