mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-15 09:27:38 +00:00
Instance env_set_empty
This commit is contained in:
parent
a00de96a57
commit
26fc705c07
5 changed files with 11 additions and 18 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "highlight.h"
|
||||
#include "history.h"
|
||||
#include "io.h"
|
||||
#include "parser.h"
|
||||
#include "proc.h"
|
||||
#include "reader.h"
|
||||
#include "wcstringutil.h"
|
||||
|
@ -452,7 +453,7 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||
auto vars_left = [&] () { return argv + argc - var_ptr; };
|
||||
auto clear_remaining_vars = [&] () {
|
||||
while (vars_left()) {
|
||||
env_set_empty(*var_ptr, opts.place);
|
||||
parser.vars().set_empty(*var_ptr, opts.place);
|
||||
// env_set_one(*var_ptr, opts.place, L"");
|
||||
++var_ptr;
|
||||
}
|
||||
|
|
19
src/env.cpp
19
src/env.cpp
|
@ -852,6 +852,7 @@ static void setup_var_dispatch_table() {
|
|||
void env_init(const struct config_paths_t *paths /* or NULL */) {
|
||||
setup_var_dispatch_table();
|
||||
|
||||
env_stack_t &vars = env_stack_t::principal();
|
||||
// Now the environment variable handling is set up, the next step is to insert valid data.
|
||||
|
||||
// Import environment variables. Walk backwards so that the first one out of any duplicates wins
|
||||
|
@ -866,7 +867,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
|||
if (eql == wcstring::npos) {
|
||||
// No equal-sign found so treat it as a defined var that has no value(s).
|
||||
if (is_read_only(key_and_val) || is_electric(key_and_val)) continue;
|
||||
env_set_empty(key_and_val, ENV_EXPORT | ENV_GLOBAL);
|
||||
vars.set_empty(key_and_val, ENV_EXPORT | ENV_GLOBAL);
|
||||
} else {
|
||||
key.assign(key_and_val, 0, eql);
|
||||
val.assign(key_and_val, eql+1, wcstring::npos);
|
||||
|
@ -965,16 +966,15 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
|||
} else {
|
||||
// We cannot get $HOME. This triggers warnings for history and config.fish already,
|
||||
// so it isn't necessary to warn here as well.
|
||||
env_set_empty(L"HOME", ENV_GLOBAL | ENV_EXPORT);
|
||||
vars.set_empty(L"HOME", ENV_GLOBAL | ENV_EXPORT);
|
||||
}
|
||||
free(unam_narrow);
|
||||
} else {
|
||||
// If $USER is empty as well (which we tried to set above), we can't get $HOME.
|
||||
env_set_empty(L"HOME", ENV_GLOBAL | ENV_EXPORT);
|
||||
vars.set_empty(L"HOME", ENV_GLOBAL | ENV_EXPORT);
|
||||
}
|
||||
}
|
||||
|
||||
env_stack_t &vars = env_stack_t::principal();
|
||||
// initialize the PWD variable if necessary
|
||||
// Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that.
|
||||
if (vars.get(L"PWD").missing_or_empty()) {
|
||||
|
@ -1431,10 +1431,6 @@ int env_set_one(const wcstring &key, env_mode_flags_t mode, wcstring val) {
|
|||
return env_stack_t::principal().set_one(key, mode, std::move(val));
|
||||
}
|
||||
|
||||
int env_set_empty(const wcstring &key, env_mode_flags_t mode) {
|
||||
return env_stack_t::principal().set_empty(key, mode);
|
||||
}
|
||||
|
||||
void env_universal_barrier() { env_stack_t::principal().universal_barrier(); }
|
||||
|
||||
wcstring env_get_pwd_slash() { return env_stack_t::principal().get_pwd_slash(); }
|
||||
|
@ -1599,12 +1595,11 @@ void env_stack_t::set_argv(const wchar_t *const *argv) {
|
|||
if (argv && *argv) {
|
||||
wcstring_list_t list;
|
||||
for (auto arg = argv; *arg; arg++) {
|
||||
list.push_back(*arg);
|
||||
list.emplace_back(*arg);
|
||||
}
|
||||
|
||||
env_set(L"argv", ENV_LOCAL, list);
|
||||
set(L"argv", ENV_LOCAL, std::move(list));
|
||||
} else {
|
||||
env_set_empty(L"argv", ENV_LOCAL);
|
||||
set_empty(L"argv", ENV_LOCAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,9 +152,6 @@ int env_set(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals);
|
|||
/// Sets the variable with the specified name to a single value.
|
||||
int env_set_one(const wcstring &key, env_mode_flags_t mode, wcstring val);
|
||||
|
||||
/// Sets the variable with the specified name to no values.
|
||||
int env_set_empty(const wcstring &key, env_mode_flags_t mode);
|
||||
|
||||
/// Synchronizes all universal variable changes: writes everything out, reads stuff in.
|
||||
void env_universal_barrier();
|
||||
|
||||
|
|
|
@ -356,7 +356,7 @@ void function_prepare_environment(env_stack_t &vars, const wcstring &name,
|
|||
env_set_one(named_arg, ENV_LOCAL | ENV_USER, *arg);
|
||||
arg++;
|
||||
} else {
|
||||
env_set_empty(named_arg, ENV_LOCAL | ENV_USER);
|
||||
vars.set_empty(named_arg, ENV_LOCAL | ENV_USER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,7 +387,7 @@ parse_execution_result_t parse_execution_context_t::run_for_statement(
|
|||
auto var = env_get(for_var_name, ENV_LOCAL);
|
||||
if (!var && !is_function_context()) var = env_get(for_var_name, ENV_DEFAULT);
|
||||
if (!var || var->read_only()) {
|
||||
int retval = env_set_empty(for_var_name, ENV_LOCAL | ENV_USER);
|
||||
int retval = parser->vars().set_empty(for_var_name, ENV_LOCAL | ENV_USER);
|
||||
if (retval != ENV_OK) {
|
||||
report_error(var_name_node, L"You cannot use read-only variable '%ls' in a for loop",
|
||||
for_var_name.c_str());
|
||||
|
|
Loading…
Reference in a new issue