Lines Matching refs:pc

69   PathCache *pc;   /* The path-list cache in which to look up the executables */  member
136 static int add_PathNode(PathCache *pc, const char *dirname);
172 static void pca_clear_cache(PathCache *pc);
177 static int pca_read_username(PathCache *pc, const char *string, int slen,
184 static int pca_extract_dir(PathCache *pc, const char *path,
191 static int pca_scan_dir(PathCache *pc, const char *dirname, CacheMem *mem);
211 static int pca_init_PcaPathConf(PcaPathConf *ppc, PathCache *pc);
217 static int pca_prepare_suffix(PathCache *pc, const char *suffix,
228 static const char *pca_prepare_prefix(PathCache *pc, const char *prefix,
236 static int pca_expand_tilde(PathCache *pc, const char *path, int pathlen,
243 static void pca_remove_marks(PathCache *pc);
267 PathCache *pc; /* The object to be returned */ in new_PathCache() local
271 pc = (PathCache *)malloc(sizeof(PathCache)); in new_PathCache()
272 if(!pc) { in new_PathCache()
281 pc->err = NULL; in new_PathCache()
282 pc->node_mem = NULL; in new_PathCache()
283 pc->abs_mem = NULL; in new_PathCache()
284 pc->rel_mem = NULL; in new_PathCache()
285 pc->head = NULL; in new_PathCache()
286 pc->tail = NULL; in new_PathCache()
287 pc->path = NULL; in new_PathCache()
288 pc->home = NULL; in new_PathCache()
289 pc->dr = NULL; in new_PathCache()
290 pc->cfc = NULL; in new_PathCache()
291 pc->check_fn = 0; in new_PathCache()
292 pc->data = NULL; in new_PathCache()
293 pc->usrnam[0] = '\0'; in new_PathCache()
297 pc->err = _new_ErrMsg(); in new_PathCache()
298 if(!pc->err) in new_PathCache()
299 return del_PathCache(pc); in new_PathCache()
303 pc->node_mem = _new_FreeList(sizeof(PathNode), PATH_NODE_BLK); in new_PathCache()
304 if(!pc->node_mem) in new_PathCache()
305 return del_PathCache(pc); in new_PathCache()
309 pc->abs_mem = new_CacheMem(); in new_PathCache()
310 if(!pc->abs_mem) in new_PathCache()
311 return del_PathCache(pc); in new_PathCache()
315 pc->rel_mem = new_CacheMem(); in new_PathCache()
316 if(!pc->rel_mem) in new_PathCache()
317 return del_PathCache(pc); in new_PathCache()
321 pc->path = _new_PathName(); in new_PathCache()
322 if(!pc->path) in new_PathCache()
323 return del_PathCache(pc); in new_PathCache()
327 pc->home = _new_HomeDir(); in new_PathCache()
328 if(!pc->home) in new_PathCache()
329 return del_PathCache(pc); in new_PathCache()
333 pc->dr = _new_DirReader(); in new_PathCache()
334 if(!pc->dr) in new_PathCache()
335 return del_PathCache(pc); in new_PathCache()
339 pc->cfc = new_CplFileConf(); in new_PathCache()
340 if(!pc->cfc) in new_PathCache()
341 return del_PathCache(pc); in new_PathCache()
346 cfc_set_check_fn(pc->cfc, pc->check_fn, pc->data); in new_PathCache()
350 return pc; in new_PathCache()
362 PathCache *del_PathCache(PathCache *pc) in del_PathCache() argument
364 if(pc) { in del_PathCache()
368 pc->err = _del_ErrMsg(pc->err); in del_PathCache()
372 pc->node_mem = _del_FreeList(pc->node_mem, 1); in del_PathCache()
376 pc->abs_mem = del_CacheMem(pc->abs_mem); in del_PathCache()
377 pc->rel_mem = del_CacheMem(pc->rel_mem); in del_PathCache()
382 pc->head = NULL; in del_PathCache()
383 pc->tail = NULL; in del_PathCache()
387 pc->path = _del_PathName(pc->path); in del_PathCache()
391 pc->home = _del_HomeDir(pc->home); in del_PathCache()
395 pc->dr = _del_DirReader(pc->dr); in del_PathCache()
399 pc->cfc = del_CplFileConf(pc->cfc); in del_PathCache()
403 free(pc); in del_PathCache()
430 void pca_set_check_fn(PathCache *pc, CplCheckFn *check_fn, void *data) in pca_set_check_fn() argument
432 if(pc) { in pca_set_check_fn()
438 if(check_fn != pc->check_fn || data != pc->data) in pca_set_check_fn()
439 pca_remove_marks(pc); in pca_set_check_fn()
443 pc->check_fn = check_fn; in pca_set_check_fn()
444 pc->data = data; in pca_set_check_fn()
449 cfc_set_check_fn(pc->cfc, check_fn, data); in pca_set_check_fn()
462 const char *pca_last_error(PathCache *pc) in pca_last_error() argument
464 return pc ? _err_get_msg(pc->err) : "NULL PathCache argument"; in pca_last_error()
473 static void pca_clear_cache(PathCache *pc) in pca_clear_cache() argument
475 if(pc) { in pca_clear_cache()
479 _rst_FreeList(pc->node_mem); in pca_clear_cache()
480 pc->head = pc->tail = NULL; in pca_clear_cache()
484 rst_CacheMem(pc->abs_mem); in pca_clear_cache()
485 rst_CacheMem(pc->rel_mem); in pca_clear_cache()
508 int pca_scan_path(PathCache *pc, const char *path) in pca_scan_path() argument
516 if(!pc) in pca_scan_path()
521 pca_clear_cache(pc); in pca_scan_path()
539 if(pca_extract_dir(pc, pptr, &pptr)) in pca_scan_path()
546 if(add_PathNode(pc, pc->path->name)) in pca_scan_path()
557 fptr = pc->abs_mem->files; in pca_scan_path()
558 for(node=pc->head; node; node=node->next) { in pca_scan_path()
581 static int pca_extract_dir(PathCache *pc, const char *path, const char **nextp) in pca_extract_dir() argument
591 if(pca_expand_tilde(pc, path, strlen(path), 0, &pptr)) in pca_extract_dir()
607 if(_pn_append_to_path(pc->path, sptr, pptr - sptr, 1) == NULL) { in pca_extract_dir()
608 _err_record_msg(pc->err, "Insufficient memory to record directory name", in pca_extract_dir()
618 int dirlen = strlen(pc->path->name); in pca_extract_dir()
620 strncmp(pc->path->name + dirlen - FS_DIR_SEP_LEN, FS_DIR_SEP, in pca_extract_dir()
622 if(_pn_append_to_path(pc->path, FS_DIR_SEP, FS_DIR_SEP_LEN, 0) == NULL) { in pca_extract_dir()
623 _err_record_msg(pc->err, "Insufficient memory to record directory name", in pca_extract_dir()
660 static int pca_read_username(PathCache *pc, const char *string, int slen, in pca_read_username() argument
684 pc->usrnam[usrlen++] = *sptr; in pca_read_username()
691 _err_record_msg(pc->err, "Username too long", END_ERR_MSG); in pca_read_username()
697 pc->usrnam[usrlen] = '\0'; in pca_read_username()
806 static int add_PathNode(PathCache *pc, const char *dirname) in add_PathNode() argument
823 node = (PathNode *) _new_FreeListNode(pc->node_mem); in add_PathNode()
825 _err_record_msg(pc->err, "Insufficient memory to cache new directory.", in add_PathNode()
834 node->mem = relative ? pc->rel_mem : pc->abs_mem; in add_PathNode()
841 node->dir = _sg_store_string(pc->abs_mem->sg, dirname, 0); in add_PathNode()
843 _err_record_msg(pc->err, "Insufficient memory to store directory name.", in add_PathNode()
853 int nfile = node->nfile = pca_scan_dir(pc, node->dir, node->mem); in add_PathNode()
855 node = (PathNode *) _del_FreeListNode(pc->node_mem, node); in add_PathNode()
862 if(pc->head) { in add_PathNode()
863 pc->tail->next = node; in add_PathNode()
864 pc->tail = node; in add_PathNode()
866 pc->head = pc->tail = node; in add_PathNode()
886 static int pca_scan_dir(PathCache *pc, const char *dirname, CacheMem *mem) in pca_scan_dir() argument
894 if(_dr_open_dir(pc->dr, dirname, NULL)) in pca_scan_dir()
899 while((filename = _dr_next_file(pc->dr))) { in pca_scan_dir()
904 _pn_clear_path(pc->path); in pca_scan_dir()
905 if(_pn_append_to_path(pc->path, " ", 1, 0) == NULL || in pca_scan_dir()
906 _pn_append_to_path(pc->path, filename, -1, 1) == NULL) { in pca_scan_dir()
907 _err_record_msg(pc->err, "Insufficient memory to record filename", in pca_scan_dir()
914 copy = _sg_store_string(mem->sg, pc->path->name, 0); in pca_scan_dir()
916 _err_record_msg(pc->err, "Insufficient memory to cache file name.", in pca_scan_dir()
931 _err_record_msg(pc->err, in pca_scan_dir()
1010 char *pca_lookup_file(PathCache *pc, const char *name, int name_len, in pca_lookup_file() argument
1018 if(!pc || !name || name_len==0) in pca_lookup_file()
1036 if(pca_expand_tilde(pc, name, name_len, literal, &nptr) || in pca_lookup_file()
1037 _pn_append_to_path(pc->path, nptr, name_len - (nptr-name), in pca_lookup_file()
1040 return pc->path->name; in pca_lookup_file()
1047 for(node=pc->head; node; node=node->next) { in pca_lookup_file()
1054 if(pca_scan_dir(pc, node->dir, node->mem) < 1) in pca_lookup_file()
1063 _pn_clear_path(pc->path); in pca_lookup_file()
1064 if(_pn_append_to_path(pc->path, name, name_len, !literal) == NULL) in pca_lookup_file()
1069 match = (char **)bsearch(pc->path->name, node->files, node->nfile, in pca_lookup_file()
1076 if(_pn_prepend_to_path(pc->path, node->dir, -1, 0) == NULL) in pca_lookup_file()
1081 if(!pc->check_fn || (*match)[0] == PCA_F_WANTED || in pca_lookup_file()
1082 ((*match)[0]==PCA_F_ENIGMA && pc->check_fn(pc->data, pc->path->name))){ in pca_lookup_file()
1084 return pc->path->name; in pca_lookup_file()
1133 PcaPathConf *new_PcaPathConf(PathCache *pc) in new_PcaPathConf() argument
1139 if(!pc) in new_PcaPathConf()
1146 _err_record_msg(pc->err, "Insufficient memory.", END_ERR_MSG); in new_PcaPathConf()
1154 if(pca_init_PcaPathConf(ppc, pc)) in new_PcaPathConf()
1170 static int pca_init_PcaPathConf(PcaPathConf *ppc, PathCache *pc) in pca_init_PcaPathConf() argument
1175 if(!pc) in pca_init_PcaPathConf()
1181 ppc->pc = pc; in pca_init_PcaPathConf()
1198 ppc->pc = NULL; /* It is up to the caller to delete the cache */ in del_PcaPathConf()
1216 PathCache *pc; /* The cache in which to look for completions */ in CPL_MATCH_FN() local
1251 pc = ppc->pc; in CPL_MATCH_FN()
1280 cfc_file_start(pc->cfc, word_start); in CPL_MATCH_FN()
1281 return cpl_file_completions(cpl, pc->cfc, line, word_end); in CPL_MATCH_FN()
1288 for(node=pc->head; node; node=node->next) { in CPL_MATCH_FN()
1295 if(pca_scan_dir(pc, node->dir, node->mem) < 1) in CPL_MATCH_FN()
1306 prefix = pca_prepare_prefix(pc, start_path, prefix_len, ppc->escaped); in CPL_MATCH_FN()
1350 _pn_clear_path(pc->path); in CPL_MATCH_FN()
1351 if(_pn_append_to_path(pc->path, node->dir, -1, 0) == NULL || in CPL_MATCH_FN()
1352 _pn_append_to_path(pc->path, match+1, -1, 0) == NULL) { in CPL_MATCH_FN()
1353 _err_record_msg(pc->err, "Insufficient memory to complete file name", in CPL_MATCH_FN()
1360 if(!pc->check_fn || match[0] == PCA_F_WANTED || in CPL_MATCH_FN()
1361 (match[0]==PCA_F_ENIGMA && pc->check_fn(pc->data, pc->path->name))) { in CPL_MATCH_FN()
1367 if(pca_prepare_suffix(pc, match + 1 + prefix_len, in CPL_MATCH_FN()
1373 if(cpl_add_completion(cpl, line, word_start, word_end, pc->path->name, in CPL_MATCH_FN()
1390 prefix = pca_prepare_prefix(pc, start_path, prefix_len, ppc->escaped); in CPL_MATCH_FN()
1396 if(_dr_open_dir(pc->dr, FS_PWD, NULL)) in CPL_MATCH_FN()
1402 while((filename = _dr_next_file(pc->dr))) { in CPL_MATCH_FN()
1410 if(pca_prepare_suffix(pc, filename + prefix_len, ppc->escaped) || in CPL_MATCH_FN()
1411 cpl_add_completion(cpl, line, word_start, word_end, pc->path->name, in CPL_MATCH_FN()
1418 prefix = pca_prepare_prefix(pc, start_path, prefix_len, ppc->escaped); in CPL_MATCH_FN()
1423 _dr_close_dir(pc->dr); in CPL_MATCH_FN()
1439 static int pca_prepare_suffix(PathCache *pc, const char *suffix, in pca_prepare_suffix() argument
1452 _pn_clear_path(pc->path); in pca_prepare_suffix()
1471 if(_pn_resize_path(pc->path, suffix_len + nbsl) == NULL) { in pca_prepare_suffix()
1472 _err_record_msg(pc->err, "Insufficient memory to complete file name", in pca_prepare_suffix()
1481 strlcpy(pc->path->name, suffix, pc->path->dim); in pca_prepare_suffix()
1488 char *dst = pc->path->name; in pca_prepare_suffix()
1559 static const char *pca_prepare_prefix(PathCache *pc, const char *prefix, in pca_prepare_prefix() argument
1566 _pn_clear_path(pc->path); in pca_prepare_prefix()
1567 if(_pn_append_to_path(pc->path, prefix, prefix_len, 1) == NULL) { in pca_prepare_prefix()
1568 _err_record_msg(pc->err, "Insufficient memory to complete filename", in pca_prepare_prefix()
1572 return pc->path->name; in pca_prepare_prefix()
1634 static int pca_expand_tilde(PathCache *pc, const char *path, int pathlen, in pca_expand_tilde() argument
1642 _pn_clear_path(pc->path); in pca_expand_tilde()
1652 if(pca_read_username(pc, ++pptr, pathlen-1, literal, &pptr)) in pca_expand_tilde()
1657 homedir = _hd_lookup_home_dir(pc->home, pc->usrnam); in pca_expand_tilde()
1659 _err_record_msg(pc->err, _hd_last_home_dir_error(pc->home), END_ERR_MSG); in pca_expand_tilde()
1665 if(_pn_append_to_path(pc->path, homedir, -1, 0) == NULL) { in pca_expand_tilde()
1666 _err_record_msg(pc->err, in pca_expand_tilde()
1698 static void pca_remove_marks(PathCache *pc) in pca_remove_marks() argument
1706 for(node=pc->head; node; node=node->next) { in pca_remove_marks()