Go to the source code of this file.
Functions | |
int | mbs_unix_separator (char *path) |
In-place replacement of windows-style path separator (\ ) by Unix separator (/ ). More... | |
char * | find_user_path (const char *mbsfile) |
Find the user folder corresponding to the given *.mbs file. More... | |
int | find_project_path (const char *mbsfile, char *prjpath) |
Find the project directory (containing dataR, symbolicR, ...) from Mbs filepath. More... | |
char * | find_project_path_from_cwd (const char *optionnal_path, int verbose) |
Find the project directory from current working directory (cwd) or provided path. More... | |
char * | explore_dir_for_project_path (const char *optionnal_path, int verbose) |
Find the project directory from current working directory (cwd) or provided path. More... | |
char * | mbs_basename (const char *path, int verbose) |
mbs_basename returns the trailing part of the path (UNIX and MAC). More... | |
char * | mbs_dirname (const char *path, int verbose) |
mbs_dirname returns the leading part of the path (UNIX and MAC). More... | |
int | mbs_splitext (const char *path, char **root, char **ext) |
Split the path into a pair (root, ext). More... | |
int | remove_prjpath (char **path, char *project_source_dir) |
If the path start with PRJPATH, an new path is allocated replacing it. More... | |
char * | mbs_getcwd () |
Return the Current Working Directory (cwd). More... | |
int | mbs_is_dir_or_file (const char *path) |
Check if the path is valid and lead to a file or directory. More... | |
int | mbs_makedirs (char *path) |
Create (recursively) the specified directory. More... | |
char* explore_dir_for_project_path | ( | const char * | optionnal_path, |
int | verbose | ||
) |
Find the project directory from current working directory (cwd) or provided path.
The function parse the cwd or the provided path until finding either:
The caller is responsible for memory freeing.
[in] | optionnal_path | If not NULL, this path is used to search the project path. If the path starts with ".", the current working directory (see function mbs_getcwd()) is added as prefix. |
[in] | verbose | Verbosity level, from error only (0) to all (2). |
int find_project_path | ( | const char * | mbsfile, |
char * | prjpath | ||
) |
Find the project directory (containing dataR, symbolicR, ...) from Mbs filepath.
The function analyze the path by splitting at separator ("/" or "\\") and analyze if the mbs filepath is located in "dataR" folder
If the provided filename:
prjpath should be large enough to contain at least mbsfile.
[in] | mbsfile | the path and filename to the .mbs file |
[out] | prjpath | the path to the root of the mbs project |
char* find_project_path_from_cwd | ( | const char * | optionnal_path, |
int | verbose | ||
) |
Find the project directory from current working directory (cwd) or provided path.
The function parse the cwd or the provided path until finding a folder named "workR" or "dataR". The project directory is assumed to be the parent of the located folder.
The caller is responsible for memory freeing.
[in] | optionnal_path | If not NULL, this path is used to search the project path. If the path starts with ".", the current working directory (see function mbs_getcwd()) is added as prefix. |
[in] | verbose | Verbosity level, from error only (0) to all (2). |
char* find_user_path | ( | const char * | mbsfile | ) |
Find the user folder corresponding to the given *.mbs file.
This function allocate a char* that must be freed by the user.
[in] | mbsfile | the path and filename to the .mbs file |
char* mbs_basename | ( | const char * | path, |
int | verbose | ||
) |
mbs_basename returns the trailing part of the path (UNIX and MAC).
If the path ends on a folder, it returns the terminal folder. If it is a file it returns the filename and its extension.
If the path is the root folder it returns '/'. However under Windows we do not check if the path only contains the path to a drive (such as 'C:/').
path | The path from which the basename must be extracted. | |
[in] | verbose | Verbosity level, from error only (0) to all (2). |
char* mbs_dirname | ( | const char * | path, |
int | verbose | ||
) |
mbs_dirname returns the leading part of the path (UNIX and MAC).
If the path ends on a folder, it returns the previous folder. If it is a file it returns the path to the folder containing the file.
If the path is the root folder it returns '/'. However under Windows we do not check if the path only contains the path to a drive (such as 'C:/').
If the given path does not contain separator, the current directory (".") is returned.
[in] | path | The path from which the leading part must be extracted. |
[in] | verbose | Verbosity level, from error only (0) to all (2). |
char* mbs_getcwd | ( | ) |
Return the Current Working Directory (cwd).
The caller is responsible for memory freeing.
This function recursively increase the buffer to store the results of the system getcwd
(or _getcwd
for Windows) until a sufficient buffer size is reached.
ERANGE
(buffer too small) or the cwd. int mbs_is_dir_or_file | ( | const char * | path | ) |
Check if the path is valid and lead to a file or directory.
[in] | path | Pointer to the path to be checked. |
int mbs_makedirs | ( | char * | path | ) |
Create (recursively) the specified directory.
On Unix system permission are "0755" (only owner can write, everybody can read and execute).
[in] | path | The directory to be created. |
int mbs_splitext | ( | const char * | path, |
char ** | root, | ||
char ** | ext | ||
) |
Split the path into a pair (root, ext).
A the exit, root + ext == path
, and the extension, ext, is an empty string or begins with a period and contains at most one period.
If root
of ext
is NULL, the corresponding part of path
will not be returned.
Both root
and ext
are pointer to char pointer, the 'char' memory will be allocated by this function. If they already points to previously allocated memory, it will be freed to avoid leak.
The path separator is uniformized to unix style.
[in] | path | The full path. |
[in,out] | root | Pointer to pointer to store the root of the path. |
[in,out] | ext | Pointer to pointer to store the extension of the path. |
#_MBS_ERR_LOW_FILES
in case of error. int mbs_unix_separator | ( | char * | path | ) |
In-place replacement of windows-style path separator (\
) by Unix separator (/
).
[in,out] | path | The path to be adapted, modifications occurs in-place. |
#_MBS_ERR_LOW_FILES
for error. int remove_prjpath | ( | char ** | path, |
char * | project_source_dir | ||
) |
If the path start with PRJPATH, an new path is allocated replacing it.
The path separator are not replaced by unix-style.
[in,out] | path | Pointer to the pointer of the path to be cleared. The path separator after "PRJPATH" must be present. |
[in] | project_source_dir | The path of the project source dir, must not contains the final separator. |
#MBS_INFO_SUCCESS
for normal output, #MBS_INFO_FAILURE
value for error.