This class holds a list of directory paths and provides functions to locate files with given relative paths under these. The semantics is suitable for implementing search paths similar to the compiler's -I flags or environment variables like $PATH, $PYTHONPATH, etc.
cu_bool_t cuos_dirpile_append | ( | cuos_dirpile_t | pile, | |
cu_str_t | dir | |||
) |
If dir exists, add it to the bottom of pile and return true, else return false.
cu_bool_t cuos_dirpile_append_cstr | ( | cuos_dirpile_t | pile, | |
char const * | dir | |||
) |
If dir exists, add it to the bottom of pile and return true, else return false.
cu_str_t cuos_dirpile_first_match | ( | cuos_dirpile_t | pile, | |
cu_str_t | rel_path | |||
) |
Returns the full path of the first file or directory with a path rel_path relative to a top-level path of pile, or NULL
if no such file or directory exists.
void cuos_dirpile_init | ( | cuos_dirpile_t | pile | ) |
Initialise an empty pile of directories.
void cuos_dirpile_init_sub | ( | cuos_dirpile_t | new_pile, | |
cuos_dirpile_t | src_pile, | |||
cu_str_t | src_subdir | |||
) |
Initialise new_pile with the existing subdirectories src_subdir of src_pile in the order of occurence in src_pile.
cu_bool_t cuos_dirpile_insert | ( | cuos_dirpile_t | pile, | |
cu_str_t | dir, | |||
cu_bool_t | on_top | |||
) |
If dir exists, add it to pile and return true, else return false. If on_top, then dir will be tried before the current list, otherwise after.
cu_bool_t cuos_dirpile_insert_cstr | ( | cuos_dirpile_t | pile, | |
char const * | dir, | |||
cu_bool_t | on_top | |||
) |
If dir exists, add it to pile and return true, else return false. If on_top, then dir will be tried before the current list, otherwise after.
int cuos_dirpile_insert_env | ( | cuos_dirpile_t | pile, | |
cu_bool_t | on_top, | |||
char const * | var, | |||
cu_str_t | subdir | |||
) |
Add the existing subdirectories subdir of directories from the colon-separated directories in var to pile. If subdir is NULL
, "." is used. If on_top, then the added directories will be tried before the current list, otherwise after. Returns -1 if envvar is unset, otherwise the number of inserted directories.
cu_bool_t cuos_dirpile_insert_envvar | ( | cuos_dirpile_t | pile, | |
char const * | var, | |||
cu_bool_t | on_top | |||
) |
NULL
for subdir. cu_bool_t cuos_dirpile_iterA_matches | ( | cuos_dirpile_t | pile, | |
cu_clop(f, cu_bool_t, cu_str_t) | , | |||
cu_str_t | rel_path | |||
) |
Calls f with the full path of each existing file or directory with a path rel_path relative to a top-level path of pile in order. Stops and returns false as soon as f returns false, else returns true.
cu_bool_t cuos_dirpile_iterA_top | ( | cuos_dirpile_t | pile, | |
cu_clop(f, cu_bool_t, cu_str_t) | ||||
) |
Calls f with each top-level directory of pile in order. Stops the iteration and returns false if f returns false, else returns true.
cuos_dirpile_t cuos_dirpile_new | ( | void | ) |
Returns an empty pile of directories.
cuos_dirpile_t cuos_dirpile_new_sub | ( | cuos_dirpile_t | src_pile, | |
cu_str_t | src_subdir | |||
) |
Return a dirpile of the existing subdirectories src_subdir of src_pile in the order of occurrence in src_pile.