Add a few more ed commands.
This commit is contained in:
@@ -13,6 +13,7 @@ Address::Result Address::handle(BEd &ctx, std::string &cmd, uint64_t &i) {
|
||||
prev.offset = 0;
|
||||
curr.base = Number(ctx.active->prev_range.end);
|
||||
curr.offset = 0;
|
||||
i++;
|
||||
} else {
|
||||
curr = Address(cmd, i);
|
||||
}
|
||||
@@ -29,11 +30,12 @@ Address::Result Address::handle(BEd &ctx, std::string &cmd, uint64_t &i) {
|
||||
ctx.active->jump(curr.resolve(ctx));
|
||||
prev_given = true;
|
||||
}
|
||||
i++;
|
||||
prev = std::move(curr);
|
||||
} else {
|
||||
if (std::holds_alternative<None>(curr.base)) {
|
||||
if (std::holds_alternative<std::monostate>(prev.base))
|
||||
return {};
|
||||
return {{}, 0};
|
||||
if (prev_given) {
|
||||
curr = prev;
|
||||
} else {
|
||||
@@ -42,6 +44,8 @@ Address::Result Address::handle(BEd &ctx, std::string &cmd, uint64_t &i) {
|
||||
}
|
||||
return {{prev.resolve(ctx), curr.resolve(ctx)}, 2};
|
||||
}
|
||||
if (prev_given)
|
||||
return {{prev.resolve(ctx), curr.resolve(ctx)}, 2};
|
||||
return {{curr.resolve(ctx)}, 1};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ void Command::register_posix(BEd &ctx) {
|
||||
for (auto &[name, buffer] : ctx.buffers)
|
||||
if (buffer->modified)
|
||||
throw ed_error("Buffer " + name + " modified.");
|
||||
throw fatal_error("", 0);
|
||||
throw fatal_error("Quitting", 0);
|
||||
}
|
||||
};
|
||||
ctx.commands.insert(
|
||||
@@ -66,7 +66,38 @@ void Command::register_posix(BEd &ctx) {
|
||||
for (auto &[name, buffer] : ctx.buffers)
|
||||
if (buffer->modified)
|
||||
throw ed_error("Buffer " + name + " modified.");
|
||||
throw fatal_error("", 0);
|
||||
throw fatal_error("Quitting", 0);
|
||||
}
|
||||
}
|
||||
);
|
||||
ctx.commands.insert(
|
||||
"Q",
|
||||
Command{
|
||||
.address_mode = Command::AddressMode::None,
|
||||
.suffix = Command::SuffixKind::None,
|
||||
.desc = "Force quitting.",
|
||||
.accept_zero = false,
|
||||
.handle = [](BEd &, std::span<const uint64_t>, std::string_view) {
|
||||
throw fatal_error("Force Quitting", 0);
|
||||
}
|
||||
}
|
||||
);
|
||||
ctx.commands.insert(
|
||||
"p",
|
||||
Command{
|
||||
.address_mode = Command::AddressMode::Range,
|
||||
.suffix = Command::SuffixKind::Suffix,
|
||||
.desc = "Print range (default .,.)",
|
||||
.accept_zero = false,
|
||||
.handle = [](BEd &ctx, std::span<const uint64_t> addresses, std::string_view) {
|
||||
uint64_t start_line = ctx.active->line;
|
||||
uint64_t end_line = ctx.active->line;
|
||||
if (!addresses.size())
|
||||
ctx.active->print(start_line, end_line);
|
||||
else if (addresses.size() == 1)
|
||||
ctx.active->print(addresses[0], addresses[0]);
|
||||
else
|
||||
ctx.active->print(addresses[0], addresses[1]);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user