Lines Matching refs:cf

92 static int cf_expand_home_dir(CompleteFile *cf, const char *user);
93 static int cf_complete_username(CompleteFile *cf, WordCompletion *cpl,
97 static int cf_complete_entry(CompleteFile *cf, WordCompletion *cpl,
101 static char *cf_read_name(CompleteFile *cf, const char *type,
104 static int cf_prepare_suffix(CompleteFile *cf, const char *suffix,
112 CompleteFile *cf; /* The file-completion resource object */
129 CompleteFile *cf; /* The object to be returned */
133 cf = (CompleteFile *) malloc(sizeof(CompleteFile));
134 if(!cf) {
143 cf->err = NULL;
144 cf->dr = NULL;
145 cf->home = NULL;
146 cf->path = NULL;
147 cf->buff = NULL;
148 cf->usrnam[0] = '\0';
149 cf->envnam[0] = '\0';
153 cf->err = _new_ErrMsg();
154 if(!cf->err)
155 return _del_CompleteFile(cf);
159 cf->dr = _new_DirReader();
160 if(!cf->dr)
161 return _del_CompleteFile(cf);
165 cf->home = _new_HomeDir();
166 if(!cf->home)
167 return _del_CompleteFile(cf);
171 cf->path = _new_PathName();
172 if(!cf->path)
173 return _del_CompleteFile(cf);
177 cf->buff = _new_PathName();
178 if(!cf->buff)
179 return _del_CompleteFile(cf);
180 return cf;
187 * cf CompleteFile * The object to be deleted.
191 CompleteFile *_del_CompleteFile(CompleteFile *cf)
193 if(cf) {
194 cf->err = _del_ErrMsg(cf->err);
195 cf->dr = _del_DirReader(cf->dr);
196 cf->home = _del_HomeDir(cf->home);
197 cf->path = _del_PathName(cf->path);
198 cf->buff = _del_PathName(cf->buff);
199 free(cf);
210 * cf CompleteFile * The filename-completion resource object.
234 * acquired by calling _cf_last_error(cf).
236 int _cf_complete_file(WordCompletion *cpl, CompleteFile *cf,
246 if(!cpl || !cf || !line || word_end < word_start) {
247 if(cf) {
248 _err_record_msg(cf->err, "_cf_complete_file: Invalid arguments",
256 _pn_clear_path(cf->path);
271 if(!cf_read_name(cf, "User", ++lptr, --nleft, cf->usrnam, USR_LEN))
276 slen = strlen(cf->usrnam);
284 if(cf_expand_home_dir(cf, cf->usrnam))
293 if(strcmp(cf->path->name, FS_ROOT_DIR) == 0 &&
306 return cf_complete_username(cf, cpl, cf->usrnam, line, word_start+1,
343 if(_pn_append_to_path(cf->path, lptr, seglen, escaped) == NULL) {
344 _err_record_msg(cf->err, "Insufficient memory to complete filename",
363 if(!cf_read_name(cf, "Environment", ++lptr, --nleft, cf->envnam, ENV_LEN))
368 nlen = strlen(cf->envnam);
374 value = getenv(cf->envnam);
376 _err_record_msg(cf->err, "Unknown environment variable: ", cf->envnam,
386 if(cf->path->name[0] == '\0' && value[0] == '~') {
387 if(!cf_read_name(cf, "User", value+1, vlen-1, cf->usrnam, USR_LEN) ||
388 cf_expand_home_dir(cf, cf->usrnam))
396 if(strcmp(cf->path->name, FS_ROOT_DIR) == 0 &&
405 if(_pn_append_to_path(cf->path, value, strlen(value), escaped)==NULL) {
406 _err_record_msg(cf->err, "Insufficient memory to complete filename",
414 strcmp(cf->path->name, FS_ROOT_DIR) == 0 &&
420 cf->path->name[vlen-FS_DIR_SEP_LEN] = '\0';
432 if(!_pu_path_is_dir(cf->path->name))
442 _err_record_msg(cf->err, cpl_last_error(cpl), END_ERR_MSG);
452 return cf_complete_entry(cf, cpl, line, word_start, word_end, escaped,
460 * cf CompleteFile * The path-completion resource object.
464 const char *_cf_last_error(CompleteFile *cf)
466 return cf ? _err_get_msg(cf->err) : "NULL CompleteFile argument";
474 * cf CompleteFile * The pathname completion resource object.
481 static int cf_expand_home_dir(CompleteFile *cf, const char *user)
486 const char *home_dir = _hd_lookup_home_dir(cf->home, user);
491 _err_record_msg(cf->err, _hd_last_home_dir_error(cf->home), END_ERR_MSG);
497 if(_pn_append_to_path(cf->path, home_dir, -1, 0) == NULL) {
498 _err_record_msg(cf->err, "Insufficient memory for home directory expansion",
509 * cf CompleteFile * The filename-completion resource object.
523 static int cf_complete_username(CompleteFile *cf, WordCompletion *cpl,
532 args.cf = cf;
543 if(_hd_scan_user_home_dirs(cf->home, prefix, &args, cf_homedir_callback)) {
544 _err_record_msg(cf->err, _hd_last_home_dir_error(cf->home), END_ERR_MSG);
561 CompleteFile *cf = args->cf;
566 if(cf_prepare_suffix(cf, usrnam+args->prefix_len, args->escaped)) {
567 strncpy(errmsg, _err_get_msg(cf->err), maxerr);
575 cf->buff->name, FS_DIR_SEP, FS_DIR_SEP)) {
584 * Report possible completions of the filename in cf->path->name[].
587 * cf CompleteFile * The file-completion resource object.
607 static int cf_complete_entry(CompleteFile *cf, WordCompletion *cpl,
623 char *pathname = cf->path->name;
662 if(_dr_open_dir(cf->dr, dirpath, NULL)) {
663 _err_record_msg(cf->err, "Can't open directory: ", dirpath, END_ERR_MSG);
683 while((file_name = _dr_next_file(cf->dr)) != NULL && !waserr) {
695 * Copy the completion suffix into the work pathname cf->buff->name,
698 if(cf_prepare_suffix(cf, file_name + prefix_len, escaped)) {
711 if(_pn_append_to_path(cf->path, file_name + prefix_len,
713 _err_record_msg(cf->err,
721 if(_pu_path_is_dir(cf->path->name)) {
724 } else if(!check_fn || check_fn(check_data, cf->path->name)) {
727 cf->path->name[pathlen] = '\0';
733 cf->path->name[pathlen] = '\0';
737 if(cpl_add_completion(cpl, line, word_start, word_end, cf->buff->name,
747 _dr_close_dir(cf->dr);
757 * cf CompleteFile * The file-completion resource object.
767 * in cf->err.
769 static char *cf_read_name(CompleteFile *cf, const char *type,
792 _err_record_msg(cf->err, type, " name too long", END_ERR_MSG);
803 * Using the work buffer cf->buff, make a suitably escaped copy of a
807 * cf CompleteFile * The file-completion resource object.
814 static int cf_prepare_suffix(CompleteFile *cf, const char *suffix,
827 _pn_clear_path(cf->buff);
846 if(_pn_resize_path(cf->buff, suffix_len + nbsl) == NULL) {
847 _err_record_msg(cf->err, "Insufficient memory to complete filename",
856 strlcpy(cf->buff->name, suffix, cf->buff->dim);
863 char *dst = cf->buff->name;