Lines Matching refs:ef

115 static int ef_record_pathname(ExpandFile *ef, const char *pathname,
117 static char *ef_cache_pathname(ExpandFile *ef, const char *pathname,
119 static void ef_clear_files(ExpandFile *ef);
121 static DirNode *ef_open_dir(ExpandFile *ef, const char *pathname);
122 static DirNode *ef_close_dir(ExpandFile *ef, DirNode *node);
123 static char *ef_expand_special(ExpandFile *ef, const char *path, int pathlen);
124 static int ef_match_relative_pathname(ExpandFile *ef, DirReader *dr,
164 ExpandFile *ef; /* The object to be returned */ in new_ExpandFile() local
168 ef = (ExpandFile *) malloc(sizeof(ExpandFile)); in new_ExpandFile()
169 if(!ef) { in new_ExpandFile()
178 ef->err = NULL; in new_ExpandFile()
179 ef->sg = NULL; in new_ExpandFile()
180 ef->cache.mem = NULL; in new_ExpandFile()
181 ef->cache.head = NULL; in new_ExpandFile()
182 ef->cache.next = NULL; in new_ExpandFile()
183 ef->cache.tail = NULL; in new_ExpandFile()
184 ef->path = NULL; in new_ExpandFile()
185 ef->home = NULL; in new_ExpandFile()
186 ef->result.files = NULL; in new_ExpandFile()
187 ef->result.nfile = 0; in new_ExpandFile()
188 ef->usrnam[0] = '\0'; in new_ExpandFile()
189 ef->envnam[0] = '\0'; in new_ExpandFile()
193 ef->err = _new_ErrMsg(); in new_ExpandFile()
194 if(!ef->err) in new_ExpandFile()
195 return del_ExpandFile(ef); in new_ExpandFile()
199 ef->sg = _new_StringGroup(_pu_pathname_dim()); in new_ExpandFile()
200 if(!ef->sg) in new_ExpandFile()
201 return del_ExpandFile(ef); in new_ExpandFile()
205 ef->cache.mem = _new_FreeList(sizeof(DirNode), DIR_CACHE_BLK); in new_ExpandFile()
206 if(!ef->cache.mem) in new_ExpandFile()
207 return del_ExpandFile(ef); in new_ExpandFile()
211 ef->path = _new_PathName(); in new_ExpandFile()
212 if(!ef->path) in new_ExpandFile()
213 return del_ExpandFile(ef); in new_ExpandFile()
217 ef->home = _new_HomeDir(); in new_ExpandFile()
218 if(!ef->home) in new_ExpandFile()
219 return del_ExpandFile(ef); in new_ExpandFile()
223 ef->files_dim = MATCH_BLK_FACT; in new_ExpandFile()
224 ef->result.files = (char **) malloc(sizeof(ef->result.files[0]) * in new_ExpandFile()
225 ef->files_dim); in new_ExpandFile()
226 if(!ef->result.files) { in new_ExpandFile()
228 return del_ExpandFile(ef); in new_ExpandFile()
230 return ef; in new_ExpandFile()
241 ExpandFile *del_ExpandFile(ExpandFile *ef) in del_ExpandFile() argument
243 if(ef) { in del_ExpandFile()
248 ef->sg = _del_StringGroup(ef->sg); in del_ExpandFile()
252 for(dnode=ef->cache.head; dnode; dnode=dnode->next) in del_ExpandFile()
258 ef->cache.mem = _del_FreeList(ef->cache.mem, 1); in del_ExpandFile()
259 ef->cache.head = ef->cache.tail = ef->cache.next = NULL; in del_ExpandFile()
263 ef->path = _del_PathName(ef->path); in del_ExpandFile()
267 ef->home = _del_HomeDir(ef->home); in del_ExpandFile()
271 if(ef->result.files) { in del_ExpandFile()
272 free(ef->result.files); in del_ExpandFile()
273 ef->result.files = NULL; in del_ExpandFile()
278 ef->err = _del_ErrMsg(ef->err); in del_ExpandFile()
282 free(ef); in del_ExpandFile()
348 FileExpansion *ef_expand_file(ExpandFile *ef, const char *path, int pathlen) in ef_expand_file() argument
357 if(!ef || !path) { in ef_expand_file()
358 if(ef) { in ef_expand_file()
359 _err_record_msg(ef->err, "ef_expand_file: NULL path argument", in ef_expand_file()
374 ef_clear_files(ef); in ef_expand_file()
380 path = ef_expand_special(ef, path, pathlen); in ef_expand_file()
386 _pn_clear_path(ef->path); in ef_expand_file()
406 if(ef_record_pathname(ef, path, 1)) in ef_expand_file()
411 ef->result.exists = _pu_file_exists(ef->result.files[0]); in ef_expand_file()
420 ef->result.exists = 1; in ef_expand_file()
426 if(ef_record_pathname(ef, FS_ROOT_DIR, 0)) in ef_expand_file()
434 if(!_pn_append_to_path(ef->path, FS_ROOT_DIR, -1, 0)) { in ef_expand_file()
435 _err_record_msg(ef->err, "Insufficient memory to record path", in ef_expand_file()
446 dnode = ef_open_dir(ef, dirname); in ef_expand_file()
452 if(ef_match_relative_pathname(ef, dnode->dr, path, 0)) { in ef_expand_file()
453 dnode = ef_close_dir(ef, dnode); in ef_expand_file()
459 dnode = ef_close_dir(ef, dnode); in ef_expand_file()
464 if(ef->result.nfile < 1) { in ef_expand_file()
465 _err_record_msg(ef->err, "No files match", END_ERR_MSG); in ef_expand_file()
471 qsort(ef->result.files, ef->result.nfile, sizeof(ef->result.files[0]), in ef_expand_file()
477 return &ef->result; in ef_expand_file()
498 static int ef_match_relative_pathname(ExpandFile *ef, DirReader *dr, in ef_match_relative_pathname() argument
511 pathlen = strlen(ef->path->name); in ef_match_relative_pathname()
533 if((separate && _pn_append_to_path(ef->path, FS_DIR_SEP, -1, 0)==NULL) || in ef_match_relative_pathname()
534 _pn_append_to_path(ef->path, file, -1, 0)==NULL) { in ef_match_relative_pathname()
535 _err_record_msg(ef->err, "Insufficient memory to record path", in ef_match_relative_pathname()
544 if(ef_record_pathname(ef, ef->path->name, 0)) in ef_match_relative_pathname()
552 } else if(_pu_path_is_dir(ef->path->name) && in ef_match_relative_pathname()
559 if(ef_record_pathname(ef, ef->path->name, 0)) in ef_match_relative_pathname()
565 DirNode *subdnode = ef_open_dir(ef, ef->path->name); in ef_match_relative_pathname()
567 if(ef_match_relative_pathname(ef, subdnode->dr, in ef_match_relative_pathname()
569 subdnode = ef_close_dir(ef, subdnode); in ef_match_relative_pathname()
572 subdnode = ef_close_dir(ef, subdnode); in ef_match_relative_pathname()
580 ef->path->name[pathlen] = '\0'; in ef_match_relative_pathname()
599 static int ef_record_pathname(ExpandFile *ef, const char *pathname, in ef_record_pathname() argument
606 copy = ef_cache_pathname(ef, pathname, remove_escapes); in ef_record_pathname()
613 if(ef->result.nfile + 1 > ef->files_dim) { in ef_record_pathname()
614 int files_dim = ef->files_dim + MATCH_BLK_FACT; in ef_record_pathname()
615 char **files = (char **) realloc(ef->result.files, in ef_record_pathname()
618 _err_record_msg(ef->err, in ef_record_pathname()
624 ef->result.files = files; in ef_record_pathname()
625 ef->files_dim = files_dim; in ef_record_pathname()
630 ef->result.files[ef->result.nfile++] = copy; in ef_record_pathname()
647 static char *ef_cache_pathname(ExpandFile *ef, const char *pathname, in ef_cache_pathname() argument
650 char *copy = _sg_store_string(ef->sg, pathname, remove_escapes); in ef_cache_pathname()
652 _err_record_msg(ef->err, "Insufficient memory to store pathname", in ef_cache_pathname()
664 static void ef_clear_files(ExpandFile *ef) in ef_clear_files() argument
666 _clr_StringGroup(ef->sg); in ef_clear_files()
667 _pn_clear_path(ef->path); in ef_clear_files()
668 ef->result.exists = 0; in ef_clear_files()
669 ef->result.nfile = 0; in ef_clear_files()
670 _err_clear_msg(ef->err); in ef_clear_files()
685 static DirNode *ef_open_dir(ExpandFile *ef, const char *pathname) in ef_open_dir() argument
692 DirCache *cache = &ef->cache; in ef_open_dir()
699 _err_record_msg(ef->err, "Insufficient memory to open a new directory", in ef_open_dir()
714 _err_record_msg(ef->err, "Insufficient memory to open a new directory", in ef_open_dir()
737 _err_record_msg(ef->err, errmsg, END_ERR_MSG); in ef_open_dir()
771 static DirNode *ef_close_dir(ExpandFile *ef, DirNode *node) in ef_close_dir() argument
776 DirCache *cache = &ef->cache; in ef_close_dir()
1043 static char *ef_expand_special(ExpandFile *ef, const char *path, int pathlen) in ef_expand_special() argument
1054 _pn_clear_path(ef->path); in ef_expand_special()
1073 if(spos < ppos && _pn_append_to_path(ef->path, path + spos, ppos-spos, 0) in ef_expand_special()
1075 _err_record_msg(ef->err, "Insufficient memory to expand path", in ef_expand_special()
1090 ef->envnam[envlen] = path[ppos++]; in ef_expand_special()
1097 _err_record_msg(ef->err, "Environment variable name too long", in ef_expand_special()
1104 ef->envnam[envlen] = '\0'; in ef_expand_special()
1108 value = getenv(ef->envnam); in ef_expand_special()
1110 _err_record_msg(ef->err, "No expansion found for: $", ef->envnam, in ef_expand_special()
1117 if(_pn_append_to_path(ef->path, value, -1, 0) == NULL) { in ef_expand_special()
1118 _err_record_msg(ef->err, "Insufficient memory to expand path", in ef_expand_special()
1131 if(spos < ppos && _pn_append_to_path(ef->path, path + spos, ppos-spos, 0) in ef_expand_special()
1133 _err_record_msg(ef->err, "Insufficient memory to expand path", END_ERR_MSG); in ef_expand_special()
1140 pptr = ef->path->name; in ef_expand_special()
1150 plen = strlen(ef->path->name); in ef_expand_special()
1160 ef->usrnam[usrlen] = *pptr++; in ef_expand_special()
1167 _err_record_msg(ef->err, "Username too long", END_ERR_MSG); in ef_expand_special()
1173 ef->usrnam[usrlen] = '\0'; in ef_expand_special()
1177 homedir = _hd_lookup_home_dir(ef->home, ef->usrnam); in ef_expand_special()
1179 _err_record_msg(ef->err, _hd_last_home_dir_error(ef->home), END_ERR_MSG); in ef_expand_special()
1199 if(_pn_resize_path(ef->path, plen - usrlen - 1 - skip + homelen)==NULL) { in ef_expand_special()
1200 _err_record_msg(ef->err, "Insufficient memory to expand filename", in ef_expand_special()
1208 memmove(ef->path->name + homelen, in ef_expand_special()
1209 ef->path->name + 1 + usrlen + skip, plen - usrlen - 1 - skip+1); in ef_expand_special()
1214 ef->path->name[i] = homedir[i]; in ef_expand_special()
1219 return ef_cache_pathname(ef, ef->path->name, 0); in ef_expand_special()
1230 const char *ef_last_error(ExpandFile *ef) in ef_last_error() argument
1232 return ef ? _err_get_msg(ef->err) : "NULL ExpandFile argument"; in ef_last_error()