Lines Matching refs:ef

113 static int ef_record_pathname(ExpandFile *ef, const char *pathname,
115 static char *ef_cache_pathname(ExpandFile *ef, const char *pathname,
117 static void ef_clear_files(ExpandFile *ef);
119 static DirNode *ef_open_dir(ExpandFile *ef, const char *pathname);
120 static DirNode *ef_close_dir(ExpandFile *ef, DirNode *node);
121 static char *ef_expand_special(ExpandFile *ef, const char *path, int pathlen);
122 static int ef_match_relative_pathname(ExpandFile *ef, DirReader *dr,
162 ExpandFile *ef; /* The object to be returned */ in new_ExpandFile() local
166 ef = (ExpandFile *) malloc(sizeof(ExpandFile)); in new_ExpandFile()
167 if(!ef) { in new_ExpandFile()
176 ef->err = NULL; in new_ExpandFile()
177 ef->sg = NULL; in new_ExpandFile()
178 ef->cache.mem = NULL; in new_ExpandFile()
179 ef->cache.head = NULL; in new_ExpandFile()
180 ef->cache.next = NULL; in new_ExpandFile()
181 ef->cache.tail = NULL; in new_ExpandFile()
182 ef->path = NULL; in new_ExpandFile()
183 ef->home = NULL; in new_ExpandFile()
184 ef->result.files = NULL; in new_ExpandFile()
185 ef->result.nfile = 0; in new_ExpandFile()
186 ef->usrnam[0] = '\0'; in new_ExpandFile()
187 ef->envnam[0] = '\0'; in new_ExpandFile()
191 ef->err = _new_ErrMsg(); in new_ExpandFile()
192 if(!ef->err) in new_ExpandFile()
193 return del_ExpandFile(ef); in new_ExpandFile()
197 ef->sg = _new_StringGroup(_pu_pathname_dim()); in new_ExpandFile()
198 if(!ef->sg) in new_ExpandFile()
199 return del_ExpandFile(ef); in new_ExpandFile()
203 ef->cache.mem = _new_FreeList(sizeof(DirNode), DIR_CACHE_BLK); in new_ExpandFile()
204 if(!ef->cache.mem) in new_ExpandFile()
205 return del_ExpandFile(ef); in new_ExpandFile()
209 ef->path = _new_PathName(); in new_ExpandFile()
210 if(!ef->path) in new_ExpandFile()
211 return del_ExpandFile(ef); in new_ExpandFile()
215 ef->home = _new_HomeDir(); in new_ExpandFile()
216 if(!ef->home) in new_ExpandFile()
217 return del_ExpandFile(ef); in new_ExpandFile()
221 ef->files_dim = MATCH_BLK_FACT; in new_ExpandFile()
222 ef->result.files = (char **) malloc(sizeof(ef->result.files[0]) * in new_ExpandFile()
223 ef->files_dim); in new_ExpandFile()
224 if(!ef->result.files) { in new_ExpandFile()
226 return del_ExpandFile(ef); in new_ExpandFile()
228 return ef; in new_ExpandFile()
239 ExpandFile *del_ExpandFile(ExpandFile *ef) in del_ExpandFile() argument
241 if(ef) { in del_ExpandFile()
246 ef->sg = _del_StringGroup(ef->sg); in del_ExpandFile()
250 for(dnode=ef->cache.head; dnode; dnode=dnode->next) in del_ExpandFile()
256 ef->cache.mem = _del_FreeList(ef->cache.mem, 1); in del_ExpandFile()
257 ef->cache.head = ef->cache.tail = ef->cache.next = NULL; in del_ExpandFile()
261 ef->path = _del_PathName(ef->path); in del_ExpandFile()
265 ef->home = _del_HomeDir(ef->home); in del_ExpandFile()
269 if(ef->result.files) { in del_ExpandFile()
270 free(ef->result.files); in del_ExpandFile()
271 ef->result.files = NULL; in del_ExpandFile()
276 ef->err = _del_ErrMsg(ef->err); in del_ExpandFile()
280 free(ef); in del_ExpandFile()
346 FileExpansion *ef_expand_file(ExpandFile *ef, const char *path, int pathlen) in ef_expand_file() argument
355 if(!ef || !path) { in ef_expand_file()
356 if(ef) { in ef_expand_file()
357 _err_record_msg(ef->err, "ef_expand_file: NULL path argument", in ef_expand_file()
372 ef_clear_files(ef); in ef_expand_file()
378 path = ef_expand_special(ef, path, pathlen); in ef_expand_file()
384 _pn_clear_path(ef->path); in ef_expand_file()
404 if(ef_record_pathname(ef, path, 1)) in ef_expand_file()
409 ef->result.exists = _pu_file_exists(ef->result.files[0]); in ef_expand_file()
418 ef->result.exists = 1; in ef_expand_file()
424 if(ef_record_pathname(ef, FS_ROOT_DIR, 0)) in ef_expand_file()
432 if(!_pn_append_to_path(ef->path, FS_ROOT_DIR, -1, 0)) { in ef_expand_file()
433 _err_record_msg(ef->err, "Insufficient memory to record path", in ef_expand_file()
444 dnode = ef_open_dir(ef, dirname); in ef_expand_file()
450 if(ef_match_relative_pathname(ef, dnode->dr, path, 0)) { in ef_expand_file()
451 dnode = ef_close_dir(ef, dnode); in ef_expand_file()
457 dnode = ef_close_dir(ef, dnode); in ef_expand_file()
462 if(ef->result.nfile < 1) { in ef_expand_file()
463 _err_record_msg(ef->err, "No files match", END_ERR_MSG); in ef_expand_file()
469 qsort(ef->result.files, ef->result.nfile, sizeof(ef->result.files[0]), in ef_expand_file()
475 return &ef->result; in ef_expand_file()
496 static int ef_match_relative_pathname(ExpandFile *ef, DirReader *dr, in ef_match_relative_pathname() argument
509 pathlen = strlen(ef->path->name); in ef_match_relative_pathname()
531 if((separate && _pn_append_to_path(ef->path, FS_DIR_SEP, -1, 0)==NULL) || in ef_match_relative_pathname()
532 _pn_append_to_path(ef->path, file, -1, 0)==NULL) { in ef_match_relative_pathname()
533 _err_record_msg(ef->err, "Insufficient memory to record path", in ef_match_relative_pathname()
542 if(ef_record_pathname(ef, ef->path->name, 0)) in ef_match_relative_pathname()
550 } else if(_pu_path_is_dir(ef->path->name) && in ef_match_relative_pathname()
557 if(ef_record_pathname(ef, ef->path->name, 0)) in ef_match_relative_pathname()
563 DirNode *subdnode = ef_open_dir(ef, ef->path->name); in ef_match_relative_pathname()
565 if(ef_match_relative_pathname(ef, subdnode->dr, in ef_match_relative_pathname()
567 subdnode = ef_close_dir(ef, subdnode); in ef_match_relative_pathname()
570 subdnode = ef_close_dir(ef, subdnode); in ef_match_relative_pathname()
578 ef->path->name[pathlen] = '\0'; in ef_match_relative_pathname()
597 static int ef_record_pathname(ExpandFile *ef, const char *pathname, in ef_record_pathname() argument
604 copy = ef_cache_pathname(ef, pathname, remove_escapes); in ef_record_pathname()
611 if(ef->result.nfile + 1 > ef->files_dim) { in ef_record_pathname()
612 int files_dim = ef->files_dim + MATCH_BLK_FACT; in ef_record_pathname()
613 char **files = (char **) realloc(ef->result.files, in ef_record_pathname()
616 _err_record_msg(ef->err, in ef_record_pathname()
622 ef->result.files = files; in ef_record_pathname()
623 ef->files_dim = files_dim; in ef_record_pathname()
628 ef->result.files[ef->result.nfile++] = copy; in ef_record_pathname()
645 static char *ef_cache_pathname(ExpandFile *ef, const char *pathname, in ef_cache_pathname() argument
648 char *copy = _sg_store_string(ef->sg, pathname, remove_escapes); in ef_cache_pathname()
650 _err_record_msg(ef->err, "Insufficient memory to store pathname", in ef_cache_pathname()
662 static void ef_clear_files(ExpandFile *ef) in ef_clear_files() argument
664 _clr_StringGroup(ef->sg); in ef_clear_files()
665 _pn_clear_path(ef->path); in ef_clear_files()
666 ef->result.exists = 0; in ef_clear_files()
667 ef->result.nfile = 0; in ef_clear_files()
668 _err_clear_msg(ef->err); in ef_clear_files()
683 static DirNode *ef_open_dir(ExpandFile *ef, const char *pathname) in ef_open_dir() argument
690 DirCache *cache = &ef->cache; in ef_open_dir()
697 _err_record_msg(ef->err, "Insufficient memory to open a new directory", in ef_open_dir()
712 _err_record_msg(ef->err, "Insufficient memory to open a new directory", in ef_open_dir()
735 _err_record_msg(ef->err, errmsg, END_ERR_MSG); in ef_open_dir()
769 static DirNode *ef_close_dir(ExpandFile *ef, DirNode *node) in ef_close_dir() argument
774 DirCache *cache = &ef->cache; in ef_close_dir()
1042 static char *ef_expand_special(ExpandFile *ef, const char *path, int pathlen) in ef_expand_special() argument
1053 _pn_clear_path(ef->path); in ef_expand_special()
1072 if(spos < ppos && _pn_append_to_path(ef->path, path + spos, ppos-spos, 0) in ef_expand_special()
1074 _err_record_msg(ef->err, "Insufficient memory to expand path", in ef_expand_special()
1089 ef->envnam[envlen] = path[ppos++]; in ef_expand_special()
1096 _err_record_msg(ef->err, "Environment variable name too long", in ef_expand_special()
1103 ef->envnam[envlen] = '\0'; in ef_expand_special()
1107 value = getenv(ef->envnam); in ef_expand_special()
1109 _err_record_msg(ef->err, "No expansion found for: $", ef->envnam, in ef_expand_special()
1116 if(_pn_append_to_path(ef->path, value, -1, 0) == NULL) { in ef_expand_special()
1117 _err_record_msg(ef->err, "Insufficient memory to expand path", in ef_expand_special()
1130 if(spos < ppos && _pn_append_to_path(ef->path, path + spos, ppos-spos, 0) in ef_expand_special()
1132 _err_record_msg(ef->err, "Insufficient memory to expand path", END_ERR_MSG); in ef_expand_special()
1139 pptr = ef->path->name; in ef_expand_special()
1149 plen = strlen(ef->path->name); in ef_expand_special()
1159 ef->usrnam[usrlen] = *pptr++; in ef_expand_special()
1166 _err_record_msg(ef->err, "Username too long", END_ERR_MSG); in ef_expand_special()
1172 ef->usrnam[usrlen] = '\0'; in ef_expand_special()
1176 homedir = _hd_lookup_home_dir(ef->home, ef->usrnam); in ef_expand_special()
1178 _err_record_msg(ef->err, _hd_last_home_dir_error(ef->home), END_ERR_MSG); in ef_expand_special()
1198 if(_pn_resize_path(ef->path, plen - usrlen - 1 - skip + homelen)==NULL) { in ef_expand_special()
1199 _err_record_msg(ef->err, "Insufficient memory to expand filename", in ef_expand_special()
1207 memmove(ef->path->name + homelen, in ef_expand_special()
1208 ef->path->name + 1 + usrlen + skip, plen - usrlen - 1 - skip+1); in ef_expand_special()
1213 ef->path->name[i] = homedir[i]; in ef_expand_special()
1218 return ef_cache_pathname(ef, ef->path->name, 0); in ef_expand_special()
1229 const char *ef_last_error(ExpandFile *ef) in ef_last_error() argument
1231 return ef ? _err_get_msg(ef->err) : "NULL ExpandFile argument"; in ef_last_error()