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