Lines Matching refs:cpl

83 static void cpl_sort_matches(WordCompletion *cpl);
84 static void cpl_zap_duplicates(WordCompletion *cpl);
85 static void cpl_clear_completions(WordCompletion *cpl);
167 WordCompletion *cpl; /* The object to be returned */ in new_WordCompletion() local
171 cpl = (WordCompletion *) malloc(sizeof(WordCompletion)); in new_WordCompletion()
172 if(!cpl) { in new_WordCompletion()
181 cpl->err = NULL; in new_WordCompletion()
182 cpl->sg = NULL; in new_WordCompletion()
183 cpl->matches_dim = 0; in new_WordCompletion()
184 cpl->result.suffix = NULL; in new_WordCompletion()
185 cpl->result.cont_suffix = NULL; in new_WordCompletion()
186 cpl->result.matches = NULL; in new_WordCompletion()
187 cpl->result.nmatch = 0; in new_WordCompletion()
189 cpl->cf = NULL; in new_WordCompletion()
194 cpl->err = _new_ErrMsg(); in new_WordCompletion()
195 if(!cpl->err) in new_WordCompletion()
196 return del_WordCompletion(cpl); in new_WordCompletion()
202 cpl->sg = _new_StringGroup(MAX_PATHLEN_FALLBACK); in new_WordCompletion()
204 cpl->sg = _new_StringGroup(_pu_pathname_dim()); in new_WordCompletion()
206 if(!cpl->sg) in new_WordCompletion()
207 return del_WordCompletion(cpl); in new_WordCompletion()
212 cpl->matches_dim = STR_BLK_FACT; in new_WordCompletion()
213 cpl->result.matches = (CplMatch *) malloc(sizeof(cpl->result.matches[0]) * in new_WordCompletion()
214 cpl->matches_dim); in new_WordCompletion()
215 if(!cpl->result.matches) { in new_WordCompletion()
217 return del_WordCompletion(cpl); in new_WordCompletion()
223 cpl->cf = _new_CompleteFile(); in new_WordCompletion()
224 if(!cpl->cf) in new_WordCompletion()
225 return del_WordCompletion(cpl); in new_WordCompletion()
227 return cpl; in new_WordCompletion()
238 WordCompletion *del_WordCompletion(WordCompletion *cpl) in del_WordCompletion() argument
240 if(cpl) { in del_WordCompletion()
241 cpl->err = _del_ErrMsg(cpl->err); in del_WordCompletion()
242 cpl->sg = _del_StringGroup(cpl->sg); in del_WordCompletion()
243 if(cpl->result.matches) { in del_WordCompletion()
244 free(cpl->result.matches); in del_WordCompletion()
245 cpl->result.matches = NULL; in del_WordCompletion()
247 cpl->cf = _del_CompleteFile(cpl->cf); in del_WordCompletion()
250 free(cpl); in del_WordCompletion()
293 int cpl_add_completion(WordCompletion *cpl, const char *line, in cpl_add_completion() argument
303 if(!cpl) in cpl_add_completion()
314 if(cpl->result.nmatch+1 > cpl->matches_dim) { in cpl_add_completion()
315 int needed = cpl->matches_dim + STR_BLK_FACT; in cpl_add_completion()
316 CplMatch *matches = (CplMatch *) realloc(cpl->result.matches, in cpl_add_completion()
317 sizeof(cpl->result.matches[0]) * needed); in cpl_add_completion()
319 _err_record_msg(cpl->err, in cpl_add_completion()
324 cpl->result.matches = matches; in cpl_add_completion()
325 cpl->matches_dim = needed; in cpl_add_completion()
332 string = _sg_alloc_string(cpl->sg, word_end-word_start + len); in cpl_add_completion()
334 _err_record_msg(cpl->err, "Insufficient memory to extend array of matches.", in cpl_add_completion()
346 match = cpl->result.matches + cpl->result.nmatch++; in cpl_add_completion()
353 cpl->result.cont_suffix = cont_suffix; in cpl_add_completion()
363 static void cpl_sort_matches(WordCompletion *cpl) in cpl_sort_matches() argument
365 qsort(cpl->result.matches, cpl->result.nmatch, in cpl_sort_matches()
366 sizeof(cpl->result.matches[0]), cpl_cmp_matches); in cpl_sort_matches()
392 static void cpl_sort_suffixes(WordCompletion *cpl) in cpl_sort_suffixes() argument
394 qsort(cpl->result.matches, cpl->result.nmatch, in cpl_sort_suffixes()
395 sizeof(cpl->result.matches[0]), cpl_cmp_suffixes); in cpl_sort_suffixes()
427 static int cpl_common_suffix(WordCompletion *cpl) in cpl_common_suffix() argument
435 result = &cpl->result; in cpl_common_suffix()
444 cpl_sort_suffixes(cpl); in cpl_common_suffix()
468 result->suffix = _sg_alloc_string(cpl->sg, length); in cpl_common_suffix()
470 _err_record_msg(cpl->err, in cpl_common_suffix()
489 static void cpl_clear_completions(WordCompletion *cpl) in cpl_clear_completions() argument
494 _clr_StringGroup(cpl->sg); in cpl_clear_completions()
498 cpl->result.nmatch = 0; in cpl_clear_completions()
499 cpl->result.suffix = NULL; in cpl_clear_completions()
500 cpl->result.cont_suffix = ""; in cpl_clear_completions()
504 _err_clear_msg(cpl->err); in cpl_clear_completions()
532 CplMatches *cpl_complete_word(WordCompletion *cpl, const char *line, in cpl_complete_word() argument
544 if(!cpl || !line || !match_fn || word_end < 0 || word_end > line_len) { in cpl_complete_word()
545 if(cpl) { in cpl_complete_word()
546 _err_record_msg(cpl->err, "cpl_complete_word: Invalid arguments.", in cpl_complete_word()
554 cpl_clear_completions(cpl); in cpl_complete_word()
559 if(match_fn(cpl, data, line, word_end)) { in cpl_complete_word()
560 if(_err_get_msg(cpl->err)[0] == '\0') in cpl_complete_word() local
561 _err_record_msg(cpl->err, "Error completing word.", END_ERR_MSG); in cpl_complete_word()
568 if(cpl_common_suffix(cpl)) in cpl_complete_word()
573 cpl_sort_matches(cpl); in cpl_complete_word()
577 cpl_zap_duplicates(cpl); in cpl_complete_word()
581 if(cpl->result.nmatch > 1) in cpl_complete_word()
582 cpl->result.cont_suffix = ""; in cpl_complete_word()
586 return &cpl->result; in cpl_complete_word()
607 CplMatches *cpl_recall_matches(WordCompletion *cpl) in cpl_recall_matches() argument
609 return (!cpl || *_err_get_msg(cpl->err)!='\0') ? NULL : &cpl->result; in cpl_recall_matches()
680 const char *cpl_last_error(WordCompletion *cpl) in cpl_last_error() argument
682 return cpl ? _err_get_msg(cpl->err) : "NULL WordCompletion argument"; in cpl_last_error()
695 void cpl_record_error(WordCompletion *cpl, const char *errmsg) in cpl_record_error() argument
697 if(cpl && errmsg) in cpl_record_error()
698 _err_record_msg(cpl->err, errmsg, END_ERR_MSG); in cpl_record_error()
737 if(!cpl) in CPL_MATCH_FN()
740 _err_record_msg(cpl->err, "cpl_file_completions: Invalid arguments.", in CPL_MATCH_FN()
776 _err_record_msg(cpl->err, "Unable to find the start of the filename.", in CPL_MATCH_FN()
786 if(_cf_complete_file(cpl, cpl->cf, line, start_path - line, word_end, in CPL_MATCH_FN()
788 cpl_record_error(cpl, _cf_last_error(cpl->cf)); in CPL_MATCH_FN()
970 static void cpl_zap_duplicates(WordCompletion *cpl) in cpl_zap_duplicates() argument
983 matches = cpl->result.matches; in cpl_zap_duplicates()
984 nmatch = cpl->result.nmatch; in cpl_zap_duplicates()
1013 cpl->result.nmatch = dst; in cpl_zap_duplicates()