Lines Matching refs:cf
90 static int cf_expand_home_dir(CompleteFile *cf, const char *user);
91 static int cf_complete_username(CompleteFile *cf, WordCompletion *cpl,
95 static int cf_complete_entry(CompleteFile *cf, WordCompletion *cpl,
99 static char *cf_read_name(CompleteFile *cf, const char *type,
102 static int cf_prepare_suffix(CompleteFile *cf, const char *suffix,
110 CompleteFile *cf; /* The file-completion resource object */ member
127 CompleteFile *cf; /* The object to be returned */ in _new_CompleteFile() local
131 cf = (CompleteFile *) malloc(sizeof(CompleteFile)); in _new_CompleteFile()
132 if(!cf) { in _new_CompleteFile()
141 cf->err = NULL; in _new_CompleteFile()
142 cf->dr = NULL; in _new_CompleteFile()
143 cf->home = NULL; in _new_CompleteFile()
144 cf->path = NULL; in _new_CompleteFile()
145 cf->buff = NULL; in _new_CompleteFile()
146 cf->usrnam[0] = '\0'; in _new_CompleteFile()
147 cf->envnam[0] = '\0'; in _new_CompleteFile()
151 cf->err = _new_ErrMsg(); in _new_CompleteFile()
152 if(!cf->err) in _new_CompleteFile()
153 return _del_CompleteFile(cf); in _new_CompleteFile()
157 cf->dr = _new_DirReader(); in _new_CompleteFile()
158 if(!cf->dr) in _new_CompleteFile()
159 return _del_CompleteFile(cf); in _new_CompleteFile()
163 cf->home = _new_HomeDir(); in _new_CompleteFile()
164 if(!cf->home) in _new_CompleteFile()
165 return _del_CompleteFile(cf); in _new_CompleteFile()
169 cf->path = _new_PathName(); in _new_CompleteFile()
170 if(!cf->path) in _new_CompleteFile()
171 return _del_CompleteFile(cf); in _new_CompleteFile()
175 cf->buff = _new_PathName(); in _new_CompleteFile()
176 if(!cf->buff) in _new_CompleteFile()
177 return _del_CompleteFile(cf); in _new_CompleteFile()
178 return cf; in _new_CompleteFile()
189 CompleteFile *_del_CompleteFile(CompleteFile *cf) in _del_CompleteFile() argument
191 if(cf) { in _del_CompleteFile()
192 cf->err = _del_ErrMsg(cf->err); in _del_CompleteFile()
193 cf->dr = _del_DirReader(cf->dr); in _del_CompleteFile()
194 cf->home = _del_HomeDir(cf->home); in _del_CompleteFile()
195 cf->path = _del_PathName(cf->path); in _del_CompleteFile()
196 cf->buff = _del_PathName(cf->buff); in _del_CompleteFile()
197 free(cf); in _del_CompleteFile()
234 int _cf_complete_file(WordCompletion *cpl, CompleteFile *cf, in _cf_complete_file() argument
244 if(!cpl || !cf || !line || word_end < word_start) { in _cf_complete_file()
245 if(cf) { in _cf_complete_file()
246 _err_record_msg(cf->err, "_cf_complete_file: Invalid arguments", in _cf_complete_file()
254 _pn_clear_path(cf->path); in _cf_complete_file()
269 if(!cf_read_name(cf, "User", ++lptr, --nleft, cf->usrnam, USR_LEN)) in _cf_complete_file()
274 slen = strlen(cf->usrnam); in _cf_complete_file()
282 if(cf_expand_home_dir(cf, cf->usrnam)) in _cf_complete_file()
291 if(strcmp(cf->path->name, FS_ROOT_DIR) == 0 && in _cf_complete_file()
304 return cf_complete_username(cf, cpl, cf->usrnam, line, word_start+1, in _cf_complete_file()
341 if(_pn_append_to_path(cf->path, lptr, seglen, escaped) == NULL) { in _cf_complete_file()
342 _err_record_msg(cf->err, "Insufficient memory to complete filename", in _cf_complete_file()
361 if(!cf_read_name(cf, "Environment", ++lptr, --nleft, cf->envnam, ENV_LEN)) in _cf_complete_file()
366 nlen = strlen(cf->envnam); in _cf_complete_file()
372 value = getenv(cf->envnam); in _cf_complete_file()
374 _err_record_msg(cf->err, "Unknown environment variable: ", cf->envnam, in _cf_complete_file()
384 if(cf->path->name[0] == '\0' && value[0] == '~') { in _cf_complete_file()
385 if(!cf_read_name(cf, "User", value+1, vlen-1, cf->usrnam, USR_LEN) || in _cf_complete_file()
386 cf_expand_home_dir(cf, cf->usrnam)) in _cf_complete_file()
394 if(strcmp(cf->path->name, FS_ROOT_DIR) == 0 && in _cf_complete_file()
403 if(_pn_append_to_path(cf->path, value, strlen(value), escaped)==NULL) { in _cf_complete_file()
404 _err_record_msg(cf->err, "Insufficient memory to complete filename", in _cf_complete_file()
412 strcmp(cf->path->name, FS_ROOT_DIR) == 0 && in _cf_complete_file()
418 cf->path->name[vlen-FS_DIR_SEP_LEN] = '\0'; in _cf_complete_file()
430 if(!_pu_path_is_dir(cf->path->name)) in _cf_complete_file()
440 _err_record_msg(cf->err, cpl_last_error(cpl), END_ERR_MSG); in _cf_complete_file()
450 return cf_complete_entry(cf, cpl, line, word_start, word_end, escaped, in _cf_complete_file()
462 const char *_cf_last_error(CompleteFile *cf) in _cf_last_error() argument
464 return cf ? _err_get_msg(cf->err) : "NULL CompleteFile argument"; in _cf_last_error()
479 static int cf_expand_home_dir(CompleteFile *cf, const char *user) in cf_expand_home_dir() argument
484 const char *home_dir = _hd_lookup_home_dir(cf->home, user); in cf_expand_home_dir()
489 _err_record_msg(cf->err, _hd_last_home_dir_error(cf->home), END_ERR_MSG); in cf_expand_home_dir()
495 if(_pn_append_to_path(cf->path, home_dir, -1, 0) == NULL) { in cf_expand_home_dir()
496 _err_record_msg(cf->err, "Insufficient memory for home directory expansion", in cf_expand_home_dir()
521 static int cf_complete_username(CompleteFile *cf, WordCompletion *cpl, in cf_complete_username() argument
530 args.cf = cf; in cf_complete_username()
541 if(_hd_scan_user_home_dirs(cf->home, prefix, &args, cf_homedir_callback)) { in cf_complete_username()
542 _err_record_msg(cf->err, _hd_last_home_dir_error(cf->home), END_ERR_MSG); in cf_complete_username()
559 CompleteFile *cf = args->cf; in HOME_DIR_FN() local
564 if(cf_prepare_suffix(cf, usrnam+args->prefix_len, args->escaped)) { in HOME_DIR_FN()
565 strncpy(errmsg, _err_get_msg(cf->err), maxerr); in HOME_DIR_FN()
573 cf->buff->name, FS_DIR_SEP, FS_DIR_SEP)) { in HOME_DIR_FN()
605 static int cf_complete_entry(CompleteFile *cf, WordCompletion *cpl, in cf_complete_entry() argument
621 char *pathname = cf->path->name; in cf_complete_entry()
660 if(_dr_open_dir(cf->dr, dirpath, NULL)) { in cf_complete_entry()
661 _err_record_msg(cf->err, "Can't open directory: ", dirpath, END_ERR_MSG); in cf_complete_entry()
681 while((file_name = _dr_next_file(cf->dr)) != NULL && !waserr) { in cf_complete_entry()
696 if(cf_prepare_suffix(cf, file_name + prefix_len, escaped)) { in cf_complete_entry()
709 if(_pn_append_to_path(cf->path, file_name + prefix_len, in cf_complete_entry()
711 _err_record_msg(cf->err, in cf_complete_entry()
719 if(_pu_path_is_dir(cf->path->name)) { in cf_complete_entry()
722 } else if(!check_fn || check_fn(check_data, cf->path->name)) { in cf_complete_entry()
725 cf->path->name[pathlen] = '\0'; in cf_complete_entry()
731 cf->path->name[pathlen] = '\0'; in cf_complete_entry()
735 if(cpl_add_completion(cpl, line, word_start, word_end, cf->buff->name, in cf_complete_entry()
745 _dr_close_dir(cf->dr); in cf_complete_entry()
767 static char *cf_read_name(CompleteFile *cf, const char *type, in cf_read_name() argument
790 _err_record_msg(cf->err, type, " name too long", END_ERR_MSG); in cf_read_name()
812 static int cf_prepare_suffix(CompleteFile *cf, const char *suffix, in cf_prepare_suffix() argument
825 _pn_clear_path(cf->buff); in cf_prepare_suffix()
844 if(_pn_resize_path(cf->buff, suffix_len + nbsl) == NULL) { in cf_prepare_suffix()
845 _err_record_msg(cf->err, "Insufficient memory to complete filename", in cf_prepare_suffix()
854 strlcpy(cf->buff->name, suffix, cf->buff->dim); in cf_prepare_suffix()
861 char *dst = cf->buff->name; in cf_prepare_suffix()