mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
This commit is contained in:
parent
008355c222
commit
216e21a1fa
87 changed files with 450 additions and 448 deletions
|
@ -19,7 +19,7 @@
|
|||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder, const Shell::AST::Command& value)
|
||||
ErrorOr<void> AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder, Shell::AST::Command const& value)
|
||||
{
|
||||
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
||||
VERIFY_NOT_REACHED();
|
||||
|
@ -35,46 +35,46 @@ void AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder, const Sh
|
|||
VERIFY_NOT_REACHED();
|
||||
|
||||
if (value.argv.is_empty()) {
|
||||
builder.put_literal("(ShellInternal)");
|
||||
TRY(builder.put_literal("(ShellInternal)"));
|
||||
} else {
|
||||
bool first = true;
|
||||
for (auto& arg : value.argv) {
|
||||
if (!first)
|
||||
builder.put_literal(" ");
|
||||
TRY(builder.put_literal(" "));
|
||||
first = false;
|
||||
builder.put_literal(arg);
|
||||
TRY(builder.put_literal(arg));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& redir : value.redirections) {
|
||||
builder.put_padding(' ', 1);
|
||||
TRY(builder.put_padding(' ', 1));
|
||||
if (redir.is_path_redirection()) {
|
||||
auto path_redir = (const Shell::AST::PathRedirection*)&redir;
|
||||
builder.put_i64(path_redir->fd);
|
||||
TRY(builder.put_i64(path_redir->fd));
|
||||
switch (path_redir->direction) {
|
||||
case Shell::AST::PathRedirection::Read:
|
||||
builder.put_literal("<");
|
||||
TRY(builder.put_literal("<"));
|
||||
break;
|
||||
case Shell::AST::PathRedirection::Write:
|
||||
builder.put_literal(">");
|
||||
TRY(builder.put_literal(">"));
|
||||
break;
|
||||
case Shell::AST::PathRedirection::WriteAppend:
|
||||
builder.put_literal(">>");
|
||||
TRY(builder.put_literal(">>"));
|
||||
break;
|
||||
case Shell::AST::PathRedirection::ReadWrite:
|
||||
builder.put_literal("<>");
|
||||
TRY(builder.put_literal("<>"));
|
||||
break;
|
||||
}
|
||||
builder.put_literal(path_redir->path);
|
||||
TRY(builder.put_literal(path_redir->path));
|
||||
} else if (redir.is_fd_redirection()) {
|
||||
auto* fdredir = (const Shell::AST::FdRedirection*)&redir;
|
||||
builder.put_i64(fdredir->new_fd);
|
||||
builder.put_literal(">");
|
||||
builder.put_i64(fdredir->old_fd);
|
||||
TRY(builder.put_i64(fdredir->new_fd));
|
||||
TRY(builder.put_literal(">"));
|
||||
TRY(builder.put_i64(fdredir->old_fd));
|
||||
} else if (redir.is_close_redirection()) {
|
||||
auto close_redir = (const Shell::AST::CloseRedirection*)&redir;
|
||||
builder.put_i64(close_redir->fd);
|
||||
builder.put_literal(">&-");
|
||||
TRY(builder.put_i64(close_redir->fd));
|
||||
TRY(builder.put_literal(">&-"));
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -84,23 +84,24 @@ void AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder, const Sh
|
|||
for (auto& command : value.next_chain) {
|
||||
switch (command.action) {
|
||||
case Shell::AST::NodeWithAction::And:
|
||||
builder.put_literal(" && ");
|
||||
TRY(builder.put_literal(" && "));
|
||||
break;
|
||||
case Shell::AST::NodeWithAction::Or:
|
||||
builder.put_literal(" || ");
|
||||
TRY(builder.put_literal(" || "));
|
||||
break;
|
||||
case Shell::AST::NodeWithAction::Sequence:
|
||||
builder.put_literal("; ");
|
||||
TRY(builder.put_literal("; "));
|
||||
break;
|
||||
}
|
||||
|
||||
builder.put_literal("(");
|
||||
builder.put_literal(command.node->class_name());
|
||||
builder.put_literal("...)");
|
||||
TRY(builder.put_literal("("));
|
||||
TRY(builder.put_literal(command.node->class_name()));
|
||||
TRY(builder.put_literal("...)"));
|
||||
}
|
||||
}
|
||||
if (!value.should_wait)
|
||||
builder.put_literal("&");
|
||||
TRY(builder.put_literal("&"));
|
||||
return {};
|
||||
}
|
||||
|
||||
namespace Shell::AST {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue