1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:37:34 +00:00

Shell: Rename the verb {lookup => look_up}

This commit is contained in:
Ali Mohammad Pur 2023-04-29 20:33:37 +03:30 committed by Ali Mohammad Pur
parent 4d00b372c8
commit 24c7995743
5 changed files with 22 additions and 22 deletions

View file

@ -3842,7 +3842,7 @@ ErrorOr<NonnullRefPtr<Value>> SimpleVariableValue::resolve_without_cast(RefPtr<S
{ {
VERIFY(shell); VERIFY(shell);
if (auto value = TRY(shell->lookup_local_variable(m_name))) { if (auto value = TRY(shell->look_up_local_variable(m_name))) {
auto result = value.release_nonnull(); auto result = value.release_nonnull();
// If a slice is applied, add it. // If a slice is applied, add it.
if (!m_slices.is_empty()) if (!m_slices.is_empty())
@ -3884,11 +3884,11 @@ ErrorOr<Vector<String>> SpecialVariableValue::resolve_as_list(RefPtr<Shell> shel
case '$': case '$':
return { resolve_slices(shell, Vector { TRY(String::number(getpid())) }, m_slices) }; return { resolve_slices(shell, Vector { TRY(String::number(getpid())) }, m_slices) };
case '*': case '*':
if (auto argv = TRY(shell->lookup_local_variable("ARGV"sv))) if (auto argv = TRY(shell->look_up_local_variable("ARGV"sv)))
return resolve_slices(shell, TRY(const_cast<Value&>(*argv).resolve_as_list(shell)), m_slices); return resolve_slices(shell, TRY(const_cast<Value&>(*argv).resolve_as_list(shell)), m_slices);
return resolve_slices(shell, Vector<String> {}, m_slices); return resolve_slices(shell, Vector<String> {}, m_slices);
case '#': case '#':
if (auto argv = TRY(shell->lookup_local_variable("ARGV"sv))) { if (auto argv = TRY(shell->look_up_local_variable("ARGV"sv))) {
if (argv->is_list()) { if (argv->is_list()) {
auto list_argv = static_cast<AST::ListValue const*>(argv.ptr()); auto list_argv = static_cast<AST::ListValue const*>(argv.ptr());
return { resolve_slices(shell, Vector { TRY(String::number(list_argv->values().size())) }, m_slices) }; return { resolve_slices(shell, Vector { TRY(String::number(list_argv->values().size())) }, m_slices) };

View file

@ -83,13 +83,13 @@ static Vector<DeprecatedString> find_matching_executables_in_path(StringView fil
ErrorOr<int> Shell::builtin_where(Main::Arguments arguments) ErrorOr<int> Shell::builtin_where(Main::Arguments arguments)
{ {
Vector<StringView> values_to_lookup; Vector<StringView> values_to_look_up;
bool do_only_path_search { false }; bool do_only_path_search { false };
bool do_follow_symlinks { false }; bool do_follow_symlinks { false };
bool do_print_only_type { false }; bool do_print_only_type { false };
Core::ArgsParser parser; Core::ArgsParser parser;
parser.add_positional_argument(values_to_lookup, "List of shell builtins, aliases or executables", "arguments"); parser.add_positional_argument(values_to_look_up, "List of shell builtins, aliases or executables", "arguments");
parser.add_option(do_only_path_search, "Search only for executables in the PATH environment variable", "path-only", 'p'); parser.add_option(do_only_path_search, "Search only for executables in the PATH environment variable", "path-only", 'p');
parser.add_option(do_follow_symlinks, "Follow symlinks and print the symlink free path", "follow-symlink", 's'); parser.add_option(do_follow_symlinks, "Follow symlinks and print the symlink free path", "follow-symlink", 's');
parser.add_option(do_print_only_type, "Print the argument type instead of a human readable description", "type", 'w'); parser.add_option(do_print_only_type, "Print the argument type instead of a human readable description", "type", 'w');
@ -97,13 +97,13 @@ ErrorOr<int> Shell::builtin_where(Main::Arguments arguments)
if (!parser.parse(arguments, Core::ArgsParser::FailureBehavior::PrintUsage)) if (!parser.parse(arguments, Core::ArgsParser::FailureBehavior::PrintUsage))
return 1; return 1;
auto const lookup_alias = [do_only_path_search, &m_aliases = this->m_aliases](StringView alias) -> Optional<DeprecatedString> { auto const look_up_alias = [do_only_path_search, &m_aliases = this->m_aliases](StringView alias) -> Optional<DeprecatedString> {
if (do_only_path_search) if (do_only_path_search)
return {}; return {};
return m_aliases.get(alias); return m_aliases.get(alias);
}; };
auto const lookup_builtin = [do_only_path_search](StringView builtin) -> Optional<DeprecatedString> { auto const look_up_builtin = [do_only_path_search](StringView builtin) -> Optional<DeprecatedString> {
if (do_only_path_search) if (do_only_path_search)
return {}; return {};
for (auto const& _builtin : builtin_names) { for (auto const& _builtin : builtin_names) {
@ -115,8 +115,8 @@ ErrorOr<int> Shell::builtin_where(Main::Arguments arguments)
}; };
bool at_least_one_succeded { false }; bool at_least_one_succeded { false };
for (auto const& argument : values_to_lookup) { for (auto const& argument : values_to_look_up) {
auto const alias = lookup_alias(argument); auto const alias = look_up_alias(argument);
if (alias.has_value()) { if (alias.has_value()) {
if (do_print_only_type) if (do_print_only_type)
outln("{}: alias", argument); outln("{}: alias", argument);
@ -125,7 +125,7 @@ ErrorOr<int> Shell::builtin_where(Main::Arguments arguments)
at_least_one_succeded = true; at_least_one_succeded = true;
} }
auto const builtin = lookup_builtin(argument); auto const builtin = look_up_builtin(argument);
if (builtin.has_value()) { if (builtin.has_value()) {
if (do_print_only_type) if (do_print_only_type)
outln("{}: builtin", builtin.value()); outln("{}: builtin", builtin.value());
@ -588,7 +588,7 @@ ErrorOr<int> Shell::builtin_export(Main::Arguments arguments)
} }
if (parts.size() == 1) { if (parts.size() == 1) {
auto value = TRY(lookup_local_variable(parts[0])); auto value = TRY(look_up_local_variable(parts[0]));
if (value) { if (value) {
auto values = TRY(const_cast<AST::Value&>(*value).resolve_as_list(*this)); auto values = TRY(const_cast<AST::Value&>(*value).resolve_as_list(*this));
StringBuilder builder; StringBuilder builder;
@ -974,7 +974,7 @@ ErrorOr<int> Shell::builtin_shift(Main::Arguments arguments)
if (count < 1) if (count < 1)
return 0; return 0;
auto argv_ = TRY(lookup_local_variable("ARGV"sv)); auto argv_ = TRY(look_up_local_variable("ARGV"sv));
if (!argv_) { if (!argv_) {
warnln("shift: ARGV is unset"); warnln("shift: ARGV is unset");
return 1; return 1;
@ -1007,7 +1007,7 @@ ErrorOr<int> Shell::builtin_source(Main::Arguments arguments)
if (!parser.parse(arguments)) if (!parser.parse(arguments))
return 1; return 1;
auto previous_argv = TRY(lookup_local_variable("ARGV"sv)); auto previous_argv = TRY(look_up_local_variable("ARGV"sv));
ScopeGuard guard { [&] { ScopeGuard guard { [&] {
if (!args.is_empty()) if (!args.is_empty())
set_local_variable("ARGV", const_cast<AST::Value&>(*previous_argv)); set_local_variable("ARGV", const_cast<AST::Value&>(*previous_argv));
@ -1203,7 +1203,7 @@ ErrorOr<int> Shell::builtin_unset(Main::Arguments arguments)
if (!did_touch_path && value == "PATH"sv) if (!did_touch_path && value == "PATH"sv)
did_touch_path = true; did_touch_path = true;
if (TRY(lookup_local_variable(value)) != nullptr) { if (TRY(look_up_local_variable(value)) != nullptr) {
unset_local_variable(value); unset_local_variable(value);
} else if (!unset_only_variables) { } else if (!unset_only_variables) {
unsetenv(value.characters()); unsetenv(value.characters());
@ -1412,7 +1412,7 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
}; };
auto enlist = [&](auto name, auto value) -> ErrorOr<NonnullRefPtr<AST::Value>> { auto enlist = [&](auto name, auto value) -> ErrorOr<NonnullRefPtr<AST::Value>> {
auto variable = TRY(lookup_local_variable(name)); auto variable = TRY(look_up_local_variable(name));
if (variable) { if (variable) {
auto list = TRY(const_cast<AST::Value&>(*variable).resolve_as_list(*this)); auto list = TRY(const_cast<AST::Value&>(*variable).resolve_as_list(*this));
auto new_value = TRY(value->resolve_as_string(*this)); auto new_value = TRY(value->resolve_as_string(*this));
@ -1791,7 +1791,7 @@ ErrorOr<int> Shell::builtin_read(Main::Arguments arguments)
if (auto const* value_from_env = getenv("IFS"); value_from_env) if (auto const* value_from_env = getenv("IFS"); value_from_env)
split_by_any_of = TRY(String::from_utf8({ value_from_env, strlen(value_from_env) })); split_by_any_of = TRY(String::from_utf8({ value_from_env, strlen(value_from_env) }));
else if (auto split_by_variable = TRY(lookup_local_variable("IFS"sv)); split_by_variable) else if (auto split_by_variable = TRY(look_up_local_variable("IFS"sv)); split_by_variable)
split_by_any_of = TRY(const_cast<AST::Value&>(*split_by_variable).resolve_as_string(*this)); split_by_any_of = TRY(const_cast<AST::Value&>(*split_by_variable).resolve_as_string(*this));
auto file = TRY(Core::File::standard_input()); auto file = TRY(Core::File::standard_input());

View file

@ -1245,7 +1245,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_math(AST::ImmediateExpression& invok
[&](String const& name) -> ErrorOr<i64> { [&](String const& name) -> ErrorOr<i64> {
size_t resolution_attempts_remaining = 100; size_t resolution_attempts_remaining = 100;
for (auto resolved_name = name; resolution_attempts_remaining > 0; --resolution_attempts_remaining) { for (auto resolved_name = name; resolution_attempts_remaining > 0; --resolution_attempts_remaining) {
auto value = TRY(lookup_local_variable(resolved_name.bytes_as_string_view())); auto value = TRY(look_up_local_variable(resolved_name.bytes_as_string_view()));
if (!value) if (!value)
break; break;

View file

@ -352,7 +352,7 @@ Shell::LocalFrame* Shell::find_frame_containing_local_variable(StringView name)
return nullptr; return nullptr;
} }
ErrorOr<RefPtr<AST::Value const>> Shell::lookup_local_variable(StringView name) const ErrorOr<RefPtr<AST::Value const>> Shell::look_up_local_variable(StringView name) const
{ {
if (auto* frame = find_frame_containing_local_variable(name)) if (auto* frame = find_frame_containing_local_variable(name))
return frame->local_variables.get(name).value(); return frame->local_variables.get(name).value();
@ -369,7 +369,7 @@ ErrorOr<RefPtr<AST::Value const>> Shell::get_argument(size_t index) const
return adopt_ref(*new AST::StringValue(TRY(String::from_deprecated_string(current_script)))); return adopt_ref(*new AST::StringValue(TRY(String::from_deprecated_string(current_script))));
--index; --index;
if (auto argv = TRY(lookup_local_variable("ARGV"sv))) { if (auto argv = TRY(look_up_local_variable("ARGV"sv))) {
if (argv->is_list_without_resolution()) { if (argv->is_list_without_resolution()) {
AST::ListValue const* list = static_cast<AST::ListValue const*>(argv.ptr()); AST::ListValue const* list = static_cast<AST::ListValue const*>(argv.ptr());
if (list->values().size() <= index) if (list->values().size() <= index)
@ -389,7 +389,7 @@ ErrorOr<RefPtr<AST::Value const>> Shell::get_argument(size_t index) const
ErrorOr<DeprecatedString> Shell::local_variable_or(StringView name, DeprecatedString const& replacement) const ErrorOr<DeprecatedString> Shell::local_variable_or(StringView name, DeprecatedString const& replacement) const
{ {
auto value = TRY(lookup_local_variable(name)); auto value = TRY(look_up_local_variable(name));
if (value) { if (value) {
StringBuilder builder; StringBuilder builder;
builder.join(' ', TRY(const_cast<AST::Value&>(*value).resolve_as_list(const_cast<Shell&>(*this)))); builder.join(' ', TRY(const_cast<AST::Value&>(*value).resolve_as_list(const_cast<Shell&>(*this))));
@ -1095,7 +1095,7 @@ bool Shell::is_allowed_to_modify_termios(const AST::Command& command) const
if (command.argv.is_empty()) if (command.argv.is_empty())
return false; return false;
auto value = lookup_local_variable("PROGRAMS_ALLOWED_TO_MODIFY_DEFAULT_TERMIOS"sv); auto value = look_up_local_variable("PROGRAMS_ALLOWED_TO_MODIFY_DEFAULT_TERMIOS"sv);
if (value.is_error()) if (value.is_error())
return false; return false;

View file

@ -183,7 +183,7 @@ public:
static bool has_history_event(StringView); static bool has_history_event(StringView);
ErrorOr<RefPtr<AST::Value const>> get_argument(size_t) const; ErrorOr<RefPtr<AST::Value const>> get_argument(size_t) const;
ErrorOr<RefPtr<AST::Value const>> lookup_local_variable(StringView) const; ErrorOr<RefPtr<AST::Value const>> look_up_local_variable(StringView) const;
ErrorOr<DeprecatedString> local_variable_or(StringView, DeprecatedString const&) const; ErrorOr<DeprecatedString> local_variable_or(StringView, DeprecatedString const&) const;
void set_local_variable(DeprecatedString const&, RefPtr<AST::Value>, bool only_in_current_frame = false); void set_local_variable(DeprecatedString const&, RefPtr<AST::Value>, bool only_in_current_frame = false);
void unset_local_variable(StringView, bool only_in_current_frame = false); void unset_local_variable(StringView, bool only_in_current_frame = false);