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