Lines Matching refs:cpl
85 static void cpl_sort_matches(WordCompletion *cpl);
86 static void cpl_zap_duplicates(WordCompletion *cpl);
87 static void cpl_clear_completions(WordCompletion *cpl);
169 WordCompletion *cpl; /* The object to be returned */ in new_WordCompletion() local
173 cpl = (WordCompletion *) malloc(sizeof(WordCompletion)); in new_WordCompletion()
174 if(!cpl) { in new_WordCompletion()
183 cpl->err = NULL; in new_WordCompletion()
184 cpl->sg = NULL; in new_WordCompletion()
185 cpl->matches_dim = 0; in new_WordCompletion()
186 cpl->result.suffix = NULL; in new_WordCompletion()
187 cpl->result.cont_suffix = NULL; in new_WordCompletion()
188 cpl->result.matches = NULL; in new_WordCompletion()
189 cpl->result.nmatch = 0; in new_WordCompletion()
191 cpl->cf = NULL; in new_WordCompletion()
196 cpl->err = _new_ErrMsg(); in new_WordCompletion()
197 if(!cpl->err) in new_WordCompletion()
198 return del_WordCompletion(cpl); in new_WordCompletion()
204 cpl->sg = _new_StringGroup(MAX_PATHLEN_FALLBACK); in new_WordCompletion()
206 cpl->sg = _new_StringGroup(_pu_pathname_dim()); in new_WordCompletion()
208 if(!cpl->sg) in new_WordCompletion()
209 return del_WordCompletion(cpl); in new_WordCompletion()
214 cpl->matches_dim = STR_BLK_FACT; in new_WordCompletion()
215 cpl->result.matches = (CplMatch *) malloc(sizeof(cpl->result.matches[0]) * in new_WordCompletion()
216 cpl->matches_dim); in new_WordCompletion()
217 if(!cpl->result.matches) { in new_WordCompletion()
219 return del_WordCompletion(cpl); in new_WordCompletion()
225 cpl->cf = _new_CompleteFile(); in new_WordCompletion()
226 if(!cpl->cf) in new_WordCompletion()
227 return del_WordCompletion(cpl); in new_WordCompletion()
229 return cpl; in new_WordCompletion()
240 WordCompletion *del_WordCompletion(WordCompletion *cpl) in del_WordCompletion() argument
242 if(cpl) { in del_WordCompletion()
243 cpl->err = _del_ErrMsg(cpl->err); in del_WordCompletion()
244 cpl->sg = _del_StringGroup(cpl->sg); in del_WordCompletion()
245 if(cpl->result.matches) { in del_WordCompletion()
246 free(cpl->result.matches); in del_WordCompletion()
247 cpl->result.matches = NULL; in del_WordCompletion()
249 cpl->cf = _del_CompleteFile(cpl->cf); in del_WordCompletion()
252 free(cpl); in del_WordCompletion()
295 int cpl_add_completion(WordCompletion *cpl, const char *line, in cpl_add_completion() argument
305 if(!cpl) in cpl_add_completion()
316 if(cpl->result.nmatch+1 > cpl->matches_dim) { in cpl_add_completion()
317 int needed = cpl->matches_dim + STR_BLK_FACT; in cpl_add_completion()
318 CplMatch *matches = (CplMatch *) realloc(cpl->result.matches, in cpl_add_completion()
319 sizeof(cpl->result.matches[0]) * needed); in cpl_add_completion()
321 _err_record_msg(cpl->err, in cpl_add_completion()
326 cpl->result.matches = matches; in cpl_add_completion()
327 cpl->matches_dim = needed; in cpl_add_completion()
334 string = _sg_alloc_string(cpl->sg, word_end-word_start + len); in cpl_add_completion()
336 _err_record_msg(cpl->err, "Insufficient memory to extend array of matches.", in cpl_add_completion()
348 match = cpl->result.matches + cpl->result.nmatch++; in cpl_add_completion()
355 cpl->result.cont_suffix = cont_suffix; in cpl_add_completion()
365 static void cpl_sort_matches(WordCompletion *cpl) in cpl_sort_matches() argument
367 qsort(cpl->result.matches, cpl->result.nmatch, in cpl_sort_matches()
368 sizeof(cpl->result.matches[0]), cpl_cmp_matches); in cpl_sort_matches()
394 static void cpl_sort_suffixes(WordCompletion *cpl) in cpl_sort_suffixes() argument
396 qsort(cpl->result.matches, cpl->result.nmatch, in cpl_sort_suffixes()
397 sizeof(cpl->result.matches[0]), cpl_cmp_suffixes); in cpl_sort_suffixes()
429 static int cpl_common_suffix(WordCompletion *cpl) in cpl_common_suffix() argument
437 result = &cpl->result; in cpl_common_suffix()
446 cpl_sort_suffixes(cpl); in cpl_common_suffix()
470 result->suffix = _sg_alloc_string(cpl->sg, length); in cpl_common_suffix()
472 _err_record_msg(cpl->err, in cpl_common_suffix()
491 static void cpl_clear_completions(WordCompletion *cpl) in cpl_clear_completions() argument
496 _clr_StringGroup(cpl->sg); in cpl_clear_completions()
500 cpl->result.nmatch = 0; in cpl_clear_completions()
501 cpl->result.suffix = NULL; in cpl_clear_completions()
502 cpl->result.cont_suffix = ""; in cpl_clear_completions()
506 _err_clear_msg(cpl->err); in cpl_clear_completions()
534 CplMatches *cpl_complete_word(WordCompletion *cpl, const char *line, in cpl_complete_word() argument
546 if(!cpl || !line || !match_fn || word_end < 0 || word_end > line_len) { in cpl_complete_word()
547 if(cpl) { in cpl_complete_word()
548 _err_record_msg(cpl->err, "cpl_complete_word: Invalid arguments.", in cpl_complete_word()
556 cpl_clear_completions(cpl); in cpl_complete_word()
561 if(match_fn(cpl, data, line, word_end)) { in cpl_complete_word()
562 if(_err_get_msg(cpl->err)[0] == '\0') in cpl_complete_word() local
563 _err_record_msg(cpl->err, "Error completing word.", END_ERR_MSG); in cpl_complete_word()
570 if(cpl_common_suffix(cpl)) in cpl_complete_word()
575 cpl_sort_matches(cpl); in cpl_complete_word()
579 cpl_zap_duplicates(cpl); in cpl_complete_word()
583 if(cpl->result.nmatch > 1) in cpl_complete_word()
584 cpl->result.cont_suffix = ""; in cpl_complete_word()
588 return &cpl->result; in cpl_complete_word()
609 CplMatches *cpl_recall_matches(WordCompletion *cpl) in cpl_recall_matches() argument
611 return (!cpl || *_err_get_msg(cpl->err)!='\0') ? NULL : &cpl->result; in cpl_recall_matches()
682 const char *cpl_last_error(WordCompletion *cpl) in cpl_last_error() argument
684 return cpl ? _err_get_msg(cpl->err) : "NULL WordCompletion argument"; in cpl_last_error()
697 void cpl_record_error(WordCompletion *cpl, const char *errmsg) in cpl_record_error() argument
699 if(cpl && errmsg) in cpl_record_error()
700 _err_record_msg(cpl->err, errmsg, END_ERR_MSG); in cpl_record_error()
739 if(!cpl) in CPL_MATCH_FN()
742 _err_record_msg(cpl->err, "cpl_file_completions: Invalid arguments.", in CPL_MATCH_FN()
778 _err_record_msg(cpl->err, "Unable to find the start of the filename.", in CPL_MATCH_FN()
788 if(_cf_complete_file(cpl, cpl->cf, line, start_path - line, word_end, in CPL_MATCH_FN()
790 cpl_record_error(cpl, _cf_last_error(cpl->cf)); in CPL_MATCH_FN()
972 static void cpl_zap_duplicates(WordCompletion *cpl) in cpl_zap_duplicates() argument
985 matches = cpl->result.matches; in cpl_zap_duplicates()
986 nmatch = cpl->result.nmatch; in cpl_zap_duplicates()
1015 cpl->result.nmatch = dst; in cpl_zap_duplicates()