Lines Matching refs:pc

71   PathCache *pc;   /* The path-list cache in which to look up the executables */  member
138 static int add_PathNode(PathCache *pc, const char *dirname);
174 static void pca_clear_cache(PathCache *pc);
179 static int pca_read_username(PathCache *pc, const char *string, int slen,
186 static int pca_extract_dir(PathCache *pc, const char *path,
193 static int pca_scan_dir(PathCache *pc, const char *dirname, CacheMem *mem);
213 static int pca_init_PcaPathConf(PcaPathConf *ppc, PathCache *pc);
219 static int pca_prepare_suffix(PathCache *pc, const char *suffix,
230 static const char *pca_prepare_prefix(PathCache *pc, const char *prefix,
238 static int pca_expand_tilde(PathCache *pc, const char *path, int pathlen,
245 static void pca_remove_marks(PathCache *pc);
269 PathCache *pc; /* The object to be returned */ in new_PathCache() local
273 pc = (PathCache *)malloc(sizeof(PathCache)); in new_PathCache()
274 if(!pc) { in new_PathCache()
283 pc->err = NULL; in new_PathCache()
284 pc->node_mem = NULL; in new_PathCache()
285 pc->abs_mem = NULL; in new_PathCache()
286 pc->rel_mem = NULL; in new_PathCache()
287 pc->head = NULL; in new_PathCache()
288 pc->tail = NULL; in new_PathCache()
289 pc->path = NULL; in new_PathCache()
290 pc->home = NULL; in new_PathCache()
291 pc->dr = NULL; in new_PathCache()
292 pc->cfc = NULL; in new_PathCache()
293 pc->check_fn = 0; in new_PathCache()
294 pc->data = NULL; in new_PathCache()
295 pc->usrnam[0] = '\0'; in new_PathCache()
299 pc->err = _new_ErrMsg(); in new_PathCache()
300 if(!pc->err) in new_PathCache()
301 return del_PathCache(pc); in new_PathCache()
305 pc->node_mem = _new_FreeList(sizeof(PathNode), PATH_NODE_BLK); in new_PathCache()
306 if(!pc->node_mem) in new_PathCache()
307 return del_PathCache(pc); in new_PathCache()
311 pc->abs_mem = new_CacheMem(); in new_PathCache()
312 if(!pc->abs_mem) in new_PathCache()
313 return del_PathCache(pc); in new_PathCache()
317 pc->rel_mem = new_CacheMem(); in new_PathCache()
318 if(!pc->rel_mem) in new_PathCache()
319 return del_PathCache(pc); in new_PathCache()
323 pc->path = _new_PathName(); in new_PathCache()
324 if(!pc->path) in new_PathCache()
325 return del_PathCache(pc); in new_PathCache()
329 pc->home = _new_HomeDir(); in new_PathCache()
330 if(!pc->home) in new_PathCache()
331 return del_PathCache(pc); in new_PathCache()
335 pc->dr = _new_DirReader(); in new_PathCache()
336 if(!pc->dr) in new_PathCache()
337 return del_PathCache(pc); in new_PathCache()
341 pc->cfc = new_CplFileConf(); in new_PathCache()
342 if(!pc->cfc) in new_PathCache()
343 return del_PathCache(pc); in new_PathCache()
348 cfc_set_check_fn(pc->cfc, pc->check_fn, pc->data); in new_PathCache()
352 return pc; in new_PathCache()
364 PathCache *del_PathCache(PathCache *pc) in del_PathCache() argument
366 if(pc) { in del_PathCache()
370 pc->err = _del_ErrMsg(pc->err); in del_PathCache()
374 pc->node_mem = _del_FreeList(pc->node_mem, 1); in del_PathCache()
378 pc->abs_mem = del_CacheMem(pc->abs_mem); in del_PathCache()
379 pc->rel_mem = del_CacheMem(pc->rel_mem); in del_PathCache()
384 pc->head = NULL; in del_PathCache()
385 pc->tail = NULL; in del_PathCache()
389 pc->path = _del_PathName(pc->path); in del_PathCache()
393 pc->home = _del_HomeDir(pc->home); in del_PathCache()
397 pc->dr = _del_DirReader(pc->dr); in del_PathCache()
401 pc->cfc = del_CplFileConf(pc->cfc); in del_PathCache()
405 free(pc); in del_PathCache()
432 void pca_set_check_fn(PathCache *pc, CplCheckFn *check_fn, void *data) in pca_set_check_fn() argument
434 if(pc) { in pca_set_check_fn()
440 if(check_fn != pc->check_fn || data != pc->data) in pca_set_check_fn()
441 pca_remove_marks(pc); in pca_set_check_fn()
445 pc->check_fn = check_fn; in pca_set_check_fn()
446 pc->data = data; in pca_set_check_fn()
451 cfc_set_check_fn(pc->cfc, check_fn, data); in pca_set_check_fn()
464 const char *pca_last_error(PathCache *pc) in pca_last_error() argument
466 return pc ? _err_get_msg(pc->err) : "NULL PathCache argument"; in pca_last_error()
475 static void pca_clear_cache(PathCache *pc) in pca_clear_cache() argument
477 if(pc) { in pca_clear_cache()
481 _rst_FreeList(pc->node_mem); in pca_clear_cache()
482 pc->head = pc->tail = NULL; in pca_clear_cache()
486 rst_CacheMem(pc->abs_mem); in pca_clear_cache()
487 rst_CacheMem(pc->rel_mem); in pca_clear_cache()
510 int pca_scan_path(PathCache *pc, const char *path) in pca_scan_path() argument
518 if(!pc) in pca_scan_path()
523 pca_clear_cache(pc); in pca_scan_path()
541 if(pca_extract_dir(pc, pptr, &pptr)) in pca_scan_path()
548 if(add_PathNode(pc, pc->path->name)) in pca_scan_path()
559 fptr = pc->abs_mem->files; in pca_scan_path()
560 for(node=pc->head; node; node=node->next) { in pca_scan_path()
583 static int pca_extract_dir(PathCache *pc, const char *path, const char **nextp) in pca_extract_dir() argument
593 if(pca_expand_tilde(pc, path, strlen(path), 0, &pptr)) in pca_extract_dir()
609 if(_pn_append_to_path(pc->path, sptr, pptr - sptr, 1) == NULL) { in pca_extract_dir()
610 _err_record_msg(pc->err, "Insufficient memory to record directory name", in pca_extract_dir()
620 int dirlen = strlen(pc->path->name); in pca_extract_dir()
622 strncmp(pc->path->name + dirlen - FS_DIR_SEP_LEN, FS_DIR_SEP, in pca_extract_dir()
624 if(_pn_append_to_path(pc->path, FS_DIR_SEP, FS_DIR_SEP_LEN, 0) == NULL) { in pca_extract_dir()
625 _err_record_msg(pc->err, "Insufficient memory to record directory name", in pca_extract_dir()
662 static int pca_read_username(PathCache *pc, const char *string, int slen, in pca_read_username() argument
686 pc->usrnam[usrlen++] = *sptr; in pca_read_username()
693 _err_record_msg(pc->err, "Username too long", END_ERR_MSG); in pca_read_username()
699 pc->usrnam[usrlen] = '\0'; in pca_read_username()
808 static int add_PathNode(PathCache *pc, const char *dirname) in add_PathNode() argument
825 node = (PathNode *) _new_FreeListNode(pc->node_mem); in add_PathNode()
827 _err_record_msg(pc->err, "Insufficient memory to cache new directory.", in add_PathNode()
836 node->mem = relative ? pc->rel_mem : pc->abs_mem; in add_PathNode()
843 node->dir = _sg_store_string(pc->abs_mem->sg, dirname, 0); in add_PathNode()
845 _err_record_msg(pc->err, "Insufficient memory to store directory name.", in add_PathNode()
855 int nfile = node->nfile = pca_scan_dir(pc, node->dir, node->mem); in add_PathNode()
857 node = (PathNode *) _del_FreeListNode(pc->node_mem, node); in add_PathNode()
864 if(pc->head) { in add_PathNode()
865 pc->tail->next = node; in add_PathNode()
866 pc->tail = node; in add_PathNode()
868 pc->head = pc->tail = node; in add_PathNode()
888 static int pca_scan_dir(PathCache *pc, const char *dirname, CacheMem *mem) in pca_scan_dir() argument
896 if(_dr_open_dir(pc->dr, dirname, NULL)) in pca_scan_dir()
901 while((filename = _dr_next_file(pc->dr))) { in pca_scan_dir()
906 _pn_clear_path(pc->path); in pca_scan_dir()
907 if(_pn_append_to_path(pc->path, " ", 1, 0) == NULL || in pca_scan_dir()
908 _pn_append_to_path(pc->path, filename, -1, 1) == NULL) { in pca_scan_dir()
909 _err_record_msg(pc->err, "Insufficient memory to record filename", in pca_scan_dir()
916 copy = _sg_store_string(mem->sg, pc->path->name, 0); in pca_scan_dir()
918 _err_record_msg(pc->err, "Insufficient memory to cache file name.", in pca_scan_dir()
933 _err_record_msg(pc->err, in pca_scan_dir()
1012 char *pca_lookup_file(PathCache *pc, const char *name, int name_len, in pca_lookup_file() argument
1020 if(!pc || !name || name_len==0) in pca_lookup_file()
1038 if(pca_expand_tilde(pc, name, name_len, literal, &nptr) || in pca_lookup_file()
1039 _pn_append_to_path(pc->path, nptr, name_len - (nptr-name), in pca_lookup_file()
1042 return pc->path->name; in pca_lookup_file()
1049 for(node=pc->head; node; node=node->next) { in pca_lookup_file()
1056 if(pca_scan_dir(pc, node->dir, node->mem) < 1) in pca_lookup_file()
1065 _pn_clear_path(pc->path); in pca_lookup_file()
1066 if(_pn_append_to_path(pc->path, name, name_len, !literal) == NULL) in pca_lookup_file()
1071 match = (char **)bsearch(pc->path->name, node->files, node->nfile, in pca_lookup_file()
1078 if(_pn_prepend_to_path(pc->path, node->dir, -1, 0) == NULL) in pca_lookup_file()
1083 if(!pc->check_fn || (*match)[0] == PCA_F_WANTED || in pca_lookup_file()
1084 ((*match)[0]==PCA_F_ENIGMA && pc->check_fn(pc->data, pc->path->name))){ in pca_lookup_file()
1086 return pc->path->name; in pca_lookup_file()
1135 PcaPathConf *new_PcaPathConf(PathCache *pc) in new_PcaPathConf() argument
1141 if(!pc) in new_PcaPathConf()
1148 _err_record_msg(pc->err, "Insufficient memory.", END_ERR_MSG); in new_PcaPathConf()
1156 if(pca_init_PcaPathConf(ppc, pc)) in new_PcaPathConf()
1172 static int pca_init_PcaPathConf(PcaPathConf *ppc, PathCache *pc) in pca_init_PcaPathConf() argument
1177 if(!pc) in pca_init_PcaPathConf()
1183 ppc->pc = pc; in pca_init_PcaPathConf()
1200 ppc->pc = NULL; /* It is up to the caller to delete the cache */ in del_PcaPathConf()
1218 PathCache *pc; /* The cache in which to look for completions */ in CPL_MATCH_FN() local
1253 pc = ppc->pc; in CPL_MATCH_FN()
1282 cfc_file_start(pc->cfc, word_start); in CPL_MATCH_FN()
1283 return cpl_file_completions(cpl, pc->cfc, line, word_end); in CPL_MATCH_FN()
1290 for(node=pc->head; node; node=node->next) { in CPL_MATCH_FN()
1297 if(pca_scan_dir(pc, node->dir, node->mem) < 1) in CPL_MATCH_FN()
1308 prefix = pca_prepare_prefix(pc, start_path, prefix_len, ppc->escaped); in CPL_MATCH_FN()
1352 _pn_clear_path(pc->path); in CPL_MATCH_FN()
1353 if(_pn_append_to_path(pc->path, node->dir, -1, 0) == NULL || in CPL_MATCH_FN()
1354 _pn_append_to_path(pc->path, match+1, -1, 0) == NULL) { in CPL_MATCH_FN()
1355 _err_record_msg(pc->err, "Insufficient memory to complete file name", in CPL_MATCH_FN()
1362 if(!pc->check_fn || match[0] == PCA_F_WANTED || in CPL_MATCH_FN()
1363 (match[0]==PCA_F_ENIGMA && pc->check_fn(pc->data, pc->path->name))) { in CPL_MATCH_FN()
1369 if(pca_prepare_suffix(pc, match + 1 + prefix_len, in CPL_MATCH_FN()
1375 if(cpl_add_completion(cpl, line, word_start, word_end, pc->path->name, in CPL_MATCH_FN()
1392 prefix = pca_prepare_prefix(pc, start_path, prefix_len, ppc->escaped); in CPL_MATCH_FN()
1398 if(_dr_open_dir(pc->dr, FS_PWD, NULL)) in CPL_MATCH_FN()
1404 while((filename = _dr_next_file(pc->dr))) { in CPL_MATCH_FN()
1412 if(pca_prepare_suffix(pc, filename + prefix_len, ppc->escaped) || in CPL_MATCH_FN()
1413 cpl_add_completion(cpl, line, word_start, word_end, pc->path->name, in CPL_MATCH_FN()
1420 prefix = pca_prepare_prefix(pc, start_path, prefix_len, ppc->escaped); in CPL_MATCH_FN()
1425 _dr_close_dir(pc->dr); in CPL_MATCH_FN()
1441 static int pca_prepare_suffix(PathCache *pc, const char *suffix, in pca_prepare_suffix() argument
1454 _pn_clear_path(pc->path); in pca_prepare_suffix()
1473 if(_pn_resize_path(pc->path, suffix_len + nbsl) == NULL) { in pca_prepare_suffix()
1474 _err_record_msg(pc->err, "Insufficient memory to complete file name", in pca_prepare_suffix()
1483 strlcpy(pc->path->name, suffix, pc->path->dim); in pca_prepare_suffix()
1490 char *dst = pc->path->name; in pca_prepare_suffix()
1561 static const char *pca_prepare_prefix(PathCache *pc, const char *prefix, in pca_prepare_prefix() argument
1568 _pn_clear_path(pc->path); in pca_prepare_prefix()
1569 if(_pn_append_to_path(pc->path, prefix, prefix_len, 1) == NULL) { in pca_prepare_prefix()
1570 _err_record_msg(pc->err, "Insufficient memory to complete filename", in pca_prepare_prefix()
1574 return pc->path->name; in pca_prepare_prefix()
1636 static int pca_expand_tilde(PathCache *pc, const char *path, int pathlen, in pca_expand_tilde() argument
1644 _pn_clear_path(pc->path); in pca_expand_tilde()
1654 if(pca_read_username(pc, ++pptr, pathlen-1, literal, &pptr)) in pca_expand_tilde()
1659 homedir = _hd_lookup_home_dir(pc->home, pc->usrnam); in pca_expand_tilde()
1661 _err_record_msg(pc->err, _hd_last_home_dir_error(pc->home), END_ERR_MSG); in pca_expand_tilde()
1667 if(_pn_append_to_path(pc->path, homedir, -1, 0) == NULL) { in pca_expand_tilde()
1668 _err_record_msg(pc->err, in pca_expand_tilde()
1700 static void pca_remove_marks(PathCache *pc) in pca_remove_marks() argument
1708 for(node=pc->head; node; node=node->next) { in pca_remove_marks()