mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-25 21:03:09 +08:00
Turn the 'mode' parameter of environment variables into an enum
This commit is contained in:
parent
b667eee351
commit
7def139020
6
env.cpp
6
env.cpp
@ -622,7 +622,7 @@ static env_node_t *env_get_node(const wcstring &key)
|
||||
return env;
|
||||
}
|
||||
|
||||
int env_set(const wcstring &key, const wchar_t *val, int var_mode)
|
||||
int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
|
||||
{
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
bool has_changed_old = has_changed_exported;
|
||||
@ -944,7 +944,7 @@ const wchar_t *env_var_t::c_str(void) const
|
||||
return wcstring::c_str();
|
||||
}
|
||||
|
||||
env_var_t env_get_string(const wcstring &key, int mode)
|
||||
env_var_t env_get_string(const wcstring &key, env_mode_flags_t mode)
|
||||
{
|
||||
const bool has_scope = mode & (ENV_LOCAL | ENV_GLOBAL | ENV_UNIVERSAL);
|
||||
const bool search_local = !has_scope || (mode & ENV_LOCAL);
|
||||
@ -1047,7 +1047,7 @@ env_var_t env_get_string(const wcstring &key, int mode)
|
||||
return env_var_t::missing_var();
|
||||
}
|
||||
|
||||
bool env_exist(const wchar_t *key, int mode)
|
||||
bool env_exist(const wchar_t *key, env_mode_flags_t mode)
|
||||
{
|
||||
env_node_t *env;
|
||||
|
||||
|
66
env.h
66
env.h
@ -11,37 +11,33 @@
|
||||
#include "util.h"
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
Flag for local (to the current block) variable
|
||||
*/
|
||||
#define ENV_LOCAL 1
|
||||
|
||||
/**
|
||||
Flag for exported (to commands) variable
|
||||
*/
|
||||
#define ENV_EXPORT 2
|
||||
|
||||
/**
|
||||
Flag for unexported variable
|
||||
*/
|
||||
#define ENV_UNEXPORT 16
|
||||
|
||||
/**
|
||||
Flag for global variable
|
||||
*/
|
||||
#define ENV_GLOBAL 4
|
||||
|
||||
/**
|
||||
Flag for variable update request from the user. All variable
|
||||
changes that are made directly by the user, such as those from the
|
||||
'set' builtin must have this flag set.
|
||||
*/
|
||||
#define ENV_USER 8
|
||||
|
||||
/**
|
||||
Flag for universal variable
|
||||
*/
|
||||
#define ENV_UNIVERSAL 32
|
||||
/* Flags that may be passed as the 'mode' in env_set / env_get_string */
|
||||
enum
|
||||
{
|
||||
/* Default mode */
|
||||
ENV_DEFAULT = 0,
|
||||
|
||||
/** Flag for local (to the current block) variable */
|
||||
ENV_LOCAL = 1,
|
||||
|
||||
/** Flag for exported (to commands) variable */
|
||||
ENV_EXPORT = 2,
|
||||
|
||||
/** Flag for unexported variable */
|
||||
ENV_UNEXPORT = 16,
|
||||
|
||||
/** Flag for global variable */
|
||||
ENV_GLOBAL = 4,
|
||||
|
||||
/** Flag for variable update request from the user. All variable
|
||||
changes that are made directly by the user, such as those from the
|
||||
'set' builtin must have this flag set. */
|
||||
ENV_USER = 8,
|
||||
|
||||
/** Flag for universal variable */
|
||||
ENV_UNIVERSAL = 32
|
||||
};
|
||||
typedef uint32_t env_mode_flags_t;
|
||||
|
||||
/**
|
||||
Error code for trying to alter read-only variable
|
||||
@ -87,7 +83,7 @@ void env_init(const struct config_paths_t *paths = NULL);
|
||||
* ENV_INVALID, the variable name or mode was invalid
|
||||
*/
|
||||
|
||||
int env_set(const wcstring &key, const wchar_t *val, int mode);
|
||||
int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t mode);
|
||||
|
||||
|
||||
/**
|
||||
@ -175,16 +171,16 @@ public:
|
||||
\param key The name of the variable to get
|
||||
\param mode An optional scope to search in. All scopes are searched if unset
|
||||
*/
|
||||
env_var_t env_get_string(const wcstring &key, int mode = 0);
|
||||
env_var_t env_get_string(const wcstring &key, env_mode_flags_t mode = ENV_DEFAULT);
|
||||
|
||||
/**
|
||||
Returns true if the specified key exists. This can't be reliably done
|
||||
using env_get, since env_get returns null for 0-element arrays
|
||||
|
||||
\param key The name of the variable to remove
|
||||
\param mode the scope to search in. All scopes are searched if unset
|
||||
\param mode the scope to search in. All scopes are searched if set to default
|
||||
*/
|
||||
bool env_exist(const wchar_t *key, int mode);
|
||||
bool env_exist(const wchar_t *key, env_mode_flags_t mode);
|
||||
|
||||
/**
|
||||
Remove environemnt variable
|
||||
|
Loading…
x
Reference in New Issue
Block a user