Make posix line mode the default always.
This commit is contained in:
@@ -24,9 +24,9 @@ struct Shard {
|
||||
static void retain(Shard *n);
|
||||
static void release(Shard *n);
|
||||
|
||||
static Shard *from_file(const std::filesystem::path &path, bool posix_ending);
|
||||
static Shard *from_string(const char *data, uint64_t len, bool posix_ending);
|
||||
static Shard *from_command(const char *cmd, bool posix_ending);
|
||||
static Shard *from_file(const std::filesystem::path &path);
|
||||
static Shard *from_string(const char *data, uint64_t len);
|
||||
static Shard *from_command(const char *cmd);
|
||||
|
||||
static std::pair<Shard *, Shard *> split(Shard *n, uint64_t offset);
|
||||
static Shard *concat(Shard *a, Shard *b);
|
||||
|
||||
@@ -11,14 +11,14 @@ bool ClipBuffer::waste() {
|
||||
void ClipBuffer::saved_hook() {}
|
||||
|
||||
uint64_t ClipBuffer::lines() {
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
uint64_t lines = s ? s->lines + 1 : 0;
|
||||
vase::Shard::release(s);
|
||||
return lines;
|
||||
}
|
||||
|
||||
uint64_t ClipBuffer::bytes() {
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
uint64_t length = s ? s->length + 1 : 0;
|
||||
vase::Shard::release(s);
|
||||
return length;
|
||||
@@ -57,7 +57,7 @@ void ClipBuffer::append(BEd &ctx, vase::Shard *text, uint64_t line) {
|
||||
ctx.prev().buffername = name;
|
||||
ctx.prev().start = line + 1;
|
||||
ctx.prev().end = line + (text ? text->lines + 1 : 0);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
s = vase::insert(&ctx.append, s, text, line);
|
||||
clip_write(s);
|
||||
vase::Shard::release(s);
|
||||
@@ -65,7 +65,7 @@ void ClipBuffer::append(BEd &ctx, vase::Shard *text, uint64_t line) {
|
||||
}
|
||||
|
||||
void ClipBuffer::remove(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
s = vase::erase(s, start_line, end_line);
|
||||
clip_write(s);
|
||||
ctx.prev().buffername = name;
|
||||
@@ -85,7 +85,7 @@ void ClipBuffer::replace(BEd &ctx, vase::Shard *text, uint64_t start_line, uint6
|
||||
ctx.prev().end = start_line + text->lines;
|
||||
uint64_t new_count = text->lines + 1;
|
||||
uint64_t old_count = end_line - start_line + 1;
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
s = vase::replace(s, text, start_line, end_line);
|
||||
clip_write(s);
|
||||
vase::Shard::release(s);
|
||||
@@ -99,7 +99,7 @@ void ClipBuffer::replace(BEd &ctx, vase::Shard *text, uint64_t start_line, uint6
|
||||
}
|
||||
|
||||
void ClipBuffer::join(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
s = vase::join(s, start_line, end_line);
|
||||
clip_write(s);
|
||||
vase::Shard::release(s);
|
||||
@@ -116,7 +116,7 @@ void ClipBuffer::substitute(
|
||||
ctx.prev().buffername = name;
|
||||
ctx.prev().start = start_line;
|
||||
ctx.prev().end = end_line;
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
s = vase::substitute(
|
||||
&ctx.append,
|
||||
s,
|
||||
@@ -138,21 +138,21 @@ void ClipBuffer::substitute(
|
||||
}
|
||||
|
||||
vase::Shard *ClipBuffer::copy(uint64_t start_line, uint64_t end_line) {
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
vase::Shard *o = vase::copy(s, start_line, end_line);
|
||||
vase::Shard::release(s);
|
||||
return o;
|
||||
}
|
||||
|
||||
uint64_t ClipBuffer::find_next(std::string_view pattern, uint64_t start) {
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
uint64_t line = vase::find_next(s, pattern, start);
|
||||
vase::Shard::release(s);
|
||||
return line;
|
||||
}
|
||||
|
||||
uint64_t ClipBuffer::find_prev(std::string_view pattern, uint64_t start) {
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
uint64_t line = vase::find_prev(s, pattern, start);
|
||||
vase::Shard::release(s);
|
||||
return line;
|
||||
@@ -176,7 +176,7 @@ void ClipBuffer::print(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
||||
ctx.prev().buffername = name;
|
||||
ctx.prev().start = start_line;
|
||||
ctx.prev().end = end_line;
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
||||
while (it.next() && start_line++ <= end_line)
|
||||
ctx.io.write_line(it.line);
|
||||
@@ -190,7 +190,7 @@ void ClipBuffer::number_print(BEd &ctx, uint64_t start_line, uint64_t end_line)
|
||||
uint8_t width = 1;
|
||||
for (uint64_t n = end_line; n >= 10; n /= 10)
|
||||
++width;
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
||||
while (it.next() && start_line <= end_line)
|
||||
ctx.io.write_line(std::format("{:>{}}\t{}", start_line++, width, it.line));
|
||||
@@ -201,7 +201,7 @@ void ClipBuffer::list_print(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
||||
ctx.prev().buffername = name;
|
||||
ctx.prev().start = start_line;
|
||||
ctx.prev().end = end_line;
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
||||
while (it.next() && start_line++ <= end_line)
|
||||
ctx.io.write_line(list_string(it.line));
|
||||
|
||||
@@ -197,7 +197,7 @@ void Function::register_extented(BEd &ctx) {
|
||||
ctx.io.write("=> ", 3);
|
||||
auto parser = syntax::MiniParser(
|
||||
*ctx.languages["ruby"],
|
||||
vase::Shard::from_string(line.data(), line.size(), true),
|
||||
vase::Shard::from_string(line.data(), line.size()),
|
||||
nullptr
|
||||
);
|
||||
const auto &tokens = parser.lines[0].second;
|
||||
|
||||
@@ -144,17 +144,17 @@ void Function::register_posix(BEd &ctx) {
|
||||
vase::Shard *s = nullptr;
|
||||
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
||||
auto path = std::get<std::filesystem::path>(arg);
|
||||
s = vase::Shard::from_file(path, true);
|
||||
s = vase::Shard::from_file(path);
|
||||
buf.set_filename(path);
|
||||
} else if (std::holds_alternative<ShellArg>(arg)) {
|
||||
auto cmd = std::get<ShellArg>(arg).cmd;
|
||||
ctx.escape_command(cmd, buf.filename().string());
|
||||
s = vase::Shard::from_command(cmd.c_str(), true);
|
||||
s = vase::Shard::from_command(cmd.c_str());
|
||||
} else {
|
||||
auto path = buf.filename();
|
||||
if (path.empty())
|
||||
throw ed_error("Need filename.");
|
||||
s = vase::Shard::from_file(path, true);
|
||||
s = vase::Shard::from_file(path);
|
||||
};
|
||||
try {
|
||||
buf.load(ctx, s);
|
||||
@@ -190,17 +190,17 @@ void Function::register_posix(BEd &ctx) {
|
||||
vase::Shard *s = nullptr;
|
||||
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
||||
auto path = std::get<std::filesystem::path>(arg);
|
||||
s = vase::Shard::from_file(path, true);
|
||||
s = vase::Shard::from_file(path);
|
||||
buf.set_filename(path);
|
||||
} else if (std::holds_alternative<ShellArg>(arg)) {
|
||||
auto cmd = std::get<ShellArg>(arg).cmd;
|
||||
ctx.escape_command(cmd, buf.filename().string());
|
||||
s = vase::Shard::from_command(cmd.c_str(), true);
|
||||
s = vase::Shard::from_command(cmd.c_str());
|
||||
} else {
|
||||
auto path = buf.filename();
|
||||
if (path.empty())
|
||||
throw ed_error("Need filename.");
|
||||
s = vase::Shard::from_file(path, true);
|
||||
s = vase::Shard::from_file(path);
|
||||
};
|
||||
try {
|
||||
buf.load(ctx, s);
|
||||
@@ -588,18 +588,18 @@ void Function::register_posix(BEd &ctx) {
|
||||
vase::Shard *s = nullptr;
|
||||
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
||||
auto path = std::get<std::filesystem::path>(arg);
|
||||
s = vase::Shard::from_file(path, true);
|
||||
s = vase::Shard::from_file(path);
|
||||
if (buf.filename().empty())
|
||||
buf.set_filename(path);
|
||||
} else if (std::holds_alternative<ShellArg>(arg)) {
|
||||
auto cmd = std::get<ShellArg>(arg).cmd;
|
||||
ctx.escape_command(cmd, buf.filename().string());
|
||||
s = vase::Shard::from_command(cmd.c_str(), true);
|
||||
s = vase::Shard::from_command(cmd.c_str());
|
||||
} else {
|
||||
auto path = buf.filename();
|
||||
if (path.empty())
|
||||
throw ed_error("Need filename.");
|
||||
s = vase::Shard::from_file(path, true);
|
||||
s = vase::Shard::from_file(path);
|
||||
};
|
||||
try {
|
||||
buf.append(ctx, s, addr.number);
|
||||
|
||||
@@ -202,7 +202,7 @@ Shard *Shard::build(Shard **pieces, uint64_t lo, uint64_t hi) {
|
||||
return node;
|
||||
}
|
||||
|
||||
Shard *Shard::from_command(const char *cmd, bool posix_ending) {
|
||||
Shard *Shard::from_command(const char *cmd) {
|
||||
auto o = new OriginalStorage("/tmp");
|
||||
int dest_fd = o->fd;
|
||||
if (dest_fd == -1) {
|
||||
@@ -278,7 +278,6 @@ Shard *Shard::from_command(const char *cmd, bool posix_ending) {
|
||||
io::IO::enable_raw();
|
||||
return nullptr;
|
||||
}
|
||||
if (posix_ending) {
|
||||
if (ending[1] == '\n') {
|
||||
Petal *last = (Petal *)pieces.back();
|
||||
last->lines--;
|
||||
@@ -295,7 +294,6 @@ Shard *Shard::from_command(const char *cmd, bool posix_ending) {
|
||||
if (last && ending[0] == '\r')
|
||||
last->length--;
|
||||
}
|
||||
}
|
||||
o->initialize();
|
||||
io::IO::enable_raw();
|
||||
if (pieces.size() == 1)
|
||||
@@ -303,7 +301,7 @@ Shard *Shard::from_command(const char *cmd, bool posix_ending) {
|
||||
return build(pieces.data(), 0, pieces.size());
|
||||
}
|
||||
|
||||
Shard *Shard::from_file(const std::filesystem::path &path, bool posix_ending) {
|
||||
Shard *Shard::from_file(const std::filesystem::path &path) {
|
||||
auto o = new OriginalStorage("/tmp");
|
||||
int dest_fd = o->fd;
|
||||
if (dest_fd == -1) {
|
||||
@@ -313,10 +311,10 @@ Shard *Shard::from_file(const std::filesystem::path &path, bool posix_ending) {
|
||||
int src_fd = open(path.c_str(), O_RDONLY);
|
||||
if (src_fd == -1) {
|
||||
delete o;
|
||||
return nullptr;
|
||||
throw ed_error("Couldn't open file.");
|
||||
}
|
||||
uint64_t total = std::filesystem::file_size(path);
|
||||
if (posix_ending && total > 0) {
|
||||
if (total > 0) {
|
||||
char last;
|
||||
if (pread(src_fd, &last, 1, (off_t)(total - 1)) != 1) {
|
||||
delete o;
|
||||
@@ -381,7 +379,7 @@ Shard *Shard::from_file(const std::filesystem::path &path, bool posix_ending) {
|
||||
return build(pieces.data(), 0, pieces.size());
|
||||
}
|
||||
|
||||
Shard *Shard::from_string(const char *data, uint64_t len, bool posix_ending) {
|
||||
Shard *Shard::from_string(const char *data, uint64_t len) {
|
||||
auto o = new OriginalStorage("/tmp");
|
||||
int dest_fd = o->fd;
|
||||
if (dest_fd == -1 || data == nullptr) {
|
||||
@@ -389,7 +387,7 @@ Shard *Shard::from_string(const char *data, uint64_t len, bool posix_ending) {
|
||||
return nullptr;
|
||||
}
|
||||
uint64_t total = len;
|
||||
if (posix_ending && total > 0) {
|
||||
if (total > 0) {
|
||||
if (data[total - 1] == '\n') {
|
||||
total--;
|
||||
if (total > 0 && data[total - 1] == '\r')
|
||||
|
||||
Reference in New Issue
Block a user