Lots of miscellaneous cleanup. Unified the path_get_cd_path, path_allocate_cd_path, etc. functions

This commit is contained in:
ridiculousfish
2012-07-20 22:11:05 -07:00
parent b08fb86637
commit 261bf12c91
12 changed files with 91 additions and 170 deletions

36
path.h
View File

@@ -9,6 +9,8 @@
#ifndef FISH_PATH_H
#define FISH_PATH_H
#include "env.h"
/**
Return value for path_cdpath_get when locatied a rotten symlink
*/
@@ -24,22 +26,16 @@
bool path_get_config(wcstring &path);
/**
Finds the full path of an executable in a newly allocated string.
Finds the full path of an executable. Returns YES if successful.
\param cmd The name of the executable.
\param output_or_NULL If non-NULL, store the full path.
\param vars The environment variables snapshot to use
\return 0 if the command can not be found, the path of the command otherwise. The result should be freed with free().
*/
bool path_get_path( const wcstring &cmd, wcstring *output_or_NULL );
/**
A version of path_get_path() that takes the user's PATH variable from the given environment variable snapshot
*/
class env_vars_snapshot_t;
bool path_get_path(const wcstring &cmd, wcstring *output_or_NULL, const env_vars_snapshot_t &vars);
/** Returns whether the path can be used for an implicit cd command; if so, also returns the path by reference (if desired). This requires it to start with one of the allowed prefixes (., .., ~) and resolve to a directory. */
bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path = NULL, const wchar_t *wd = NULL);
bool path_get_path(const wcstring &cmd,
wcstring *output_or_NULL,
const env_vars_snapshot_t &vars = env_vars_snapshot_t::current());
/**
Returns the full path of the specified directory, using the CDPATH
@@ -54,14 +50,22 @@ bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path = NULL, co
symlink and a file are found, it is undefined which error status
will be returned.
\param in The name of the directory.
\param dir The name of the directory.
\param out_or_NULL If non-NULL, return the path to the resolved directory
\param wd The working directory, or NULL to use the default. The working directory should have a slash appended at the end.
\param vars The environment variable snapshot to use (for the CDPATH variable)
\return 0 if the command can not be found, the path of the command otherwise. The path should be free'd with free().
*/
bool path_get_cdpath(const wcstring &dir,
wcstring *out_or_NULL,
const wchar_t *wd = NULL,
const env_vars_snapshot_t &vars = env_vars_snapshot_t::current());
wchar_t *path_allocate_cdpath( const wcstring &in, const wchar_t *wd = NULL);
bool path_can_get_cdpath(const wcstring &in, const wchar_t *wd = NULL);
bool path_get_cdpath_string(const wcstring &in, wcstring &out, const env_vars_snapshot_t &vars);
/** Returns whether the path can be used for an implicit cd command; if so, also returns the path by reference (if desired). This requires it to start with one of the allowed prefixes (., .., ~) and resolve to a directory. */
bool path_can_be_implicit_cd(const wcstring &path,
wcstring *out_path = NULL,
const wchar_t *wd = NULL,
const env_vars_snapshot_t &vars = env_vars_snapshot_t::current());
/**
Remove double slashes and trailing slashes from a path,